@@ -12,12 +12,12 @@ jobs:
1212 runs-on : ubuntu-latest
1313
1414 steps :
15- - name : Checkout Repository
15+ - name : Checkout Repo
1616 uses : actions/checkout@v4
1717 with :
1818 fetch-depth : 0
1919
20- - name : Get Added/Modified Markdown Files (PR only)
20+ - name : Get Changed Markdown Files (PR only)
2121 id : changed-files
2222 if : github.event_name == 'pull_request'
2323 run : |
@@ -27,42 +27,63 @@ jobs:
2727 echo "$files" >> $GITHUB_OUTPUT
2828 echo "EOF" >> $GITHUB_OUTPUT
2929
30- - name : Prepare Sanitized Markdown Files (PR)
30+ - name : Run Initial Lychee Check (PR)
3131 if : github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != ''
32+ uses :
lycheeverse/[email protected] 33+ with :
34+ args : >
35+ --verbose --no-progress --exclude-mail --exclude ^https?://
36+ --output lychee/initial.out
37+ ${{ steps.changed-files.outputs.md_files }}
38+ env :
39+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
40+
41+ - name : Extract Markdown Files with Broken Links
42+ if : github.event_name == 'pull_request'
43+ id : affected-md
3244 run : |
33- rsync -av --exclude '.git' --exclude 'node_modules' ./ sanitized_md/
34- for file in ${{ steps.changed-files.outputs.md_files }}; do
35- if [ -f "sanitized_md/$file" ]; then
36- sed -i -e 's/<!--.*-->//g' -e '/<!--/,/-->/d' "sanitized_md/$file"
37- fi
45+ mkdir -p sanitized_md
46+ # Extract only .md file paths from the lychee output
47+ affected=$(grep -E 'file://.*\.md' lychee/initial.out | cut -d' ' -f1 | sed 's|file://||' | sort -u)
48+ echo "$affected"
49+ echo "affected_files<<EOF" >> $GITHUB_OUTPUT
50+ echo "$affected" >> $GITHUB_OUTPUT
51+ echo "EOF" >> $GITHUB_OUTPUT
52+
53+ - name : Strip HTML Comments from Affected Markdown Files Only
54+ if : steps.affected-md.outputs.affected_files != ''
55+ run : |
56+ for file in ${{ steps.affected-md.outputs.affected_files }}; do
57+ target="sanitized_md/$file"
58+ mkdir -p "$(dirname "$target")"
59+ # Copy the file and strip only comments
60+ perl -0777 -pe 's/<!--.*?-->//gs' "$file" > "$target"
3861 done
3962
40- - name : Run Lychee on Changed Markdown Files (PR)
41- if : github.event_name == 'pull_request' && steps.changed-files .outputs.md_files != ''
63+ - name : Rerun Lychee on Cleaned Files
64+ if : steps.affected-md .outputs.affected_files != ''
4265 uses :
lycheeverse/[email protected] 4366 with :
4467 args : >
45- --verbose --no-progress --exclude-mail
46- --exclude ^https?://
47- sanitized_md/${{ steps.changed-files.outputs.md_files }}
68+ --verbose --no-progress --exclude-mail --exclude ^https?://
69+ sanitized_md/**/*.md
4870 env :
4971 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5072
51- - name : Prepare Sanitized Markdown Files (Manual)
73+ - name : Full Repo Scan (Manual)
5274 if : github.event_name == 'workflow_dispatch'
5375 run : |
76+ mkdir -p sanitized_md
5477 rsync -av --exclude '.git' --exclude 'node_modules' ./ sanitized_md/
5578 find sanitized_md -name "*.md" -exec perl -0777 -i -pe 's/<!--.*?-->//gs' {} +
5679
57-
5880 - name : Run Lychee on Entire Repo (Manual)
5981 if : github.event_name == 'workflow_dispatch'
6082 uses :
lycheeverse/[email protected] 6183 with :
6284 args : >
63- --verbose --no-progress --exclude-mail
64- --exclude ^https?://
65- 'sanitized_md/**/*.md'
66- output : lychee/out.md
85+ --verbose --no-progress --exclude-mail --exclude ^https?://
86+ sanitized_md/**/*.md
87+ output : lychee/full.out
6788 env :
6889 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments