-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test documentation links against a TOC file #31
Conversation
cf24aa3
to
9971787
Compare
all_links.each do |key, doc_address| | ||
next unless doc_address.match?(/html/) | ||
failed[key] = doc_address unless checker.test_link(doc_address) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all_links.each do |key, doc_address| | |
next unless doc_address.match?(/html/) | |
failed[key] = doc_address unless checker.test_link(doc_address) | |
end | |
failed = all_links.filter { |_key, doc_address| !doc_address.include?('html') && checker.test_link(doc_address) } |
a42fa8f
to
b83b0bb
Compare
@ekohl Done, thanks! |
Where and how will be obtain (and host) the TOC file for the upcoming release and then execute this as part of the regular CI? Also, what about GA'ed versions, should we there also test against a TOC, even tho we do have published docs to test against? |
In my vision this will become a github action that we will be able to trigger on changes to either docs repo or theme repo.
The make task that generates TOC for upstream docs lives here: theforeman/foreman-documentation#2665. There is also a similar downstream PR that makes sure the downstream TOC is generated. I would vote against storing the TOC file somewhere since it's cheap to generate, although we can add it as a build artifact. Even though we can test against the GA'd docs, I suggest to reuse the same procedure. It is a matter of which git tag to check out on the docs repo clone, so I don't think it's a big difference. One of the advantages of this procedure, is the ability to test anchors validity (we didn't have it with the old tests by default). |
How do we get GitHub to access the downstream docs repo? |
Unfortunately for downstream, we will have to do it from the downstream side, unless there will be a decision to give access to the TOC file at least from upstream. This task accepts a filename_to_link file that we can beef up and use for translating upstream names in the TOC to downstream names (or translate downstream links to their upstream counterparts). This would give us the ability to test downstream links against the upstream documentation. This will not give us full confidence for topics specific to downstream, but at least for common ones - it will do the trick. |
This smells like a source for regressions then (= when a PR to this repo can't verify the links automatically). |
06a3169
to
21f09e3
Compare
Added TOC file to the fixtures directory. The file would be updated by automatic PRs. |
f869889
to
43e5b73
Compare
@@ -78,7 +78,7 @@ module Documentation | |||
}.freeze | |||
|
|||
SPECIAL_LINKS = [ | |||
[/docs\.theforeman\.org\/.*?\/Managing_Hosts\/.*?registering-a-host.*?managing-hosts/i, "#{ForemanThemeSatellite.documentation_root}/managing_hosts/registering_hosts_to_server_managing-hosts#Registering_Hosts_managing-hosts"], | |||
[/docs\.theforeman\.org\/.*?\/Managing_Hosts\/.*?registering-a-host.*?managing-hosts/i, "#{ForemanThemeSatellite.documentation_root}/managing_hosts/registering_hosts_to_server_managing-hosts#Registering_Hosts_by_Using_Global_Registration_managing-hosts"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same link exists in DOCS_GUIDES_LINKS
but wasn't updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForemanThemeSatellite::Documentation::DOCS_GUIDES_LINKS is untested
Added DOCS_GUIDES_LINKS hash too |
I don't think the test failures are related. Ready for another round |
test/link_checker.rb
Outdated
|
||
def extract_doc_path(path) | ||
# take the right part of the path after the '/html/' from the original link | ||
%r{/html/(.*)}.match(path)&.[](1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%r{/html/(.*)}.match(path)&.[](1) | |
%r{/html/(.*)}.match(path).to_a[1] |
that's the same, right? I was starring at that &.[]
too long.
(nil.to_a
is []
, so it works also when there is no match)
test/link_checker.rb
Outdated
split = path.match(%r{([^/]*)/(.*)}) | ||
first = split&.[](1) || path | ||
rest = split&.[](2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split = path.match(%r{([^/]*)/(.*)}) | |
first = split&.[](1) || path | |
rest = split&.[](2) | |
first, rest = path.split('/', 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% cat /tmp/bench.rb
require 'benchmark/ips'
path = "something/very/long/but/we/dont/care"
Benchmark.ips do |x|
x.report("regex") do
split = path.match(%r{([^/]*)/(.*)})
first = split&.[](1) || path
rest = split&.[](2)
end
x.report("split") do
first, rest = path.split('/', 2)
end
end
% ruby /tmp/bench.rb
Warming up --------------------------------------
regex 145.613k i/100ms
split 315.618k i/100ms
Calculating -------------------------------------
regex 1.423M (± 1.3%) i/s - 7.135M in 5.014002s
split 3.064M (± 0.7%) i/s - 15.465M in 5.047714s
;-)
'registering-a-host_managing-hosts' => "#{ForemanThemeSatellite.documentation_root}/managing_hosts/registering_hosts_to_server_managing-hosts#Registering_Hosts_managing-hosts", | ||
'registering-a-host_managing-hosts' => "#{ForemanThemeSatellite.documentation_root}/managing_hosts/registering_hosts_to_server_managing-hosts#Registering_Hosts_by_Using_Global_Registration_managing-hosts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test_docs_redirect_branded
failure is related, as you changed the link here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see inline comments.
ack once resolved
b9b985e
to
3b18ec8
Compare
Instead of testing against the production documentation, test against a TOC file that can be generated from non-published documentation.