Skip to content

Commit a122bc8

Browse files
committed
Restructure CI build to only fail for changed pages
1 parent f2fc02e commit a122bc8

File tree

3 files changed

+95
-20
lines changed

3 files changed

+95
-20
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exclude:
1010
- cibuild.sh
1111
- .travis.yml
1212
- maintainer-notes.md
13+
- check-build-html.rb
1314

1415
gems:
1516
- jekyll-mentions

check-build-html.rb

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
require "jekyll"
2+
require "html-proofer"
3+
4+
$site_source_dir = ARGV[0]
5+
$site_dest_dir = ARGV[1]
6+
$target_range = ARGV[2]
7+
8+
$only_proof_subset = !!$target_range && !$target_range.empty?
9+
10+
$proofer_runner = HTMLProofer::Runner.new([$site_dest_dir], {
11+
:type => :directory,
12+
:check_html => true,
13+
:allow_hash_href => true,
14+
:url_ignore => [
15+
/example\.com/,
16+
/https:\/\/github\.com\/myuser\/myrepo/,
17+
/robosnap\.net/,
18+
/https:\/\/github.com\/ev3dev\/ev3dev\.github\.io\/edit\/.*/,
19+
/warmcat\.com/,
20+
/robosnap\.net/,
21+
/01\.org/
22+
]
23+
})
24+
25+
begin
26+
$proofer_runner.run
27+
rescue => e
28+
puts e.message
29+
end
30+
31+
failures = $proofer_runner.instance_variable_get :@failures
32+
33+
changed_dest_files = []
34+
if $only_proof_subset
35+
$site = Jekyll::Site.new(Jekyll.configuration({
36+
"source" => $site_source_dir + "/",
37+
"config" => $site_source_dir + "/_config.yml",
38+
"destination" => $site_dest_dir,
39+
"safe" => true
40+
}))
41+
$site.read
42+
43+
$jekyll_file_map = {}
44+
def save_entity_mapping(jekyll_entity)
45+
current_dest_file = File.expand_path(jekyll_entity.destination $site.dest)
46+
$jekyll_file_map[File.expand_path(jekyll_entity.path)] = current_dest_file
47+
end
48+
49+
$site.pages.each do |page|
50+
save_entity_mapping page
51+
end
52+
53+
$site.posts.docs.each do |post|
54+
save_entity_mapping post
55+
end
56+
57+
$site.static_files.each do |file|
58+
save_entity_mapping file
59+
end
60+
61+
changed_source_files = `git -C "#{$site_source_dir}" diff --name-only #{$target_range} --`.split("\n")
62+
if $?.success?
63+
changed_dest_files = changed_source_files.map { |file| $jekyll_file_map[File.expand_path(file)] }.compact
64+
else
65+
$only_proof_subset = false
66+
end
67+
68+
end
69+
70+
fatal_failures = failures.select { |failure| !$only_proof_subset || (changed_dest_files.include? File.expand_path(failure.path)) }
71+
72+
if fatal_failures.empty?
73+
puts "No fatal failures found. There may be non-fatal failures printed above."
74+
exit 0
75+
else
76+
puts "The following fatal failures were found:"
77+
fatal_failures.each do |failure|
78+
puts "\t" + failure.to_s
79+
end
80+
exit 1
81+
end

cibuild.sh

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,21 @@ fi
2626
echo "Building site ------------------------------------"
2727
bundle exec jekyll build --trace
2828

29-
# credit: code snippet borrowed from jekyllrb.com website source
30-
IGNORE_HREFS=$(ruby -e 'puts %w{
31-
example.com
32-
https:\/\/github\.com\/myuser\/myrepo
33-
.*revolds-whitepaper\.pdf
34-
https:\/\/github.com\/ev3dev\/ev3dev\.github\.io\/edit\/.*
35-
warmcat.com
36-
robosnap.net
37-
01.org
38-
alldatasheet.com
39-
}.map{|h| "/#{h}/"}.join(",")')
40-
41-
# Explanation of ignored sites:
42-
# - example.com and github.com/myuser/myrepo are fake/example links
43-
# - The edit on github pages don't exist when you create a page, so ignoring them.
44-
# They are automatically generated anyway.
45-
# -revolds-whitepaper.pdf causes problems on travis but is really a good link (for now)
46-
# - warmcat.com works locally but fails on travis for some reason related to ssl
47-
4829
echo "Validating HTML ----------------------------------"
30+
31+
SOURCE_DIR="$(readlink -f .)"
32+
DEST_DIR="."
33+
34+
if [[ -z $TRAVIS || ($TRAVIS = true && $TRAVIS_EVENT_TYPE = "cron") ]]; then
35+
COMMIT_RESTRICTION_RANGE=""
36+
else
37+
COMMIT_RESTRICTION_RANGE="$TRAVIS_COMMIT_RANGE"
38+
fi
39+
40+
echo "Commit range target: $COMMIT_RESTRICTION_RANGE"
41+
4942
# We want to use the publish script so that we can implement other transformations in the future
50-
ruby publish.rb --no-fix-links --test "htmlproofer ./ --url-ignore $IGNORE_HREFS --check-html --allow-hash-href"
43+
ruby publish.rb --no-fix-links --test "ruby $(readlink -f check-build-html.rb) '$SOURCE_DIR' '$DEST_DIR' $COMMIT_RESTRICTION_RANGE"
5144

5245
# If the site build succeeded but we found BOMs, we want to fail the build
5346
if [ $FOUND_BOM == true ]

0 commit comments

Comments
 (0)