Skip to content
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

Merged
merged 4 commits into from
Apr 18, 2024

Conversation

ShimShtein
Copy link
Contributor

Instead of testing against the production documentation, test against a TOC file that can be generated from non-published documentation.

Comment on lines 61 to 64
all_links.each do |key, doc_address|
next unless doc_address.match?(/html/)
failed[key] = doc_address unless checker.test_link(doc_address)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) }

@ShimShtein ShimShtein force-pushed the link_checker branch 2 times, most recently from a42fa8f to b83b0bb Compare January 14, 2024 15:00
@ShimShtein
Copy link
Contributor Author

@ekohl Done, thanks!

@evgeni
Copy link
Member

evgeni commented Jan 17, 2024

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?
My concern is that with todays setup we have "test links for N+1 release against prod N docs" which works in 80% of the cases, while with the current state of this PR we effectively move to "test links on demand by some magic process" (as the TOC file is not in the PR) thus possibly missing things when a PR does change the link but CI doesn't turn red.

Also, what about GA'ed versions, should we there also test against a TOC, even tho we do have published docs to test against?

@ShimShtein
Copy link
Contributor Author

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?

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 task should look like this:

  1. Make sure we have ruby and asciidoctor are installed
  2. Clone the theme repo
  3. Clone the documentation repo
  4. In the documentation repo run make task that generates the TOC file
  5. In the theme repo, run the rake task

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).

@evgeni
Copy link
Member

evgeni commented Jan 17, 2024

How do we get GitHub to access the downstream docs repo?

@ShimShtein
Copy link
Contributor Author

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.

@evgeni
Copy link
Member

evgeni commented Jan 17, 2024

This smells like a source for regressions then (= when a PR to this repo can't verify the links automatically).

@ShimShtein ShimShtein force-pushed the link_checker branch 3 times, most recently from 06a3169 to 21f09e3 Compare February 20, 2024 09:40
@ShimShtein
Copy link
Contributor Author

Added TOC file to the fixtures directory. The file would be updated by automatic PRs.

@@ -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"],
Copy link
Member

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?

Copy link
Member

@evgeni evgeni left a 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

@ShimShtein
Copy link
Contributor Author

Added DOCS_GUIDES_LINKS hash too

@ShimShtein
Copy link
Contributor Author

I don't think the test failures are related. Ready for another round


def extract_doc_path(path)
# take the right part of the path after the '/html/' from the original link
%r{/html/(.*)}.match(path)&.[](1)
Copy link
Member

@evgeni evgeni Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
%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)

Comment on lines 44 to 46
split = path.match(%r{([^/]*)/(.*)})
first = split&.[](1) || path
rest = split&.[](2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
split = path.match(%r{([^/]*)/(.*)})
first = split&.[](1) || path
rest = split&.[](2)
first, rest = path.split('/', 2)

Copy link
Member

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",
Copy link
Member

@evgeni evgeni Apr 15, 2024

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.

Copy link
Member

@evgeni evgeni left a 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

@evgeni evgeni merged commit 7fb213d into RedHatSatellite:develop Apr 18, 2024
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants