-
Notifications
You must be signed in to change notification settings - Fork 522
64 lines (56 loc) · 2.14 KB
/
Copy pathbroken-links-checker.yml
File metadata and controls
64 lines (56 loc) · 2.14 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
name: Broken Link Checker
on:
pull_request:
paths:
- '**/*.md'
workflow_dispatch:
permissions:
contents: read
jobs:
markdown-link-check:
name: Check Markdown Broken Links
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v6
with:
fetch-depth: 0
# For PR : Get only changed markdown files
- name: Get changed markdown files (PR only)
id: changed-markdown-files
if: github.event_name == 'pull_request'
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
changed_files=$(git diff --name-only --diff-filter=ACMR "$BASE_SHA" "$HEAD_SHA" -- '*.md' | tr '\n' ' ' | sed 's/ *$//')
if [ -n "$changed_files" ]; then
echo "any_changed=true" >> "$GITHUB_OUTPUT"
else
echo "any_changed=false" >> "$GITHUB_OUTPUT"
fi
echo "all_changed_files=$changed_files" >> "$GITHUB_OUTPUT"
# For PR: Check broken links only in changed files
- name: Check Broken Links in Changed Markdown Files
id: lychee-check-pr
if: github.event_name == 'pull_request' && steps.changed-markdown-files.outputs.any_changed == 'true'
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0
with:
args: >
--verbose --no-progress --exclude ^https?://
${{ steps.changed-markdown-files.outputs.all_changed_files }}
failIfEmpty: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# For manual trigger: Check all markdown files in repo
- name: Check Broken Links in All Markdown Files in Entire Repo (Manual Trigger)
id: lychee-check-manual
if: github.event_name == 'workflow_dispatch'
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0
with:
args: >
--verbose --no-progress --exclude ^https?://
'**/*.md'
failIfEmpty: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}