|
1 | | -name: Check Links In Pull Requests |
| 1 | +name: Broken Link Checker |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
|
9 | 9 | permissions: |
10 | 10 | contents: read |
11 | 11 |
|
12 | | -concurrency: |
13 | | - group: ${{ github.workflow }}-${{ github.ref }} |
14 | | - cancel-in-progress: true |
15 | | - |
16 | 12 | jobs: |
17 | | - check-links: |
| 13 | + markdown-link-check: |
| 14 | + name: Check Markdown Broken Links |
18 | 15 | runs-on: ubuntu-latest |
19 | 16 |
|
20 | 17 | steps: |
21 | | - - name: Clone repository |
| 18 | + - name: Checkout Repo |
22 | 19 | uses: actions/checkout@v4 |
23 | 20 | with: |
24 | 21 | fetch-depth: 0 |
25 | | - ref: ${{github.event.pull_request.head.ref}} |
26 | | - repository: ${{github.event.pull_request.head.repo.full_name}} |
27 | | - |
28 | | - - name: Check out base branch |
29 | | - run: git checkout ${{github.event.pull_request.base.ref}} |
30 | | - |
31 | | - - name: Dump all links from ${{github.event.pull_request.base.ref}} |
32 | | - uses: lycheeverse/lychee-action@v2 |
33 | | - with: |
34 | | - args: | |
35 | | - --dump |
36 | | - --include-fragments |
37 | | - --verbose --exclude-mail --no-progress --exclude ^https?:// |
38 | | - . |
39 | | - output: ./existing-links.txt |
40 | | - continue-on-error: true # Don't fail if base branch check has issues |
41 | | - |
42 | | - - name: Stash untracked files |
43 | | - run: git stash push --include-untracked |
44 | | - |
45 | | - - name: Check out feature branch |
46 | | - run: git checkout ${{ github.head_ref }} |
47 | 22 |
|
48 | | - - name: Apply stashed changes |
49 | | - run: git stash pop || true |
50 | | - |
51 | | - - name: Update ignore file |
| 23 | + - name: Get Added/Modified Markdown Files (PR only) |
| 24 | + id: changed-files |
| 25 | + if: github.event_name == 'pull_request' |
52 | 26 | run: | |
53 | | - if [ -f "existing-links.txt" ]; then |
54 | | - cat existing-links.txt >> .lycheeignore |
55 | | - fi |
56 | | -
|
57 | | - - name: Check links |
58 | | - uses: lycheeverse/lychee-action@v2 |
| 27 | + git fetch origin ${{ github.base_ref }} |
| 28 | + files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true) |
| 29 | + echo "md_files<<EOF" >> $GITHUB_OUTPUT |
| 30 | + echo "$files" >> $GITHUB_OUTPUT |
| 31 | + 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 != '' |
| 34 | + uses: lycheeverse/[email protected] |
59 | 35 | with: |
60 | 36 | args: > |
61 | 37 | --verbose --exclude-mail --no-progress --exclude ^https?:// |
62 | | - . |
| 38 | + ${{ steps.changed-files.outputs.md_files }} |
| 39 | + failIfEmpty: false |
| 40 | + env: |
| 41 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
63 | 42 |
|
64 | | - - name: Provide helpful failure message |
65 | | - if: failure() |
66 | | - run: | |
67 | | - echo "::error::Link check failed! Please review the broken links reported above." |
68 | | - echo "Format: Add one URL pattern per line" |
69 | | - exit 1 |
70 | | - |
71 | 43 | - name: Check Broken Links in Entire Repo (Manual) |
72 | 44 | if: github.event_name == 'workflow_dispatch' |
73 | 45 | uses: lycheeverse/[email protected] |
|
0 commit comments