-
Notifications
You must be signed in to change notification settings - Fork 708
Add automated broken link checking for documentation #7399
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
Open
ShivamJha2436
wants to merge
2
commits into
projectcontour:main
Choose a base branch
from
ShivamJha2436:docs-broken-link-checker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| name: Docs Broken Link Checker | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "site/content/docs/main/**/*.md" | ||
|
|
||
| schedule: | ||
| - cron: "0 7 * * 1" | ||
|
|
||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| link-check: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| # Lychee parses Markdown files, extracts URLs, and checks them via HTTP requests. | ||
| # The job fails if any broken links are detected. | ||
| - name: Run Lychee link checker (main docs only) | ||
| uses: lycheeverse/lychee-action@a8c4c7cb88f0c7386610c35eb25108e448569cb0 # v2.7.0 | ||
| with: | ||
| args: > | ||
| --verbose | ||
| --no-progress | ||
| --timeout 20 | ||
| --max-retries 3 | ||
| --retry-wait-time 5 | ||
| --exclude-mail | ||
| --accept 200,206,429 | ||
| --ignore-path .lycheeignore | ||
| --output lychee-report.md | ||
| --format markdown | ||
| "site/content/docs/main/**/*.md" | ||
|
|
||
| # Scheduled runs should create or update a tracking issue instead of opening duplicates. | ||
| - name: Create or update issue (scheduled runs only) | ||
| if: failure() && github.event_name == 'schedule' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require("fs"); | ||
|
|
||
| const title = "Broken links found in documentation"; | ||
| const report = fs.readFileSync("lychee-report.md", "utf8"); | ||
|
|
||
| // Search for an existing open issue with the same title | ||
| const search = await github.rest.search.issuesAndPullRequests({ | ||
| q: `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open "${title}"` | ||
| }); | ||
|
|
||
| if (search.data.total_count > 0) { | ||
| const issue = search.data.items[0]; | ||
|
|
||
| // Add the latest report as a comment | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: report | ||
| }); | ||
|
|
||
| console.log(`Updated existing issue #${issue.number}`); | ||
| } else { | ||
| // Create a new issue if none exists | ||
| await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title: title, | ||
| body: report, | ||
| labels: ["documentation", "automated"] | ||
| }); | ||
|
|
||
| console.log("Created new broken-links issue"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Lychee Ignore File for Contour Documentation Link Checks | ||
|
|
||
| # Purpose: | ||
| # - Avoid false positives from placeholder/dev links | ||
| # - Ignore dynamic GitHub URLs that cannot be validated reliably | ||
| # - Reduce CI noise while still catching real broken links | ||
|
|
||
| # Local development links (not valid in CI) | ||
| localhost | ||
| 127.0.0.1 | ||
|
|
||
| # Placeholder/example domains used in docs | ||
| example.com | ||
| example.org | ||
|
|
||
| # Mail links are not checkable as HTTP URLs | ||
| mailto:* | ||
|
|
||
| # GitHub issue creation links are dynamic and often return redirects | ||
| https://github.com/projectcontour/contour/issues/new* | ||
| https://github.com/projectcontour/contour/issues?q=* | ||
|
|
||
| # GitHub compare URLs are temporary/dynamic | ||
| https://github.com/projectcontour/contour/compare/* | ||
|
|
||
| # Common documentation short-links that may rate-limit bots | ||
| https://twitter.com/* | ||
| https://x.com/* |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.