|
| 1 | +# WHY-FILE: Automated link checking. |
| 2 | +# OBS: Behavior is configured in lychee.toml in this repository. |
| 3 | +# OBS: Runs on pull requests and monthly on schedule; manual trigger always available. |
| 4 | + |
| 5 | +name: Check Links |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: # WHY: Manual trigger - always available |
| 9 | + |
| 10 | + pull_request: # WHY: Validates PR links before merge |
| 11 | + |
| 12 | + schedule: |
| 13 | + - cron: "0 6 1 * *" # WHY: Runs monthly (1st of month) |
| 14 | + |
| 15 | +concurrency: |
| 16 | + # WHY: Prevent multiple simultaneous link checks on same ref |
| 17 | + group: link-check-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + lychee: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + issues: write |
| 27 | + pull-requests: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: 1) Checkout repository code |
| 31 | + uses: actions/checkout@v6 # OBS: v6 current as of Dec 2025 |
| 32 | + |
| 33 | + - name: 2) Check links with Lychee |
| 34 | + uses: lycheeverse/lychee-action@v2 |
| 35 | + with: |
| 36 | + args: > |
| 37 | + --config lychee.toml |
| 38 | + --user-agent "${{ github.repository }}/lychee" |
| 39 | + './**/*.bib' |
| 40 | + './**/*.md' |
| 41 | + './**/*.html' |
| 42 | + './**/*.tex' |
| 43 | + './**/*.yml' |
| 44 | + './**/*.yaml' |
| 45 | + lycheeVersion: latest # OBS: Always use latest lychee release |
| 46 | + env: |
| 47 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + - name: 3) Comment on PR if links broken |
| 50 | + if: failure() && github.event_name == 'pull_request' |
| 51 | + uses: actions/github-script@v8 |
| 52 | + with: |
| 53 | + script: | |
| 54 | + const runUrl = `${context.payload.repository.html_url}/actions/runs/${context.runId}`; |
| 55 | + const comment = [ |
| 56 | + "## Link Check Results", |
| 57 | + "", |
| 58 | + `Some links appear broken. Check the workflow logs: ${runUrl}`, |
| 59 | + ].join("\n"); |
| 60 | +
|
| 61 | + await github.rest.issues.createComment({ |
| 62 | + issue_number: context.issue.number, |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + body: comment, |
| 66 | + }); |
| 67 | +
|
| 68 | + - name: 4) Create issue for scheduled failures # WHY: Track broken links found during scheduled checks |
| 69 | + # OBS: Only creates issue if none already open with 'broken-links' label |
| 70 | + if: failure() && github.event_name == 'schedule' |
| 71 | + uses: actions/github-script@v8 |
| 72 | + with: |
| 73 | + script: | |
| 74 | + const date = new Date().toISOString().split("T")[0]; |
| 75 | + const title = `Link Check Failed - ${date}`; |
| 76 | + const runUrl = `${context.payload.repository.html_url}/actions/runs/${context.runId}`; |
| 77 | + const body = `Monthly link check found broken links.\n\nWorkflow logs: ${runUrl}`; |
| 78 | +
|
| 79 | + const existing = await github.rest.issues.listForRepo({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + labels: "broken-links", |
| 83 | + state: "open", |
| 84 | + }); |
| 85 | +
|
| 86 | + if (existing.data.length === 0) { |
| 87 | + await github.rest.issues.create({ |
| 88 | + owner: context.repo.owner, |
| 89 | + repo: context.repo.repo, |
| 90 | + title, |
| 91 | + body, |
| 92 | + labels: ["maintenance", "broken-links"], |
| 93 | + }); |
| 94 | + } |
0 commit comments