|
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 |
| 2 | +#Use the skip-link-check label on a PR to skip checking links on a PR |
3 | 3 |
|
4 | 4 | name: link check on PR |
5 | 5 |
|
|
8 | 8 | branches: [main] |
9 | 9 |
|
10 | 10 | jobs: |
11 | | - check-links: |
| 11 | + linkChecker: |
12 | 12 | runs-on: ubuntu-latest |
| 13 | + |
13 | 14 | steps: |
14 | | - - name: Clone repository |
15 | | - uses: actions/checkout@v4 |
| 15 | + - uses: actions/checkout@v4 |
16 | 16 | with: |
17 | | - fetch-depth: 0 |
18 | | - ref: ${{github.event.pull_request.head.ref}} |
19 | | - repository: ${{github.event.pull_request.head.repo.full_name}} |
| 17 | + fetch-depth: 1 |
20 | 18 |
|
21 | | - - name: Check out main branch |
22 | | - run: git checkout main |
| 19 | + - name: Get Changed Files |
| 20 | + id: changed-files |
| 21 | + uses: tj-actions/changed-files@v41 |
23 | 22 |
|
24 | | - - name: Dump all links from main |
25 | | - id: dump_links_from_main |
26 | | - uses: lycheeverse/lychee-action@v1 |
| 23 | + - name: Check for Skip Label |
| 24 | + id: skip-label |
| 25 | + uses: actions/github-script@v6 |
27 | 26 | 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 |
| 27 | + script: | |
| 28 | + const labels = await github.rest.issues.listLabelsOnIssue({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + issue_number: context.issue.number |
| 32 | + }); |
| 33 | + return labels.data.some(label => label.name === 'skip-link-check'); |
| 34 | + |
| 35 | + - name: Check Links |
| 36 | + if: steps.skip-label.outputs.result == 'false' |
48 | 37 | uses: lycheeverse/lychee-action@v1 |
49 | 38 | with: |
50 | | - args: | |
51 | | - --no-progress |
52 | | - --include-fragments |
53 | | - . |
54 | | - # Fail action on broken links |
| 39 | + args: --accept=200,403,429 --base . --verbose --no-progress ${{ steps.changed-files.outputs.all_changed_files }} |
| 40 | + token: ${{ secrets.CUSTOM_TOKEN }} |
55 | 41 | fail: true |
56 | | - |
| 42 | + |
| 43 | + - name: Skip Message |
| 44 | + if: steps.skip-label.outputs.result == 'true' |
| 45 | + run: echo "Link check was skipped due to the presence of the 'skip-link-check' label." |
| 46 | + |
57 | 47 | - name: Suggestions |
58 | 48 | if: failure() |
59 | 49 | run: | |
60 | 50 | echo -e "\nPlease review the links reported in the Check links step above." |
61 | | - echo -e "If a link is valid but fails due to a CAPTCHA challenge, IP blocking, login requirements, etc., |
62 | | - consider adding such links to .lycheeignore file to bypass future checks.\n" |
| 51 | + echo -e "If a link is valid but fails due to a CAPTCHA challenge, IP blocking, login requirements, etc., consider adding such links to .lycheeignore file to bypass future checks.\n" |
63 | 52 | exit 1 |
0 commit comments