forked from travis-ci/docs-travis-ci-com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
executable file
·205 lines (175 loc) · 4.9 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
#!/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_txt(hostname, record: 0)
JSON.parse(
Faraday.get("https://dnsjson.com/#{hostname}/TXT.json").body
).fetch('results').fetch('records').fetch(record).split.map(&:strip)
end
task default: :test
desc 'Runs the tests!'
task test: %i[build run_html_proofer]
desc 'Builds the site'
task build: %i[remove_output_dir regen] do
rm_f '.jekyll-metadata'
sh 'bundle exec jekyll build --config=_config.yml'
end
desc 'Remove the output dir'
task :remove_output_dir do
rm_rf('_site')
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'
)
File.write(t.name, Faraday.get(source).body)
end
file '_data/trusty_language_mapping.yml' => [
'_data/trusty-language-mapping.json'
] do |t|
File.write(
t.name,
YAML.dump(JSON.parse(File.read('_data/trusty-language-mapping.json')))
)
puts "Updated #{t.name}"
end
file '_data/ec2-public-ips.json' do |t|
source = File.join(
'https://raw.githubusercontent.com',
'travis-infrastructure/terraform-config/master/aws-shared-2',
'generated-public-ip-addresses.json'
)
File.write(t.name, Faraday.get(source).body)
end
file '_data/ec2_public_ips.yml' => '_data/ec2-public-ips.json' do |t|
data = JSON.parse(File.read('_data/ec2-public-ips.json'))
by_site = %w[com org].map do |site|
[
site,
data['ips_by_host'].find { |d| d['host'] =~ /-#{site}-/ }
]
end
File.write(t.name, YAML.dump(by_site.to_h))
puts "Updated #{t.name}"
end
file '_data/gce_ip_range.yml' do |t|
# Using steps described in:
# https://cloud.google.com/compute/docs/faq#where_can_i_find_short_product_name_ip_ranges
# we populate the range of IP addresses for GCE instances
dns_root = ENV.fetch(
'GOOGLE_DNS_ROOT', '_cloud-netblocks.googleusercontent.com'
)
blocks = dns_txt(dns_root).grep(/^include:/).map do |bl|
dns_txt(bl.sub(/^include:/, '')).grep(/^ip4:/)
.map { |l| l.sub(/^ip4:/, '') }
end
File.write(
t.name,
YAML.dump(
'ip_ranges' => blocks.flatten
.compact
.sort { |a, b| IPAddr.new(a) <=> IPAddr.new(b) }
)
)
puts "Updated #{t.name}"
end
desc 'Refresh generated files'
task regen: [
:clean,
'_data/ec2_public_ips.yml',
'_data/gce_ip_range.yml',
'_data/trusty_language_mapping.yml'
]
desc 'Remove generated files'
task :clean do
rm_f(%w[
_data/ec2_public_ips.yml
_data/ec2-public-ips.json
_data/gce_ip_range.yml
_data/trusty-language-mapping.json
_data/trusty_language_mapping.yml
])
end
desc 'Start Jekyll server'
task serve: :regen do
sh 'bundle exec jekyll serve --config=_config.yml'
end
namespace :assets do
task precompile: :build
end