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

Fix flaky broken link checker #3173

Merged
merged 2 commits into from
Sep 29, 2023
Merged

Fix flaky broken link checker #3173

merged 2 commits into from
Sep 29, 2023

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Sep 25, 2023

We have a very flaky npm run check-links script at the moment

This PR partially fixes #3113 and alphagov/govuk-frontend#4223 makes the link checker stable by:

1. Avoiding sitemap.xml parsing
2. Remove flag --source-maps
3. Remove flag --recursive (uses glob instead)
4. Replace reporter tap-mocha-reporter with tap-min
5. Saving output to disk before piping to reporter

Task output

In the past we've switched reporter to increase stability but see Munter/hyperlink#179 (comment). The best fix was to pipe to disk first, using the README suggestion in #3173 (comment)

Initially this PR bypassed the reporter entirely but output was too noisy:

> check-links
> hyperlink --canonicalroot https://design-system.service.gov.uk/ --internal --root deploy/public --skip "govuk/all.css" --skip "govuk-frontend/all.css" --skip "govuk-frontend/all.js" --skip "<YOUR-DOMAIN>" $(glob "deploy/public/**/*.html")

TAP version 13
# Crawling internal assets
ok 1 load deploy/public/index.html
ok 2 load deploy/public/google921002f57f264802.html
ok 3 load deploy/public/styles/index.html
ok 4 load deploy/public/sitemap/index.html
ok 5 load deploy/public/privacy-policy/index.html
ok 6 load deploy/public/patterns/index.html
ok 7 load deploy/public/get-started/index.html
ok 8 load deploy/public/get-in-touch/index.html
ok 9 load deploy/public/design-system-team/index.html
ok 10 load deploy/public/cookies/index.html

@netlify
Copy link

netlify bot commented Sep 25, 2023

You can preview this change here:

Name Link
🔨 Latest commit f68a012
🔍 Latest deploy log https://app.netlify.com/sites/govuk-design-system-preview/deploys/6516f50bb63d880008d6624a
😎 Deploy Preview https://deploy-preview-3173--govuk-design-system-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@colinrotherham colinrotherham changed the title Simplify link checker, fix known redirects Fix flaky link checker Sep 25, 2023
@colinrotherham colinrotherham changed the title Fix flaky link checker Fix flaky broken link checker Sep 25, 2023
@colinrotherham colinrotherham force-pushed the check-links-reporter branch 2 times, most recently from 24f69c3 to e4b596e Compare September 25, 2023 16:56
@colinrotherham
Copy link
Contributor Author

Moving back into draft as it's still returning exit codes but without error logs

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@domoscargin
Copy link
Contributor

All passing great locally - coupla questions. The output is annoying, but auditing the errors is just a "search for 'not ok'" away, so really not a biggie imo.

When used without `--internal` we see problems parsing external URLs when the `--source-maps` flag is also enabled

Removing it just in case
@romaricpascal
Copy link
Member

It's cheap enough to swap reporters so I'd be keen to try tap-min by merging and monitoring what happens for a bit.

If it fails, there's another option with tap-spot, mentioned in hyperlink's README... and we can always pipe to grep on CI to clean things up a bit if all reporters fail 😊

@colinrotherham
Copy link
Contributor Author

colinrotherham commented Sep 29, 2023

@romaricpascal Thanks, sadly tried using tap-min and we have 2 failures:

https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/1
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/2
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/3
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/4
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/5
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/6
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/7
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/8 ← ❌
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/9
https://github.com/alphagov/govuk-design-system/actions/runs/6341861869/attempts/10 ← ❌

For comparison on main I've also seen failures in 2 out of 10 runs:

https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/1
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/2 ← ❌
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/3
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/4
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/5
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/6
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/7
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/8 ← ❌
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/9
https://github.com/alphagov/govuk-design-system/actions/runs/6352016459/attempts/10

@colinrotherham
Copy link
Contributor Author

colinrotherham commented Sep 29, 2023

Note: With tap recent updates shall we keep tap-mocha-reporter and/or await tapjs/tap-mocha-reporter#76?

I'll do some more runs with the existing tap-mocha-reporter as Dependabot will update it on Monday anyway

Saving to disk before hitting the reporter appears to remove the flaky non-zero exit codes too

Co-authored-by: Romaric Pascal <[email protected]>
@romaricpascal
Copy link
Member

romaricpascal commented Sep 29, 2023

Whoop! 🥳 If adding tee solves the issue, that's neat. It also opens us up (in the future) to uploading the link checking results as an artifact when it fails, which could help automation/reprocessing things locally, so don't mind the extra command in between.

If things work just as well with tee and tap-mocha-reporter, I'd be keen to stick with tap-mocha-reporter (wider pool of people maintaining the project, being part of the tapjs org).

Thanks for re-running the checks so many times 😊

@colinrotherham
Copy link
Contributor Author

Yeah looking good still:

https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/1
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/2
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/3
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/4
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/5
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/6
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/7
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/8
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/9
https://github.com/alphagov/govuk-design-system/actions/runs/6354060722/attempts/10

To confirm, exit codes are still returned on failure too:
https://github.com/alphagov/govuk-design-system/actions/runs/6354399404/job/17260821602

> check-links
> hyperlink --canonicalroot https://design-system.service.gov.uk/ --internal --recursive deploy/public/sitemap.xml | tee check-links.log | tap-mocha-reporter min

Guessing --root from input files: file:///home/runner/work/govuk-design-system/govuk-design-system/deploy/public/

  2227 passing (39s)
  8 pending
  5 failing

  1) load deploy/public/components/hint-colin-broke-this-link:
     load deploy/public/components/hint-colin-broke-this-link
  

  2) load deploy/public/components/error-message-colin-broke-this-link:
     load deploy/public/components/error-message-colin-broke-this-link
  

  3) load deploy/public/components/fieldset-colin-broke-this-link:
     load deploy/public/components/fieldset-colin-broke-this-link
  

  4) load deploy/public/components/label-colin-broke-this-link:
     load deploy/public/components/label-colin-broke-this-link
  

  5) load deploy/public/components/tag-colin-broke-this-link:
     load deploy/public/components/tag-colin-broke-this-link

@colinrotherham colinrotherham merged commit 5918669 into main Sep 29, 2023
18 of 20 checks passed
@colinrotherham colinrotherham deleted the check-links-reporter branch September 29, 2023 16:36
@colinrotherham
Copy link
Contributor Author

colinrotherham commented Sep 29, 2023

@romaricpascal For info, Windows checks passed too (it includestee which is nice)

EditorConfig check has failures though but I've fixed these in #3183

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.

Improve our broken link checking tests
3 participants