-
Notifications
You must be signed in to change notification settings - Fork 897
206 lines (187 loc) Β· 8.81 KB
/
lychee.yml
File metadata and controls
206 lines (187 loc) Β· 8.81 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: π Lychee
on:
pull_request:
paths:
- 'apps/docs/content/**'
- '.github/workflows/lychee.yml'
concurrency:
group: lychee-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
check:
name: Check Links
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
- name: π Get changed docs files
id: changed-docs
uses: tj-actions/changed-files@v46
with:
files: |
apps/docs/content/**/*.md
apps/docs/content/**/*.mdx
- name: Skip when no docs files changed
if: ${{ steps.changed-docs.outputs.any_changed != 'true' }}
run: echo "No docs markdown changes in this PR. Skipping lychee."
- name: π Lychee Link Checker (First Run)
id: lychee
if: ${{ steps.changed-docs.outputs.any_changed == 'true' }}
uses: lycheeverse/lychee-action@v2
with:
args: >-
--cache
--cache-exclude-status 429,500,502,503,504
--max-cache-age 5m
--verbose
--no-progress
--base-url 'https://local.invalid/'
--timeout 20
--max-concurrency 8
--max-retries 8
--retry-wait-time 5
--scheme http
--scheme https
--exclude '^https?://local\.invalid/'
--exclude 'https://www.gnu.org'
--exclude 'https://docs.solidjs.com'
--accept 200,201,204,301,302,303,307,308,403,429
${{ steps.changed-docs.outputs.all_changed_files }}
output: lychee/out.md
fail: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: π Retry Lychee Link Checker (Second Run for Timeouts)
id: lychee-retry
if: ${{ always() && steps.changed-docs.outputs.any_changed == 'true' && steps.lychee.outputs.exit_code != 0 }}
uses: lycheeverse/lychee-action@v2
with:
args: >-
--cache
--cache-exclude-status 429,500,502,503,504
--max-cache-age 5m
--verbose
--no-progress
--base-url 'https://local.invalid/'
--timeout 30
--max-concurrency 8
--max-retries 10
--retry-wait-time 10
--scheme http
--scheme https
--exclude '^https?://local\.invalid/'
--exclude 'https://www.gnu.org'
--exclude 'https://docs.solidjs.com'
--accept 200,201,204,301,302,303,307,308,403,429
${{ steps.changed-docs.outputs.all_changed_files }}
output: lychee/out-retry.md
fail: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: π Clean up Lychee Report
if: ${{ always() && github.event.pull_request.head.repo.fork == false && steps.changed-docs.outputs.any_changed == 'true' }}
run: |
mkdir -p lychee
# Use retry results if available, otherwise use first run results
if [ -f "lychee/out-retry.md" ]; then
REPORT_FILE="lychee/out-retry.md"
elif [ -f "lychee/out.md" ]; then
REPORT_FILE="lychee/out.md"
fi
if [ -n "$REPORT_FILE" ]; then
# Parse stats from lychee markdown table
TOTAL=$(grep 'Total' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
SUCCESS=$(grep 'Successful' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
ERRORS=$(grep 'Errors' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
REDIRECTS=$(grep 'Redirected' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
EXCLUDED=$(grep 'Excluded' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
TIMEOUTS=$(grep 'Timeouts' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
UNKNOWN=$(grep 'Unknown' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
UNSUPPORTED=$(grep 'Unsupported' "$REPORT_FILE" | grep -oE '\| [0-9]+ +\|' | grep -oE '[0-9]+' || echo "0")
# Extract errors section
ERRORS_SECTION=$(sed -n '/^## Errors/,/^## /p' "$REPORT_FILE" | sed '$d' | tail -n +2)
# Format errors section
FORMATTED_ERRORS=""
while IFS= read -r line; do
if [[ $line =~ ^### ]]; then
file=$(echo "$line" | sed 's/### Errors in //')
FORMATTED_ERRORS+="\n**\`$file\`**\n"
elif [[ $line =~ ^\* ]]; then
FORMATTED_ERRORS+="$line\n"
fi
done <<< "$ERRORS_SECTION"
# Create formatted output using echo statements
echo "## π Lychee Link Check Report" > lychee/formatted.md
echo "" >> lychee/formatted.md
echo "**$TOTAL links:** \`β
$SUCCESS OK\` | \`π« $ERRORS errors\` | \`π $REDIRECTS redirects\` | \`π» $EXCLUDED excluded\`" >> lychee/formatted.md
echo "" >> lychee/formatted.md
if [ "$ERRORS" -eq 0 ]; then
echo "### β
All links are working!" >> lychee/formatted.md
else
echo "### β Errors" >> lychee/formatted.md
# Keep PR comment concise so we never exceed GitHub's 65,536-char limit
echo -e "$FORMATTED_ERRORS" | awk 'NR<=200' >> lychee/formatted.md
TOTAL_ERROR_LINES=$(echo -e "$FORMATTED_ERRORS" | wc -l | tr -d ' ')
if [ "$TOTAL_ERROR_LINES" -gt 200 ]; then
echo "" >> lychee/formatted.md
echo "_Showing first 200 lines of errors. See workflow artifact for full report._" >> lychee/formatted.md
fi
fi
echo "---" >> lychee/formatted.md
echo "" >> lychee/formatted.md
echo "<details>" >> lychee/formatted.md
echo "<summary>Full Statistics Table</summary>" >> lychee/formatted.md
echo "" >> lychee/formatted.md
echo "| Status | Count |" >> lychee/formatted.md
echo "|--------|-------|" >> lychee/formatted.md
echo "| β
Successful | $SUCCESS |" >> lychee/formatted.md
echo "| π Redirected | $REDIRECTS |" >> lychee/formatted.md
echo "| π» Excluded | $EXCLUDED |" >> lychee/formatted.md
echo "| π« Errors | $ERRORS |" >> lychee/formatted.md
echo "| β Unsupported | $UNSUPPORTED |" >> lychee/formatted.md
echo "| β³ Timeouts | $TIMEOUTS |" >> lychee/formatted.md
echo "| β Unknown | $UNKNOWN |" >> lychee/formatted.md
echo "" >> lychee/formatted.md
echo "</details>" >> lychee/formatted.md
# Hard truncate as a final guardrail for sticky PR comments
python - <<'PY'
from pathlib import Path
p = Path("lychee/formatted.md")
if p.exists():
max_chars = 60000
text = p.read_text(encoding="utf-8")
if len(text) > max_chars:
note = "\n\n_Comment truncated to avoid GitHub body limit. Download the artifact for full details._\n"
p.write_text(text[: max_chars - len(note)] + note, encoding="utf-8")
PY
else
# Ensure sticky PR comment always has content even if Lychee output is missing
cat > lychee/formatted.md <<'EOF'
## π Lychee Link Check Report
Lychee did not produce a markdown report file for this run.
Check the workflow logs and uploaded artifact for details.
EOF
fi
- name: π¦ Upload Lychee reports
if: ${{ always() && steps.changed-docs.outputs.any_changed == 'true' }}
uses: actions/upload-artifact@v4
with:
name: lychee-report-${{ github.run_id }}
path: lychee/
if-no-files-found: ignore
- name: π Comment Broken Links
if: ${{ always() && github.event.pull_request.head.repo.fork == false && steps.changed-docs.outputs.any_changed == 'true' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: lychee
path: lychee/formatted.md
- name: π« Fail if broken links found
if: ${{ steps.changed-docs.outputs.any_changed == 'true' && (steps.lychee-retry.conclusion == 'success' && steps.lychee-retry.outputs.exit_code != 0 || steps.lychee-retry.conclusion == 'failure') }}
run: |
if [ "${{ steps.lychee-retry.conclusion }}" == "success" ]; then
echo "Failing based on retry run results"
exit ${{ steps.lychee-retry.outputs.exit_code }}
else
echo "Failing based on first run results"
exit ${{ steps.lychee.outputs.exit_code }}
fi