forked from travis-ci/docs-travis-ci-com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
executable file
·222 lines (188 loc) · 5.33 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env rake
# frozen_string_literal: true
require 'ipaddr'
require 'json'
require 'yaml'
require 'faraday'
require 'html-proofer'
def print_line_containing(file, str)
File.open(file).grep(/#{str}/).each { |line| puts "#{file}: #{line}" }
end
def dns_resolve(hostname, rectype: 'A')
JSON.parse(
Faraday.get("https://dnsjson.com/#{hostname}/#{rectype}.json").body
).fetch('results').fetch('records')
end
def define_ip_range(nat_hostname, dest)
data = dns_resolve(nat_hostname)
bytes = File.write(
dest,
YAML.dump(
'host' => nat_hostname,
'ip_range' => data.sort { |a, b| IPAddr.new(a) <=> IPAddr.new(b) }
)
)
puts "Updated #{dest} (#{bytes} bytes)"
end
task default: :test
desc 'Runs the tests!'
task test: %i[build run_html_proofer]
desc 'Builds the site (Jekyll and Slate)'
task build: %i[remove_output_dir regen make_api] do
rm_f '.jekyll-metadata'
sh 'bundle exec jekyll build --config=_config.yml'
end
desc 'Remove the output dirs'
task :remove_output_dir do
rm_rf('_site')
rm_rf('api/*')
end
desc 'Lists files containing beta features'
task :list_beta_files do
files = FileList.new('**/*.md')
files.exclude('_site/*', 'STYLE.md')
files.each do |f|
print_line_containing(f, '\.beta')
end
end
desc 'Runs the html-proofer test'
task :run_html_proofer => [:build] do
# seems like the build does not render `%3*`,
# so let's remove them for the check
url_swap = {
/%3A\z/ => '',
/%3F\z/ => '',
/-\.travis\.yml/ => '-travisyml'
}
HTMLProofer.check_directory(
'./_site',
url_swap: url_swap,
internal_domains: ['docs.travis-ci.com'],
connecttimeout: 600,
only_4xx: true,
typhoeus: {
ssl_verifypeer: false, ssl_verifyhost: 0, followlocation: true
},
url_ignore: [
'https://www.appfog.com/',
/itunes\.apple\.com/,
/coverity.com/,
/articles201769485/
],
file_ignore: %w[
./_site/api/index.html
./_site/user/languages/erlang/index.html
./_site/user/languages/objective-c/index.html
./_site/user/reference/osx/index.html
]
).run
end
desc 'Runs the html-proofer test for internal links only'
task :run_html_proofer_internal => [:build] do
# seems like the build does not render `%3*`,
# so let's remove them for the check
url_swap = {
/%3A\z/ => '',
/%3F\z/ => '',
/-\.travis\.yml/ => '-travisyml'
}
HTMLProofer.check_directory(
'./_site',
url_swap: url_swap,
disable_external: true,
internal_domains: ['docs.travis-ci.com'],
connecttimeout: 600,
only_4xx: true,
typhoeus: {
ssl_verifypeer: false, ssl_verifyhost: 0, followlocation: true
},
file_ignore: %w[
./_site/api/index.html
./_site/user/languages/erlang/index.html
./_site/user/languages/objective-c/index.html
./_site/user/reference/osx/index.html
]
).run
end
file '_data/trusty-language-mapping.json' do |t|
source = File.join(
'https://raw.githubusercontent.com',
'travis-infrastructure/terraform-config/master/aws-production-2',
'generated-language-mapping.json'
)
bytes = File.write(t.name, Faraday.get(source).body)
puts "Updated #{t.name} (#{bytes} bytes)"
end
file '_data/trusty_language_mapping.yml' => [
'_data/trusty-language-mapping.json'
] do |t|
bytes = File.write(
t.name,
YAML.dump(JSON.parse(File.read('_data/trusty-language-mapping.json')))
)
puts "Updated #{t.name} (#{bytes} bytes)"
end
file '_data/ip_range.yml' do |t|
define_ip_range('nat.travisci.net', t.name)
end
file '_data/ec2_ip_range.yml' do |t|
define_ip_range('nat.aws-us-east-1.travisci.net', t.name)
end
file '_data/gce_ip_range.yml' do |t|
define_ip_range('nat.gce-us-central1.travisci.net', t.name)
end
file '_data/linux_containers_ip_range.yml' do |t|
define_ip_range('nat.linux-containers.travisci.net', t.name)
end
file '_data/macstadium_ip_range.yml' do |t|
define_ip_range('nat.macstadium-us-se-1.travisci.net', t.name)
end
file '_data/packet_ip_range.yml' do |t|
define_ip_range('nat.packet-ewr1.travisci.net', t.name)
end
file '_data/node_js_versions.yml' do |t|
remote_node_versions = `bash -l -c "source $HOME/.nvm/nvm.sh; nvm ls-remote"`.split("\n").
map {|l| l.gsub(/.*v(0\.[0-9]*|[0-9]*)\..*$/, '\1')}.uniq.
sort {|a,b| Gem::Version.new(b) <=> Gem::Version.new(a) }
bytes = File.write(
t.name,
YAML.dump(
remote_node_versions.flatten.compact.take(5)
)
)
puts "Updated #{t.name} (#{bytes} bytes)"
end
desc 'Refresh generated files'
task regen: (%i[clean] + %w[
_data/ec2_ip_range.yml
_data/gce_ip_range.yml
_data/ip_range.yml
_data/linux_containers_ip_range.yml
_data/macstadium_ip_range.yml
_data/trusty_language_mapping.yml
_data/node_js_versions.yml
])
desc 'Remove generated files'
task :clean do
rm_f(%w[
_data/ec2_ip_range.yml
_data/gce_ip_range.yml
_data/ip_range.yml
_data/linux_containers_ip_range.yml
_data/macstadium_ip_range.yml
_data/trusty-language-mapping.json
_data/trusty_language_mapping.yml
_data/node_js_versions.yml
])
end
desc 'Start Jekyll server'
task serve: [:make_api, :regen] do
sh 'bundle exec jekyll serve --config=_config.yml'
end
namespace :assets do
task precompile: [:make_api, :build]
end
desc 'make API docs'
task :make_api do
sh 'bundle exec middleman build --clean'
end