|
| 1 | +name: Check Links In Pull Requests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, edited, reopened, synchronize, ready_for_review] |
| 6 | + |
| 7 | +permissions: {} |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-links-pr: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Clone repository |
| 19 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + ref: ${{github.event.pull_request.head.ref}} |
| 23 | + repository: ${{github.event.pull_request.head.repo.full_name}} |
| 24 | + |
| 25 | + - name: Add upstream remote |
| 26 | + run: | |
| 27 | + upstreamurl="https://github.com/kubernetes-sigs/cluster-api-provider-openstack.git" |
| 28 | + git remote add upstream "${upstreamurl}" |
| 29 | + git fetch upstream |
| 30 | +
|
| 31 | + - name: Checkout base branch |
| 32 | + run: git checkout "upstream/${{ github.event.pull_request.base.ref }}" |
| 33 | + |
| 34 | + - name: Get list of changed Markdown files |
| 35 | + id: changed-files |
| 36 | + run: | |
| 37 | + git diff --name-only "upstream/${{ github.event.pull_request.base.ref }}...${{ github.head_ref }}" -- "*.md" > changed-files.txt |
| 38 | + cat changed-files.txt |
| 39 | + if [[ -s "changed-files.txt" ]]; then |
| 40 | + echo "Changed md files found" |
| 41 | + echo "foundFiles=true" >> "${GITHUB_ENV}" |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Switch to PR branch |
| 45 | + run: git checkout ${{ github.head_ref }} |
| 46 | + |
| 47 | + - name: Check links in changed files |
| 48 | + if: env.foundFiles == 'true' |
| 49 | + uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2.4.1 |
| 50 | + with: |
| 51 | + failIfEmpty: false |
| 52 | + args: | |
| 53 | + --user-agent "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0" |
| 54 | + --root-dir "$(pwd)/" |
| 55 | + --fallback-extensions "md" |
| 56 | + --github-token "${GITHUB_TOKEN}" |
| 57 | + $(cat changed-files.txt | tr '\n' ' ') |
| 58 | +
|
| 59 | + - name: Provide helpful failure message |
| 60 | + if: failure() |
| 61 | + run: | |
| 62 | + echo "::error::Link check failed! Please review the broken links reported above." |
| 63 | + echo "" |
| 64 | + echo "If certain links are valid but fail due to:" |
| 65 | + echo "- CAPTCHA challenges" |
| 66 | + echo "- IP blocking" |
| 67 | + echo "- Authentication requirements" |
| 68 | + echo "- Rate limiting" |
| 69 | + echo "" |
| 70 | + echo "Consider adding them to .lycheeignore to bypass future checks." |
| 71 | + echo "Format: Add one URL pattern per line" |
| 72 | + exit 1 |
0 commit comments