Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit bf71ef8

Browse files
committed
Fixed issue with report generation and formatted Ruby code
1 parent ae0a190 commit bf71ef8

File tree

1 file changed

+63
-68
lines changed

1 file changed

+63
-68
lines changed

rakelib/test.rake

Lines changed: 63 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,66 @@
11
namespace :test do
2-
3-
# Run htmlproofer to check for broken links
4-
desc "Build devdocs and check for broken links"
5-
task links: %w[build links_no_build]
6-
7-
desc "Check the existing _site for broken links on Jenkins"
8-
task :cicd do
9-
10-
puts 'Checking links with htmlproofer...'.magenta
11-
12-
HTMLProofer.check_directory("_site", options).run
13-
2+
# Run htmlproofer to check for broken links
3+
desc 'Build devdocs and check for broken links'
4+
task links: %w[build links_no_build]
5+
6+
desc 'Check the existing _site for broken links on Jenkins'
7+
task :cicd do
8+
puts 'Checking links with htmlproofer...'.magenta
9+
10+
HTMLProofer.check_directory('_site', options).run
11+
end
12+
13+
desc 'Check the existing _site for broken links'
14+
task :links_no_build do
15+
begin
16+
# We're expecting link validation errors, but unless we rescue from StandardError, rake will abort and won't run the convert task (https://stackoverflow.com/a/10048406).
17+
# Wrapping task in a begin-rescue block prevents rake from aborting.
18+
# Seems to prevent printing an error count though.
19+
20+
puts 'Checking links with htmlproofer...'.magenta
21+
22+
# If you're running this for the first time, create the tmp/.htmlproofer directory first or the script fails.
23+
mkdir_p dir_name unless Dir.exist?(dir_name)
24+
25+
# Write console output (stderr only) to a file.
26+
# Use this if you need to also capture stdout: https://stackoverflow.com/a/2480439
27+
report = md_report_path
28+
$stderr.reopen(report, 'w+')
29+
30+
HTMLProofer.check_directory('_site', options).run
31+
32+
# We're expecting link validation errors, but unless we rescue from StandardError, rake will abort and won't run the convert task (https://stackoverflow.com/a/10048406).
33+
# Wrapping task in a begin-rescue block prevent rake from aborting.
34+
# Seems to prevent printing an error count though.
35+
rescue StandardError
36+
# Show how many lines contains the Markdown report
37+
size_in_lines(report)
1438
end
15-
16-
desc "Check the existing _site for broken links"
17-
task :links_no_build do
18-
19-
begin
20-
# We're expecting link validation errors, but unless we rescue from StandardError, rake will abort and won't run the convert task (https://stackoverflow.com/a/10048406).
21-
# Wrapping task in a begin-rescue block prevents rake from aborting.
22-
# Seems to prevent printing an error count though.
23-
24-
puts 'Checking links with htmlproofer...'.magenta
25-
26-
# If you're running this for the first time, create the tmp/.htmlproofer directory first or the script fails.
27-
mkdir_p dir_name unless Dir.exists?(dir_name)
28-
29-
# Write console output (stderr only) to a file.
30-
# Use this if you need to also capture stdout: https://stackoverflow.com/a/2480439
31-
$stderr.reopen(md_report_path, "w")
32-
33-
HTMLProofer.check_directory("_site", options).run
34-
35-
# We're expecting link validation errors, but unless we rescue from StandardError, rake will abort and won't run the convert task (https://stackoverflow.com/a/10048406).
36-
# Wrapping task in a begin-rescue block prevent rake from aborting.
37-
# Seems to prevent printing an error count though.
38-
rescue
39-
# Show how many lines contains the Markdown report
40-
size_in_lines(md_report_path)
41-
end
42-
end
43-
44-
desc "Checkout to the master branch and check the links"
45-
task on_master: %w[to_master links]
46-
47-
desc "Report about broken links in HTML"
48-
task report: %w[links] do
49-
50-
puts 'Converting the link check reports to HTML...'.magenta
51-
52-
# Locate the output directory, iterate over markdown files inside it, and convert those files to HTML.
53-
Find.find(dir_name) do |path|
54-
# Filter .md files only
55-
if File.extname(path) == '.md'
56-
print "Reading the #{path} ... ".magenta
57-
# Change a file extension to .html
58-
html_file = path.ext('html')
59-
File.open( html_file , 'w') do |file|
60-
print "converting to HTML ... ".magenta
61-
file.write kramdown( content(path) )
62-
file.write css
63-
end
64-
# Open the HTML reports in browser
65-
print "opening the converted report in browser ... ".magenta
66-
open_in_browser(html_file)
67-
puts "Done!".green
68-
end
69-
end
39+
end
40+
41+
desc 'Checkout to the master branch and check the links'
42+
task on_master: %w[to_master links]
43+
44+
desc 'Report about broken links in HTML'
45+
task report: %w[links] do
46+
puts 'Converting the link check reports to HTML...'.magenta
47+
48+
# Locate the output directory, iterate over markdown files inside it, and convert those files to HTML.
49+
Find.find(dir_name) do |path|
50+
# Filter .md files only
51+
next unless File.extname(path) == '.md'
52+
print "Reading the #{path} ... ".magenta
53+
# Change a file extension to .html
54+
html_file = path.ext('html')
55+
File.open(html_file, 'w') do |file|
56+
print 'converting to HTML ... '.magenta
57+
file.write kramdown(content(path))
58+
file.write css
59+
end
60+
# Open the HTML reports in browser
61+
print 'opening the converted report in browser ... '.magenta
62+
open_in_browser(html_file)
63+
puts 'Done!'.green
7064
end
71-
end
65+
end
66+
end

0 commit comments

Comments
 (0)