forked from mapzen/metroextractor-cities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
73 lines (63 loc) · 1.61 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
#!/usr/bin/env rake
require 'json'
require 'rainbow/ext/string'
desc 'Run integration tests'
task :build do
# Prepare sandbox
#
sandbox = File.join(File.dirname(__FILE__), %w(tmp))
prepare_sandbox(sandbox)
# Check ruby syntax
#
puts 'Running rubocop'.color(:blue)
sh "rubocop #{File.dirname(sandbox)}/tmp"
# Validate cities.json
#
puts 'Validating cities.json'.color(:blue)
begin
JSON.load(File.read('cities.json'))
puts 'Syntax OK'.color(:green)
rescue JSON::ParserError
puts 'Syntax Error!'.color(:red)
exit 1
end
# Validate cities.geojson
#
puts 'Validating cities.geojson'.color(:blue)
begin
JSON.load(File.read('cities.geojson'))
puts 'Syntax OK'.color(:green)
rescue JSON::ParserError
puts 'Syntax Error!'.color(:red)
exit 1
end
# Produce new cities.geojson
#
if ENV['CIRCLECI'] == 'true'
if ENV['CIRCLE_BRANCH'] == 'master'
puts 'Building cities.geojson'.color(:blue)
sh <<-EOH
bin/json2geojson.rb
git diff --exit-code
if [ $? != 0 ]
then
echo 'Changes found, committing and pushing'
git config user.email 'circle@circleci'
git config user.name 'circle'
git commit -am 'COMMITTED VIA CIRCLECI: cities.geojson update'
git push origin master
else
echo "No changes found, we're done here"
fi
EOH
end
end
end
task default: 'build'
def prepare_sandbox(sandbox)
files = %w(Rakefile *.md *.rb)
puts 'Preparing sandbox'.color(:blue)
rm_rf sandbox
mkdir_p sandbox
cp_r Dir.glob("{#{files.join(',')}}"), sandbox
end