|
1 | | -name: Broken Link Checker |
| 1 | +name: Check Links In Pull Requests |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
|
8 | 8 |
|
9 | 9 | permissions: |
10 | 10 | contents: read |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
11 | 15 |
|
12 | 16 | jobs: |
13 | | - markdown-link-check: |
14 | | - name: Check Markdown Broken Links |
| 17 | + check-links: |
15 | 18 | runs-on: ubuntu-latest |
16 | 19 |
|
17 | 20 | steps: |
18 | | - - name: Checkout Repo |
| 21 | + - name: Checkout PR branch |
19 | 22 | uses: actions/checkout@v4 |
20 | 23 | with: |
21 | 24 | fetch-depth: 0 |
22 | 25 |
|
23 | | - - name: Get Added/Modified Markdown Files (PR only) |
| 26 | + - name: Set up Git |
| 27 | + run: git fetch origin ${{ github.base_ref }} |
| 28 | + |
| 29 | + - name: Get added/modified Markdown files |
24 | 30 | id: changed-files |
25 | | - if: github.event_name == 'pull_request' |
26 | 31 | run: | |
27 | | - git fetch origin ${{ github.base_ref }} |
28 | 32 | files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true) |
29 | 33 | echo "md_files<<EOF" >> $GITHUB_OUTPUT |
30 | 34 | echo "$files" >> $GITHUB_OUTPUT |
31 | 35 | echo "EOF" >> $GITHUB_OUTPUT |
32 | | - - name: Check Broken Links in Added/Modified Files (PR) |
33 | | - if: github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != '' |
| 36 | +
|
| 37 | + - name: Dump base branch links into ignore file |
| 38 | + if: steps.changed-files.outputs.md_files != '' |
| 39 | + run: | |
| 40 | + git checkout origin/${{ github.base_ref }} |
| 41 | + mkdir -p .lychee |
| 42 | + lychee --dump --include-fragments ${{ steps.changed-files.outputs.md_files }} > .lychee/ignore.txt || true |
| 43 | +
|
| 44 | + - name: Checkout PR branch again |
| 45 | + run: git checkout ${{ github.head_ref }} |
| 46 | + |
| 47 | + - name: Run lychee on PR changes |
| 48 | + if: steps.changed-files.outputs.md_files != '' |
34 | 49 | uses: lycheeverse/[email protected] |
35 | 50 | with: |
36 | 51 | args: > |
37 | | - --verbose --exclude-mail --no-progress --exclude ^https?:// |
| 52 | + --no-progress --include-fragments |
| 53 | + --max-concurrency 4 |
| 54 | + --exclude-mail |
| 55 | + --accept 200,429 |
| 56 | + --ignore-file .lychee/ignore.txt |
38 | 57 | ${{ steps.changed-files.outputs.md_files }} |
39 | 58 | failIfEmpty: false |
40 | 59 | env: |
41 | 60 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
42 | 61 |
|
| 62 | + - name: Provide helpful message on failure |
| 63 | + if: failure() |
| 64 | + run: | |
| 65 | + echo "::error::Link check failed! Please review broken links above." |
| 66 | + echo "If some links are false positives (e.g. behind auth, CAPTCHA)," |
| 67 | + echo "you can add them to a .lycheeignore or adjust the check." |
| 68 | + exit 1 |
| 69 | + |
43 | 70 | - name: Check Broken Links in Entire Repo (Manual) |
44 | 71 | if: github.event_name == 'workflow_dispatch' |
45 | 72 | uses: lycheeverse/[email protected] |
46 | 73 | with: |
47 | 74 | args: > |
48 | | - --verbose --exclude-mail --no-progress --exclude ^https?:// |
| 75 | + --verbose --exclude-mail --no-progress --exclude ^https?:// |
49 | 76 | '**/*.md' |
50 | 77 | failIfEmpty: false |
51 | 78 | output: lychee/out.md |
|
0 commit comments