-
Notifications
You must be signed in to change notification settings - Fork 117
/
Rakefile
148 lines (125 loc) · 4.82 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
#encoding: utf-8
namespace :links do
require 'html-proofer'
require 'optparse'
# ENABLE LINK CHECKING ON FILES STAGED FOR GIT COMMIT
# (QUICK LINK CHECK)
if ENV['QUICK_LINK_CHECK_ENABLED'].to_s.downcase == "true"
directories = %w(content)
merge_base = `git merge-base origin/source HEAD`.chomp
files_ignore = `git diff -z --name-only #{merge_base}`.split("\0")
files_ignore = files_ignore.select do |filename|
next true if directories.include?(File.dirname(filename))
filename.end_with?('.html') ||
filename.end_with?('.markdown') ||
filename.end_with?('.md')
end.map { |f|
# Verify regex at https://regex101.com
Regexp.new('^((?!' + File.basename(f, File.extname(f)) + ').)*$')
}
if files_ignore.length == 0
abort "No html, markdown, md files staged for git commit"
end
note = ''
# BLACK MAGIC TO HIJACK ARG AS A TASK
task ARGV.last.to_sym do ; end
# LINK CHECKING ON ALL FILES
else
files_ignore = []
note = '(This can take a few mins to run) '
end
desc 'Generate HTML of Kubevirt.io'
task :build do
if ARGV.length > 0
if ARGV.include? "quiet"
quiet = '-q'
# BLACK MAGIC TO HIJACK ARG AS A TASK
task ARGV.last.to_sym do ; end
else
quiet = ''
# BLACK MAGIC TO HIJACK ARG AS A TASK
task ARGV.last.to_sym do ; end
end
end
puts
puts "Building..."
sh 'bundle exec jekyll build' + ' ' + String(quiet)
end
desc 'Checks html files for broken external links'
task :test_external, [:ARGV] do
# Verify regex at https://regex101.com
options = {
:assume_extension => true,
:log_level => :info,
:external_only => true,
:internal_domains => ["https://instructor.labs.sysdeseng.com", "https://www.youtube.com"],
:url_ignore => [ /http(s)?:\/\/(kubevirt.io\/\/(user-guide)?(videos)?).*/,
/http(s)?:\/\/(www.)?killercoda.com.*/,
/http(s)?:\/\/(metal.)equinix.com.*/ ],
:url_swap => {'https://kubevirt.io/' => '',},
:http_status_ignore => [0, 400, 429, 999]
}
parser = OptionParser.new
parser.banner = "Usage: rake -- [arguments]"
# Added option -u which will remove the url_swap option to from the map
parser.on("-u", "--us", "Remove url_swap from htmlProofer") do |url_swap|
options.delete(:url_swap)
end
args = parser.order!(ARGV) {}
parser.parse!(args)
puts
puts "Checks html files for broken external links " + note + "..."
HTMLProofer.check_directory("./_site", options).run
end
desc 'Checks html files for broken internal links'
task :test_internal do
options = {
:assume_extension => true,
:allow_hash_href => true,
:log_level => :info,
:disable_external => true,
:http_status_ignore => [0, 200, 400, 429, 999]
}
puts
puts "Checks html files for broken internal links " + note + "..."
HTMLProofer.check_directory("./_site", options).run
end
desc 'Checks html files for links to nonexistant userguide selectors'
task :userguide_selectors => :build do
# Verify regex's at https://regex101.com
options = {
:log_level => :debug,
:checks_to_ignore => [ "ScriptCheck", "ImageCheck" ],
:assume_extension => true,
:only_4xx => true,
:allow_hash_href => true,
:enforce_https => true,
:check_external_hash => true,
:external_only => true,
:url_ignore => [
/http(s)?:\/\/(?!(kubevirt.io\/user-guide)).*/
],
}
puts
puts "Discovering links to userguide with selectors " + note + " ..."
# BLACK MAGIC BEGINS RIGHT HERE ...
io = StringIO.new
$stdout = io
HTMLProofer.check_directory("./_site", options).run
# UNCOMMENT TO enable full output of HTMLProofer
STDOUT.puts $stdout.string
$stdout.string.each_line do |f|
if f.include? "#"
if f.strip.match("Received a 200 for")
f["Received a "] = ''
f["for "] = ''
f[" in "] = ','
f.sub!(/^[0-9]+ /,'')
STDOUT.puts f
end
end
end
end
end
desc 'The default task will execute all tests in a row'
task :default => ['links:build']