-
Notifications
You must be signed in to change notification settings - Fork 5.5k
157 lines (137 loc) · 5.26 KB
/
Copy pathlinks.yml
File metadata and controls
157 lines (137 loc) · 5.26 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
name: Link Check
on:
pull_request:
types: [opened, synchronize]
schedule:
- cron: "0 0 * * SUN"
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
check-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
if: github.event_name == 'pull_request'
env:
BASE_REF: ${{ github.base_ref }}
run: |
# Get list of changed files
CHANGED_FILES=$(git diff --name-only "origin/$BASE_REF"...HEAD | grep -E '\.(md|ipynb)$' || true)
echo "Changed files:"
echo "$CHANGED_FILES"
# Save changed files to output
if [ -z "$CHANGED_FILES" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Setup Python
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || steps.changed-files.outputs.has_changes == 'true'
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Convert notebooks for link extraction (PR - changed files only)
if: github.event_name == 'pull_request' && steps.changed-files.outputs.has_changes == 'true'
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.files }}
run: |
pip install jupyter nbconvert
mkdir -p temp_md
# Convert only changed notebooks
echo "$CHANGED_FILES" | grep '\.ipynb$' | while read nb; do
if [ -f "$nb" ]; then
echo "Converting: $nb"
jupyter nbconvert --to markdown "$nb" \
--output-dir=temp_md \
--ExtractOutputPreprocessor.enabled=False
fi
done
- name: Convert notebooks for link extraction (scheduled/manual - all files)
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: |
pip install jupyter nbconvert
mkdir -p temp_md
for nb in $(find . -name "*.ipynb" -not -path "*/.*"); do
echo "Converting: $nb"
jupyter nbconvert --to markdown "$nb" \
--output-dir=temp_md \
--ExtractOutputPreprocessor.enabled=False
done
- name: Prepare file list for link checking (PR)
if: github.event_name == 'pull_request' && steps.changed-files.outputs.has_changes == 'true'
id: file-list
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.files }}
run: |
FILES=""
# Add all changed markdown files (from any directory)
while IFS= read -r f; do
if [ -n "$f" ] && [ -f "$f" ]; then
FILES="$FILES $f"
fi
done < <(echo "$CHANGED_FILES" | grep '\.md$')
# Add converted notebooks
if [ -d "temp_md" ] && [ -n "$(ls -A temp_md/*.md 2>/dev/null)" ]; then
FILES="$FILES temp_md/*.md"
fi
# Remove leading/trailing whitespace
FILES=$(echo $FILES | xargs)
echo "Prepared files for lychee: $FILES"
if [ -z "$FILES" ]; then
echo "file_args=" >> $GITHUB_OUTPUT
echo "has_files=false" >> $GITHUB_OUTPUT
else
echo "file_args=$FILES" >> $GITHUB_OUTPUT
echo "has_files=true" >> $GITHUB_OUTPUT
fi
- name: Check Links with Lychee (PR - changed files only)
if: github.event_name == 'pull_request' && steps.changed-files.outputs.has_changes == 'true' && steps.file-list.outputs.has_files == 'true'
id: lychee
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0 (sha-pinned)
with:
args: |
--config lychee.toml
--format markdown
--no-progress
${{ steps.file-list.outputs.file_args }}
output: lychee-report.md
fail: false
failIfEmpty: false
- name: Check Links with Lychee (scheduled/manual - all files)
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
id: lychee-full
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0 (sha-pinned)
with:
args: |
--config lychee.toml
--format markdown
--no-progress
skills/**/*.md
temp_md/*.md
README.md
output: lychee-report.md
fail: false
failIfEmpty: false
- name: Comment PR with results
if: github.event_name == 'pull_request' && steps.lychee.outputs.exit_code != 0
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4 (sha-pinned)
with:
header: link-check
path: lychee-report.md
- name: Upload link check results
if: always()
uses: actions/upload-artifact@v6
with:
name: link-check-results
path: |
lychee-report.md
.lycheecache