Repository navigation
Add a link checker for links added or changed in a PR - #1875
Conversation
|
@eastagiletracker This can be a good start. Could you align the versions used with the one of our current link checker? https://github.com/elixir-europe/rdmkit/blob/master/.github/workflows/link-check.yml |
| branches: [master, main] | ||
| paths: | ||
| - '**.md' | ||
| - '**.html' |
There was a problem hiding this comment.
we don't have html as content files so this can be removed
There was a problem hiding this comment.
Removed in 59e2b49, the trigger paths are now .md, .yml and .yaml.
| # extracts the links from them. Written outside the workspace because | ||
| # lychee-action removes ./lychee before it runs. | ||
| git diff --unified=0 --no-color --diff-filter=AMR "$BASE_SHA...$HEAD_SHA" \ | ||
| -- '*.md' '*.html' '*.yml' '*.yaml' ':(exclude).github/**' \ |
There was a problem hiding this comment.
Removed from the git diff pathspec as well (59e2b49).
| with: | ||
| # External links only: relative links and {% tool %} tags are resolved | ||
| # at build time and covered by the nightly check of the built site. | ||
| args: --no-progress --scheme https --scheme http --exclude '^https://github\.com' --accept '100..=103,200..=299,429' ${{ runner.temp }}/pr-added-lines.md |
There was a problem hiding this comment.
align settings as much as relevant to https://github.com/elixir-europe/rdmkit/blob/master/.github/workflows/link-check.yml
There was a problem hiding this comment.
Aligned in 59e2b49 where it applies. Same as link-check.yml: lychee-action v2.9.0, Lychee v0.24.2, the ^https://github\.com exclusion, a --root-dir, id: lychee and the github.repository_owner == 'elixir-europe' guard. Kept different on purpose:
fail: true, because failing the PR is the point of this check (the nightly job reports instead).--scheme https --scheme http, because the PR job checks raw diff lines, not the built_site, so relative links and{% tool %}tags cannot resolve here. The nightly job still checks those.--accept ...,429, so a rate-limited site does not block a PR. Happy to drop it if you prefer to match the nightly job exactly.--fallback-extensions htmland the--exclude-pathentries are not needed, since they only apply to the built_site.
One correction to my earlier comment: with v0.24.2, Lychee reports root-relative links such as [..](/github_way) as errors unless a root dir is given, so the version bump alone would have failed PRs that touch paragraphs with those links. --root-dir now resolves them to file:// URLs, which the scheme filter skips. I checked this on the existing pages/ paragraphs that contain root-relative links: 4 errors without the flag, 0 with it. A real 404 still fails, and actionlint is clean.
There was a problem hiding this comment.
change filename to pr-link-check.yml to align with https://github.com/elixir-europe/rdmkit/blob/master/.github/workflows/pr-checklist.yml naming
There was a problem hiding this comment.
Renamed to .github/workflows/pr-link-check.yml (59e2b49).
|
What happens with false positives? Does that mean the page can not be brought live? |
|
@bedroesb No, it does not block anything by itself. For a known false positive (a site that blocks bots with a 403, a flaky host and so on) there are two options:
Rate-limited responses (429) are already accepted, which removes the most common false positive. If you would rather never see a red X, I can switch it to One more note: this PR only changes |
|
Thanks, lets try it out after merge! |
This PR proposes a pull-request link checker that runs Lychee on only the links a PR adds or changes (Fixes #1754). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/669. You can sign in with your GitHub ID to claim ownership of the project.
Today the only link check is the nightly
Link Checkerworkflow, which builds the whole site and reports into #1570, so a broken link reachesmasterfirst and is found a day later. On currentmaster(6bbfc3d1) none of the workflows that run onpull_requestinvoke Lychee (grep -l lychee .github/workflows/*returns onlylink-check.yml, whose triggers arescheduleandworkflow_dispatch).The new
.github/workflows/pr-link-check.ymlruns on pull requests that touch.md,.ymlor.yamlcontent (not.github/). It takesgit diff --unified=0 base...head, keeps only the added lines, and passes them tolycheeverse/lychee-action@v2.9.0with the same Lychee version (v0.24.2) and the samegithub.comexclusion as the nightly job. Onlyhttp/httpslinks are checked, since relative and root-relative links and{% tool %}tags only resolve in the built site, which the nightly job still covers. The job fails when an added link is broken and writes the Lychee report to the job summary. It needs onlycontents: read, so it works for PRs from forks and never checks out or runs PR code with a writable token. Two details that are easy to trip over: the diff is written to$RUNNER_TEMPbecauselychee-actiondeletes./lycheebefore it runs, andfailIfEmpty: falseis set because a PR whose new lines contain no links should pass (the action fails such runs by default). Note that a Markdown paragraph is a single line in this repo, so editing one word re-checks every link in that paragraph. I read that as covering the "changed" part of the request.Verification. I ran the workflow on GitHub Actions in my fork, using three throwaway PRs that each append one line to
pages/national_resources/gr_resources.md:https://rdmkit.elixir-europe.org/this-page-does-not-exist-lc-test), a working link and a relative link: the job failed with[404] https://rdmkit.elixir-europe.org/this-page-does-not-exist-lc-test | Rejected status code ... Not Found(4 links: 1 OK, 1 broken, 2 excluded, namely the relative link and a reserved.invalidtest domain that Lychee skips by design){% tool "fega" %}tag and a relative link: passed (3 links checked, none broken)I also ran the same extraction and Lychee arguments locally against four merged commits (
1140c83cfega links,0600b296,acf037b8Spatial Transcriptomics Portal entry,8dc81626). Each picked up exactly the links that commit introduced, including theurl:field of a newtool_and_resource_list.ymlentry, and all passed. A non-existent domain is reported as a connection error.actionlintshows no new findings: its output on the workflows directory is the same before and after the change (two pre-existing notes inall-registry-links-update.ymlandjekyll.yml).How this was managed
This work was tracked as story pcj on a board imported from this repo's issues and pull requests, which we used to manage it.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com