-
Notifications
You must be signed in to change notification settings - Fork 446
73 lines (65 loc) · 2.39 KB
/
Copy pathcheck-md-links.yml
File metadata and controls
73 lines (65 loc) · 2.39 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
name: Check Markdown Links
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-md-links:
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Collect added/modified Markdown files
id: changed
run: |
# Only added (A) or modified (M) files in this PR — deletions and renames-source are skipped.
# Three-dot diff (BASE...HEAD) gives the PR's own changes vs. the merge-base,
# so commits that landed on the base branch after this PR diverged are excluded.
{
echo 'files<<EOF'
git diff --name-only --diff-filter=AM \
"${{ github.event.pull_request.base.sha }}...HEAD" \
-- 'docs/**/*.md' 'docs/**/*.mdx' \
'i18n/zh-CN/docusaurus-plugin-content-docs/current/**/*.md' \
'i18n/zh-CN/docusaurus-plugin-content-docs/current/**/*.mdx'
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Check links in changed Markdown files
run: |
set -u
FILES="${{ steps.changed.outputs.files }}"
if [ -z "$FILES" ]; then
echo "No Markdown files added or modified in this PR. Skipping."
exit 0
fi
echo "Markdown files to check:"
echo "$FILES"
echo "------------------------------------------------------------"
FAILED=()
while IFS= read -r file; do
[ -z "$file" ] && continue
if [ ! -f "$file" ]; then
echo "Skip (not found in working tree): $file"
continue
fi
echo
echo "=== Checking: $file ==="
if ! python3 scripts/check_md_links_single.py "$file" --no-external; then
FAILED+=("$file")
fi
done <<< "$FILES"
echo
echo "============================================================"
if [ ${#FAILED[@]} -gt 0 ]; then
echo "❌ Broken internal links found in ${#FAILED[@]} file(s):"
for f in "${FAILED[@]}"; do
echo " - $f"
done
exit 1
fi
echo "✅ All checked Markdown files have valid internal links."