-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathRakefile
118 lines (87 loc) · 2.76 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#############################################################################
#
# Modified version of jekyllrb Rakefile
# https://github.com/jekyll/jekyll/blob/master/Rakefile
#
#############################################################################
require 'rake'
require 'date'
USERNAME = "PincongBackup"
REPO = "pages"
SOURCE_BRANCH = "master"
DESTINATION_BRANCH = "master"
def check_destination
unless Dir.exist? "_site"
sh "git clone https://#{ENV['GIT_NAME']}:#{ENV['GH_TOKEN']}@github.com/#{USERNAME}/#{REPO}.git _site"
end
end
task :deploy do
# Detect pull request
if ENV['TRAVIS_PULL_REQUEST'].to_s.to_i > 0
puts 'Pull request detected. Not proceeding with deploy.'
exit
end
# Configure git if this is run in Travis CI
if ENV["TRAVIS"]
sh "git config --global user.name '#{ENV['GIT_NAME']}'"
sh "git config --global user.email '#{ENV['GIT_EMAIL']}'"
sh "git config --global push.default simple"
end
# Make sure destination folder exists as git repo
check_destination
puts "_site"
# clean
Dir.chdir("_site") {
puts "\ncleaning"
files = `git rm -rf . | wc -l`.match(/\d+/)[0]
puts "#{files} files cleaned\n"
}
sh "bundle exec jekyll build"
sh "ipfs swarm peers"
ipfs_hash = `ipfs add -r -Q _site`.match(/\w+/)[0]
sh "ipfs pin add -r /ipfs/#{ipfs_hash}"
sh "ipfs name publish --key=key #{ipfs_hash}"
# Commit and push to github
sha = `git log`.match(/[a-z0-9]{40}/)[0]
Dir.chdir("_site") do
sh "git add --all ."
sh "git commit -m 'Updating to ##{sha}. \nipfs://#{ipfs_hash}'"
sh "git push --quiet origin #{DESTINATION_BRANCH}"
puts "Pushed updated branch #{DESTINATION_BRANCH} to GitHub Pages"
end
while true do
peers = `ipfs swarm peers | wc -l`.match(/\d+/)[0].to_i
puts "\nConnected to #{peers} peers"
if peers >= 100 then
# sh "ipfs swarm peers"
break
else
sleep(0.5)
end
end
end
task :sync, [:minutes] do |t, args|
args.with_defaults(:minutes => 10)
minutes = args.minutes.to_i
max = (minutes - 1) * 60 + 40
i = 0
puts "\nsyncing"
while i < max do
if i % 30 == 0 then
peers = `ipfs swarm peers | wc -l`.match(/\d+/)[0].to_i
puts "Connected to #{peers} peers"
end
sleep(1)
i += 1
end
end
task :test do
puts "\ntesting"
ipns_hash = `ipfs key list -l`.match(/(\w{46}) key/)[1]
ipfs_hash = `ipfs name resolve #{ipfs_hash}`.match(/\w{46}/)[0]
gateways = [ "cloudflare-ipfs.com", "ipfs.io", "ipfs.ink" ]
gateways.each do |i|
sh "curl 'https://#{i}/ipfs/#{ipfs_hash}' > /dev/null"
sh "curl 'https://#{i}/ipns/#{ipns_hash}' > /dev/null"
end
end