|
1 | 1 | #Checks links in a PR to ensure they are valid. If link is valid but failing, it can be added to the .lycheeignore file |
2 | | -#Code source: https://github.com/lycheeverse/lychee-action/issues/238 |
3 | 2 |
|
4 | 3 | name: link check on PR |
5 | 4 |
|
6 | 5 | on: |
7 | 6 | pull_request: |
8 | 7 | branches: [main] |
9 | | - |
10 | 8 | jobs: |
11 | | - check-links: |
| 9 | + linkChecker: |
12 | 10 | runs-on: ubuntu-latest |
13 | 11 | steps: |
14 | | - - name: Clone repository |
15 | | - uses: actions/checkout@v4 |
| 12 | + - uses: actions/checkout@v4 |
16 | 13 | with: |
17 | | - fetch-depth: 0 |
18 | | - ref: ${{github.event.pull_request.head.ref}} |
19 | | - repository: ${{github.event.pull_request.head.repo.full_name}} |
20 | | - |
21 | | - - name: Check out main branch |
22 | | - run: git checkout main |
23 | | - |
24 | | - - name: Dump all links from main |
25 | | - id: dump_links_from_main |
| 14 | + fetch-depth: 1 |
| 15 | + - name: Get Changed Files |
| 16 | + id: changed-files |
| 17 | + uses: tj-actions/changed-files@v34 |
| 18 | + - name: Check Links |
26 | 19 | uses: lycheeverse/lychee-action@v1 |
27 | 20 | with: |
28 | | - args: | |
29 | | - --dump |
30 | | - --include-fragments |
31 | | - . |
32 | | - output: ./links-main.txt |
33 | | - |
34 | | - - name: Stash untracked files |
35 | | - run: git stash push --include-untracked |
36 | | - |
37 | | - - name: Check out feature branch |
38 | | - run: git checkout ${{ github.head_ref }} |
39 | | - |
40 | | - - name: Apply stashed changes |
41 | | - # Apply stashed changes, ignore errors if stash is empty |
42 | | - run: git stash pop || true |
43 | | - |
44 | | - - name: Append links-main.txt to .lycheeignore |
45 | | - run: cat links-main.txt >> .lycheeignore |
46 | | - |
47 | | - - name: Check links |
48 | | - uses: lycheeverse/lychee-action@v1 |
49 | | - with: |
50 | | - args: | |
51 | | - --no-progress |
52 | | - --include-fragments |
53 | | - . |
54 | | - # Fail action on broken links |
| 21 | + args: --accept=200,403,429 --base . --verbose --no-progress ${{ steps.changed-files.outputs.all_changed_files }} |
| 22 | + token: ${{ secrets.CUSTOM_TOKEN }} |
55 | 23 | fail: true |
56 | | - |
57 | 24 | - name: Suggestions |
58 | 25 | if: failure() |
59 | 26 | run: | |
|
0 commit comments