|
| 1 | +name: Check Links In Pull Requests |
| 2 | +permissions: {} |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + check-links: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Clone repository |
| 17 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + ref: ${{github.event.pull_request.head.ref}} |
| 21 | + repository: ${{github.event.pull_request.head.repo.full_name}} |
| 22 | + |
| 23 | + - name: Checkout base branch |
| 24 | + run: git checkout ${{ github.event.pull_request.base.ref }} |
| 25 | + |
| 26 | + - name: Get list of changed Markdown files |
| 27 | + id: changed-files |
| 28 | + run: | |
| 29 | + git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.head_ref }} -- '*.md' > changed-files.txt |
| 30 | + cat changed-files.txt |
| 31 | + if [ -s changed-files.txt ]; then |
| 32 | + echo "Changed md files found" |
| 33 | + echo "foundFiles=true" >> $GITHUB_ENV |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Switch to PR branch |
| 37 | + run: git checkout ${{ github.head_ref }} |
| 38 | + |
| 39 | + - name: Check links in changed files |
| 40 | + if: env.foundFiles == 'true' |
| 41 | + uses: lycheeverse/lychee-action@f796c8b7d468feb9b8c0a46da3fac0af6874d374 # v2.2.0 |
| 42 | + with: |
| 43 | + failIfEmpty: false |
| 44 | + args: | |
| 45 | + --no-progress |
| 46 | + $(cat changed-files.txt | tr '\n' ' ') |
| 47 | +
|
| 48 | + - name: Provide helpful failure message |
| 49 | + if: failure() |
| 50 | + run: | |
| 51 | + echo "::error::Link check failed! Please review the broken links reported above." |
| 52 | + echo "" |
| 53 | + echo "If certain links are valid but fail due to:" |
| 54 | + echo "- CAPTCHA challenges" |
| 55 | + echo "- IP blocking" |
| 56 | + echo "- Authentication requirements" |
| 57 | + echo "- Rate limiting" |
| 58 | + echo "" |
| 59 | + echo "Consider adding them to .lycheeignore to bypass future checks." |
| 60 | + echo "Format: Add one URL pattern per line" |
| 61 | + exit 1 |
0 commit comments