-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathcheck_links.rb
31 lines (28 loc) · 1 KB
/
check_links.rb
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
require 'html-proofer'
begin
# Newly created files on feature branches do not yet exist in production, so tell HTML Proofer to ignore links to them
# Based on https://github.com/gjtorikian/html-proofer#ignoring-new-files
merge_base = `git merge-base origin/main HEAD`
new_urls = %x(git diff -z --name-only --diff-filter=AC #{merge_base})
.split("\0")
.filter { |path| path.start_with? "source/" }
.map { |path| path.delete_prefix("source/").delete_suffix(".erb").delete_suffix(".md") }
proofer = HTMLProofer.check_directory(
"build",
{
:assume_extension => true,
:allow_hash_href => true,
:check_internal_hash => true,
:ignore_files => [
/search/ # Provided by tech-docs gem but has a "broken" link from html-proofer's point of view
],
:ignore_urls => [
"https://gdshelpdesk.digital.cabinet-office.gov.uk",
/https:\/\/github.com\//
].concat(new_urls)
}
)
proofer.run
rescue RuntimeError => e
abort e.to_s
end