forked from ashfurrow/peerlab.community
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
80 lines (69 loc) · 2.31 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
require 'middleman-gh-pages'
require 'rake'
desc "Deploy if Travis environment variables are set correctly."
task :travis do
branch = ENV['TRAVIS_BRANCH']
pull_request = ENV['TRAVIS_PULL_REQUEST']
abort 'Must be run on Travis' unless branch
if pull_request != 'false'
puts 'Skipping deploy for pull request; can only be deployed from master branch.'
exit 0
end
if branch != 'master'
puts "Skipping deploy for #{ branch }; can only be deployed from master branch."
exit 0
end
Rake::Task['publish'].invoke
puts 'Invalidating CDN.'
sleep 20 # Give GitHub time to deploy the site before invalidating.
CLOUDFLARE_ZONE_ID = '78aee06030dd52496fcc5b508ca32336'
# Documented at https://api.cloudflare.com/#zone-purge-all-files
sh <<-EOS
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/#{CLOUDFLARE_ZONE_ID}/purge_cache" \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_CLIENT_API_KEY" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'
EOS
puts 'Invalidation complete.'
end
desc "Builds the site in the ./test directory."
task :test do
sh "bundle exec middleman build --build-dir=test"
end
desc "Start middleman server"
task :server do
puts "Starting Middleman server"
middleman = Process.spawn("bundle exec middleman")
trap("INT") {
Process.kill(9, middleman) rescue Errno::ESRCH
exit 0
}
Process.wait(middleman)
end
namespace :yaml do
desc "Check data/events.yml for lexicographical sort by city name"
task :check do
contents = File.read("data/events.yml")
cities = contents.scan(/- city: ([^\n]+)$/).flatten
unless cities.sort == cities
fail "data/events.yml is not sorted"
end
end
desc "Sorts data/events.yml lexicographically by city name"
task :sort do
# We're going to assume each entry starts with `- city`, as shown in the README
contents = File.read("data/events.yml")
entries = contents.split("- city: ")[1...-1]
new_entries = entries
.map { |e| { name: e.split("\n").first, entry: e } }
.sort { |l, r| l[:name] <=> r[:name] }
new_contents = <<~EOS
peer_labs:
#{ new_entries.map { |e| "- city: #{ e[:entry] }" }.join("") }
EOS
File.write('data/events.yml', new_contents)
end
end
task :serve => :server
task :default => :server