-
Notifications
You must be signed in to change notification settings - Fork 21
/
proof-html.rb
91 lines (82 loc) · 2.37 KB
/
proof-html.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
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
require "html-proofer"
require "json"
require "uri"
CHROME_FROZEN_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.0.0 Safari/537.36"
def get_bool(name, fallback)
s = ENV["INPUT_#{name}"]
return fallback if s.nil? or s == ""
case s
when /^t/i # matches "t", "true", "True"
true
when /^y/i # matches "y", "yes", "Yes"
true
when "1"
true
else
false
end
end
def get_int(name, fallback)
s = ENV["INPUT_#{name}"]
return fallback if s.nil? or s == ""
s.to_i
end
def get_str(name)
s = ENV["INPUT_#{name}"]
s.nil? ? "" : s
end
ignore_url_re = get_str("IGNORE_URL_RE").split("\n").map { |s| Regexp.new s }
ignore_url = get_str("IGNORE_URL").split("\n").concat ignore_url_re
tokens_str = get_str("TOKENS")
tokens = JSON.parse (tokens_str == "" ? "{}" : tokens_str)
swap_urls_str = get_str("SWAP_URLS")
swap_urls = JSON.parse (swap_urls_str == "" ? "{}" : swap_urls_str)
swap_urls.transform_keys! { |k| Regexp.new k }
checks = ["Links", "Scripts", "Images"]
if get_bool("CHECK_FAVICON", true)
checks.push("Favicon")
end
if get_bool("CHECK_OPENGRAPH", true)
checks.push("OpenGraph")
end
options = {
:checks => checks,
:cache => { :timeframe => {
:internal => "1d",
:external => "1d",
} },
:check_external_hash => get_bool("CHECK_EXTERNAL_HASH", true),
:ignore_empty_alt => get_bool("IGNORE_EMPTY_ALT", false),
:ignore_missing_alt => get_bool("IGNORE_MISSING_ALT", false),
:allow_missing_href => get_bool("ALLOW_MISSING_HREF", false),
:enforce_https => get_bool("ENFORCE_HTTPS", true),
:hydra => {
:max_concurrency => get_int("MAX_CONCURRENCY", 50),
},
:typhoeus => {
:cookiefile => ".cookies",
:cookiejar => ".cookies",
:connecttimeout => get_int("CONNECT_TIMEOUT", 30),
:followlocation => true,
:headers => {
"User-Agent" => CHROME_FROZEN_UA,
},
:timeout => get_int("TIMEOUT", 120),
},
:disable_external => get_bool("DISABLE_EXTERNAL", false),
:ignore_urls => ignore_url,
:swap_urls => swap_urls,
}
begin
proofer = HTMLProofer.check_directory(get_str("DIRECTORY"), options)
proofer.before_request do |request|
uri = URI.parse request.url
base = "#{uri.scheme}://#{uri.host}"
token = tokens[base]
request.options[:headers]["Authorization"] = "Bearer #{token}" unless token.nil?
end
proofer.run
rescue => msg
puts "#{msg}"
exit 1
end