Skip to content

Commit 0f7116c

Browse files
Update Broken-links-checker-final.yml
1 parent e31a57f commit 0f7116c

File tree

1 file changed

+18
-43
lines changed

1 file changed

+18
-43
lines changed

.github/workflows/Broken-links-checker-final.yml

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- '**/*.md'
77
workflow_dispatch:
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
markdown-link-check:
1114
name: Check Markdown Broken Links
@@ -17,7 +20,7 @@ jobs:
1720
with:
1821
fetch-depth: 0
1922

20-
- name: Get Changed Markdown Files (PR only)
23+
- name: Get Added/Modified Markdown Files (PR only)
2124
id: changed-files
2225
if: github.event_name == 'pull_request'
2326
run: |
@@ -26,60 +29,32 @@ jobs:
2629
echo "md_files<<EOF" >> $GITHUB_OUTPUT
2730
echo "$files" >> $GITHUB_OUTPUT
2831
echo "EOF" >> $GITHUB_OUTPUT
29-
- name: Run Initial Lychee Check (PR)
32+
- name: Check Broken Links in Added/Modified Files (PR)
3033
if: github.event_name == 'pull_request' && steps.changed-files.outputs.md_files != ''
3134
uses: lycheeverse/[email protected]
3235
with:
3336
args: >
34-
--verbose --no-progress --exclude-mail --exclude ^https?://
35-
--output lychee/initial.out
37+
--verbose --exclude-mail --no-progress --exclude ^https?://
3638
${{ steps.changed-files.outputs.md_files }}
3739
env:
3840
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
40-
- name: Extract Markdown Files with Broken Links
41-
if: github.event_name == 'pull_request'
42-
id: affected-md
43-
run: |
44-
mkdir -p sanitized_md
45-
# Extract only .md file paths from the lychee output
46-
affected=$(grep -E 'file://.*\.md' lychee/initial.out | cut -d' ' -f1 | sed 's|file://||' | sort -u)
47-
echo "$affected"
48-
echo "affected_files<<EOF" >> $GITHUB_OUTPUT
49-
echo "$affected" >> $GITHUB_OUTPUT
50-
echo "EOF" >> $GITHUB_OUTPUT
51-
- name: Strip HTML Comments from Affected Markdown Files Only
52-
if: steps.affected-md.outputs.affected_files != ''
53-
run: |
54-
for file in ${{ steps.affected-md.outputs.affected_files }}; do
55-
target="sanitized_md/$file"
56-
mkdir -p "$(dirname "$target")"
57-
# Copy the file and strip only comments
58-
perl -0777 -pe 's/<!--.*?-->//gs' "$file" > "$target"
59-
done
60-
- name: Rerun Lychee on Cleaned Files
61-
if: steps.affected-md.outputs.affected_files != ''
62-
uses: lycheeverse/[email protected]
63-
with:
64-
args: >
65-
--verbose --no-progress --exclude-mail --exclude ^https?://
66-
sanitized_md/**/*.md
67-
env:
68-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69-
70-
- name: Full Repo Scan (Manual)
41+
42+
- name: Preprocess All Markdown Files (strip comments)
7143
if: github.event_name == 'workflow_dispatch'
7244
run: |
73-
mkdir -p sanitized_md
74-
rsync -av --exclude '.git' --exclude 'node_modules' ./ sanitized_md/
75-
find sanitized_md -name "*.md" -exec perl -0777 -i -pe 's/<!--.*?-->//gs' {} +
76-
- name: Run Lychee on Entire Repo (Manual)
45+
mkdir -p cleaned_md
46+
find . -name "*.md" ! -path "./cleaned_md/*" | while read file; do
47+
mkdir -p "cleaned_md/$(dirname "$file")"
48+
sed -E '/<!--/,/-->/d' "$file" > "cleaned_md/$file"
49+
done
50+
51+
- name: Check Broken Links in Entire Repo (Manual)
7752
if: github.event_name == 'workflow_dispatch'
7853
uses: lycheeverse/[email protected]
7954
with:
8055
args: >
81-
--verbose --no-progress --exclude-mail --exclude ^https?:// --include-file
82-
sanitized_md/**/*.md
83-
output: lychee/full.out
56+
--verbose --exclude-mail --no-progress --exclude ^https?://
57+
cleaned_md/**/*.md
58+
output: lychee/out.md
8459
env:
8560
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)