@@ -30,77 +30,75 @@ jobs:
3030 echo "$files" >> $GITHUB_OUTPUT
3131 echo "EOF" >> $GITHUB_OUTPUT
3232
33- - name : Run Lychee (PR)
33+ - name : Check Broken Links in Added/Modified Files (PR)
3434 if : github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != ''
35- run : |
36- npx lychee --verbose --exclude-mail --no-progress --exclude ^https?:// ${{ steps.changed-files.outputs.md_files }} > lychee_output.txt || true
35+ uses :
lycheeverse/[email protected] 36+ with :
37+ args : >
38+ --verbose --exclude-mail --no-progress --exclude ^https?://
39+ ${{ steps.changed-files.outputs.md_files }}
40+ env :
41+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3742
38- - name : Run Lychee (Manual)
43+ - name : Check Broken Links in Entire Repo (Manual)
3944 if : github.event_name == 'workflow_dispatch'
40- run : |
41- npx lychee --verbose --exclude-mail --no-progress --exclude ^https?:// '**/*.md' > lychee_output.txt || true
42-
43- - name : Filter Commented-Out Links from Output
44- run : |
45- cat > filter_lychee_output.sh <<'EOF'
46- #!/bin/bash
47- LYCHEE_OUTPUT_FILE="lychee_output.txt"
48- FINAL_OUTPUT_FILE="lychee_final_output.txt"
49- > "$FINAL_OUTPUT_FILE"
50-
51- current_file=""
52-
53- while IFS= read -r line; do
54- if [[ "$line" =~ ^Errors\ in\ (.*)\ \[ERROR\]?$ ]]; then
55- current_file="${BASH_REMATCH[1]}"
56- echo "$line" >> "$FINAL_OUTPUT_FILE"
57- continue
58- fi
59-
60- if [[ "$line" =~ file://(.*)\ \| ]]; then
61- full_path="${BASH_REMATCH[1]}"
62- broken_link=$(basename "$full_path")
63-
64- if [ -f "$current_file" ]; then
65- if grep -zoP "(?s)<!--.*?$broken_link.*?-->" "$current_file" > /dev/null; then
66- echo "Skipping commented-out link: $broken_link in $current_file"
67- continue
68- fi
69- fi
70-
71- echo "$line" >> "$FINAL_OUTPUT_FILE"
72- fi
73- done < "$LYCHEE_OUTPUT_FILE"
74-
75- echo "Filtered Lychee output saved to $FINAL_OUTPUT_FILE"
76- EOF
77-
78- chmod +x filter_lychee_output.sh
79- ./filter_lychee_output.sh
80-
81- - name : Save Filtered Errors to Markdown File
82- run : |
83- mkdir -p lychee
84- echo "# 🔗 Broken Link Report" > lychee/out.md
85- echo "" >> lychee/out.md
86- if [ -s lychee_final_output.txt ]; then
87- cat lychee_final_output.txt >> lychee/out.md
88- else
89- echo "✅ No non-commented broken links found." >> lychee/out.md
90- fi
91-
92- - name : Upload Filtered Report as Artifact
93- uses : actions/upload-artifact@v4
45+ uses :
lycheeverse/[email protected] 9446 with :
95- name : filtered-link-report
96- path : lychee/out.md
97-
98- - name : Fail if Real Broken Links Remain
47+ args : >
48+ --verbose --exclude-mail --no-progress --exclude ^https?://
49+ '**/*.md'
50+ output : lychee/out.md
51+ env :
52+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
53+
54+ - name : Clean lychee/out.md by removing errors inside HTML comments
55+ if : github.event_name == 'workflow_dispatch'
56+ run : |
57+ FILTERED="lychee/out.md.cleaned"
58+ > "$FILTERED"
59+
60+ awk '
61+ BEGIN { RS="### "; FS="\n" }
62+ NR == 1 { next }
63+ {
64+ header = "### " $1
65+ file_section = $1
66+ file_path = ""
67+
68+ if (match(file_section, /in (.*\.md)/, m)) {
69+ file_path = m[1]
70+ }
71+
72+ keep_section = ""
73+ for (i = 2; i <= NF; i++) {
74+ line = $i
75+ if (match(line, /\((file:\/\/[^\)]+)\)/, mfile)) {
76+ fullpath = mfile[1]
77+ localpath = substr(fullpath, 8)
78+ filename = gensub(/^.*\//, "", "g", localpath)
79+
80+ cmd = "awk \047BEGIN{incomment=0} /<!--/{incomment=1} /-->/&&incomment{incomment=0; next} incomment && index(\\\$0, \\\"" filename "\\\")>0 {exit 0} END{exit 1}\047 \"" file_path "\""
81+ status = system(cmd)
82+
83+ if (status != 0) {
84+ keep_section = keep_section line "\n"
85+ }
86+ } else {
87+ keep_section = keep_section line "\n"
88+ }
89+ }
90+
91+ if (length(keep_section) > 0) {
92+ print header "\n" keep_section >> "'"$FILTERED"'"
93+ }
94+ }
95+ ' lychee/out.md
96+
97+ mv "$FILTERED" lychee/out.md
98+
99+ - name : Show Cleaned Report
100+ if : github.event_name == 'workflow_dispatch'
99101 run : |
100- if grep -q "\[ERROR\]" lychee_final_output.txt; then
101- echo "❌ Found non-commented broken links:"
102- cat lychee_final_output.txt
103- exit 1
104- else
105- echo "✅ No real broken links found."
106- fi
102+ echo '```markdown'
103+ cat lychee/out.md
104+ echo '```'
0 commit comments