-
Notifications
You must be signed in to change notification settings - Fork 296
85 lines (74 loc) · 2.66 KB
/
pr-link-check.yaml
File metadata and controls
85 lines (74 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Check Links In Pull Requests
on:
pull_request:
types: [ opened, edited, reopened, synchronize, ready_for_review ]
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-links-pr:
runs-on: ubuntu-slim
steps:
- name: Clone repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
persist-credentials: false
- name: Add upstream remote
run: |
upstreamurl="https://github.com/kubernetes-sigs/cluster-api-provider-openstack.git"
git remote add upstream "${upstreamurl}"
git fetch upstream
- name: Checkout base branch
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: git checkout "upstream/${BASE_REF}"
- name: Get list of changed Markdown files
id: changed-files
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REF: ${{ github.head_ref }}
run: |
git diff --name-only "upstream/${BASE_REF}...${HEAD_REF}" -- "*.md" > changed-files.txt
cat changed-files.txt
if [[ -s "changed-files.txt" ]]; then
echo "Changed md files found"
echo "foundFiles=true" >> "${GITHUB_ENV}"
fi
- name: Switch to PR branch
env:
HEAD_REF: ${{ github.head_ref }}
run: git checkout "${HEAD_REF}"
- name: Check links in changed files
if: env.foundFiles == 'true'
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0
with:
failIfEmpty: false
args: |
--user-agent "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0"
--root-dir "$(pwd)/"
--fallback-extensions "md"
--github-token "${GITHUB_TOKEN}"
--insecure
--max-retries 3
--retry-wait-time 5
--exclude-all-private
--no-progress
$(cat changed-files.txt | tr '\n' ' ')
- name: Provide helpful failure message
if: failure()
run: |
echo "::error::Link check failed! Please review the broken links reported above."
echo ""
echo "If certain links are valid but fail due to:"
echo "- CAPTCHA challenges"
echo "- IP blocking"
echo "- Authentication requirements"
echo "- Rate limiting"
echo ""
echo "Consider adding them to .lycheeignore to bypass future checks."
echo "Format: Add one URL pattern per line"
exit 1