66 - ' **/*.md'
77 workflow_dispatch :
88
9+ permissions :
10+ contents : read
11+
912jobs :
1013 markdown-link-check :
1114 name : Check Markdown Broken Links
@@ -17,109 +20,48 @@ jobs:
1720 with :
1821 fetch-depth : 0
1922
20- - name : Mirror Repo to sanitized_md/
21- run : |
22- rsync -av --exclude '.git' --exclude 'node_modules' ./ sanitized_md/
23-
24- # ‣ PR: get only changed .md files
25- - name : Get Changed Markdown Files (PR)
23+ - name : Get Added/Modified Markdown Files (PR only)
2624 id : changed-files
2725 if : github.event_name == 'pull_request'
2826 run : |
2927 git fetch origin ${{ github.base_ref }}
30- files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD \
31- | grep '\.md$' || true)
28+ files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '\.md$' || true)
3229 echo "md_files<<EOF" >> $GITHUB_OUTPUT
3330 echo "$files" >> $GITHUB_OUTPUT
3431 echo "EOF" >> $GITHUB_OUTPUT
3532
36- # ‣ PR: initial Lychee run
37- - name : Initial Lychee Check on Changed Files (PR)
33+ - name : Strip HTML comments from markdown
3834 if : github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != ''
39- uses :
lycheeverse/[email protected] 40- with :
41- output : lychee/pr.out
42- args : >
43- --verbose --no-progress --exclude-mail --exclude '^https?://'
44- ${{ steps.changed-files.outputs.md_files }}
45- env :
46- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
47-
48- # ‣ PR: extract only the .md files with errors
49- - name : Extract Affected Files (PR)
50- if : github.event_name == 'pull_request'
51- id : affected-pr
5235 run : |
53- mkdir -p sanitized_md
54- grep -Eo 'file://[^ ]+\.md' lychee/pr.out \
55- | sed 's|file://||' \
56- | sort -u \
57- | tee affected.txt
58- echo "affected_files<<EOF" >> $GITHUB_OUTPUT
59- cat affected.txt >> $GITHUB_OUTPUT
60- echo "EOF" >> $GITHUB_OUTPUT
36+ for file in ${{ steps.changed-files.outputs.md_files }}; do
37+ # Remove all HTML comments (multi-line aware) in-place
38+ sed -z -i 's/<!--[\s\S]*?-->//g' "$file"
39+ done
6140
62- # ‣ PR: strip comments **in the copies**
63- - name : Strip HTML Comments from Affected Files (PR)
64- if : steps.affected-pr.outputs.affected_files != ''
65- run : |
66- while read -r file; do
67- src="sanitized_md/$file"
68- perl -0777 -pe 's/<!--.*?-->//gs' "$src" > "$src.tmp" \
69- && mv "$src.tmp" "$src"
70- done < affected.txt
71-
72- # ‣ PR: **re-run** Lychee on the **sanitized** files
73- - name : Re-check Sanitized Affected Files (PR)
74- if : steps.affected-pr.outputs.affected_files != ''
75- uses :
lycheeverse/[email protected] 76- with :
77- args : >
78- --verbose --no-progress --exclude-mail --exclude '^https?://'
79- sanitized_md/**/*.md
80- env :
81- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
82-
83- # --- Manual Dispatch: same two-pass logic ---
84- - name : Initial Lychee Check on All Markdown (Manual)
85- if : github.event_name == 'workflow_dispatch'
41+ - name : Check Broken Links in Added/Modified Files (PR)
42+ if : github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != ''
8643 uses :
lycheeverse/[email protected] 8744 with :
88- output : lychee/manual.out
8945 args : >
90- --verbose --no-progress --exclude-mail --exclude ' ^https?://'
91- '**/*.md'
46+ --verbose --exclude-mail --no-progress --exclude ^https?://
47+ ${{ steps.changed-files.outputs.md_files }}
9248 env :
9349 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9450
95- - name : Extract Affected Files (Manual )
51+ - name : Strip HTML comments (manual run )
9652 if : github.event_name == 'workflow_dispatch'
97- id : affected-manual
9853 run : |
99- mkdir -p sanitized_md
100- grep -Eo 'file://[^ ]+\.md' lychee/manual.out \
101- | sed 's|file://||' \
102- | sort -u \
103- | tee affected-manual.txt
104- echo "affected_files<<EOF" >> $GITHUB_OUTPUT
105- cat affected-manual.txt >> $GITHUB_OUTPUT
106- echo "EOF" >> $GITHUB_OUTPUT
54+ for file in **/*.md; do
55+ sed -z -i 's/<!--[\s\S]*?-->//g' "$file"
56+ done
10757
108- - name : Strip HTML Comments (Manual)
109- if : steps.affected-manual.outputs.affected_files != ''
110- run : |
111- while read -r file; do
112- src="sanitized_md/$file"
113- perl -0777 -pe 's/<!--.*?-->//gs' "$src" > "$src.tmp" \
114- && mv "$src.tmp" "$src"
115- done < affected-manual.txt
116-
117- - name : Re-check Sanitized Affected Files (Manual)
118- if : steps.affected-manual.outputs.affected_files != ''
58+ - name : Check Broken Links in Entire Repo (Manual)
59+ if : github.event_name == 'workflow_dispatch'
11960 uses :
lycheeverse/[email protected] 12061 with :
12162 args : >
122- --verbose --no-progress --exclude-mail --exclude '^https?://'
123- sanitized_md/**/*.md
63+ --verbose --exclude-mail --no-progress --exclude ^https?://
64+ '**/*.md'
65+ output : lychee/out.md
12466 env :
12567 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments