-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (154 loc) · 5.74 KB
/
DocsBackfill.yml
File metadata and controls
182 lines (154 loc) · 5.74 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
name: Backfill Docs
on:
workflow_dispatch:
permissions:
contents: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
backfill:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
# Save docs infrastructure from main (without coverage — too slow for backfill)
- name: Save docs infrastructure
run: |
cp -r docs /tmp/docs-infrastructure
rm -f /tmp/docs-infrastructure/coverage.qmd
# Remove coverage chapter from _quarto.yml
python3 -c "
import re
with open('/tmp/docs-infrastructure/_quarto.yml') as f:
content = f.read()
content = re.sub(r'\n\s*- coverage\.qmd', '', content)
with open('/tmp/docs-infrastructure/_quarto.yml', 'w') as f:
f.write(content)
"
# Remove LocalCoverage from docs/Project.toml
sed -i '/LocalCoverage/d' /tmp/docs-infrastructure/Project.toml
- uses: julia-actions/setup-julia@v3
with:
version: '1'
- uses: julia-actions/cache@v3
- uses: quarto-dev/quarto-actions/setup@v2
# Prepare gh-pages
- name: Setup gh-pages
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
if git ls-remote --exit-code origin gh-pages; then
git clone --branch gh-pages --single-branch \
"https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" \
gh-pages-deploy
else
mkdir gh-pages-deploy
cd gh-pages-deploy
git init
git checkout --orphan gh-pages
git commit --allow-empty -m "Initialize gh-pages"
fi
# Build docs for every version tag
- name: Build all versions
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
TAGS=$(git tag -l 'v*' | sort -V)
if [ -z "$TAGS" ]; then
echo "No version tags found, nothing to backfill."
exit 0
fi
BUILT=()
SKIPPED=()
for TAG in $TAGS; do
echo ""
echo "=========================================="
echo "Building docs for $TAG"
echo "=========================================="
# Skip if already deployed
if [ -d "gh-pages-deploy/$TAG" ]; then
echo "Already deployed, skipping."
BUILT+=("$TAG")
continue
fi
# Checkout tag (force to discard overlaid docs from previous iteration)
git checkout -f "$TAG"
# Overlay Quarto docs infrastructure from main
rm -rf docs
cp -r /tmp/docs-infrastructure docs
# Install and build
if ! julia --project=docs -e 'using Pkg; Pkg.develop(path="."); Pkg.instantiate()'; then
echo "WARNING: Pkg setup failed for $TAG, skipping."
SKIPPED+=("$TAG")
continue
fi
# Stamp build date
sed -i "s/__BUILD_DATE__/$(date -u +'%Y-%m-%d')/" docs/_quarto.yml
if ! quarto render docs; then
echo "WARNING: Quarto render failed for $TAG, skipping."
SKIPPED+=("$TAG")
continue
fi
cp -r docs/_site "gh-pages-deploy/$TAG"
BUILT+=("$TAG")
echo "Success: $TAG"
done
# Return to main
git checkout -f main
# --- Update gh-pages metadata ---
cd gh-pages-deploy
# Rebuild versions.json from deployed version directories
python3 -c "
import json, os, re
versions = [d for d in os.listdir('.')
if re.match(r'^v\d', d) and os.path.isdir(d)]
def semver_key(v):
return tuple(int(n) for n in re.findall(r'\d+', v))
versions.sort(key=semver_key, reverse=True)
with open('versions.json', 'w') as f:
json.dump(versions, f, indent=2)
print('versions.json:', versions)
"
# Stable redirect → latest version
LATEST=$(python3 -c "
import json
with open('versions.json') as f:
vs = json.load(f)
print(vs[0] if vs else '')
")
if [ -n "$LATEST" ]; then
mkdir -p stable
cat > stable/index.html << STABLE_EOF
<!DOCTYPE html>
<html>
<head><meta http-equiv="refresh" content="0; url=/${REPO_NAME}/${LATEST}/"></head>
<body>Redirecting to <a href="/${REPO_NAME}/${LATEST}/">latest stable</a>...</body>
</html>
STABLE_EOF
fi
# Root redirect → stable
cat > index.html << ROOT_EOF
<!DOCTYPE html>
<html>
<head><meta http-equiv="refresh" content="0; url=/${REPO_NAME}/stable/"></head>
<body>Redirecting to <a href="/${REPO_NAME}/stable/">stable docs</a>...</body>
</html>
ROOT_EOF
touch .nojekyll
git add -A
if git diff --cached --quiet; then
echo "No changes to deploy"
else
git commit -m "Backfill docs for all versions"
git push "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" HEAD:gh-pages
fi
# Summary
echo ""
echo "=========================================="
echo "SUMMARY"
echo "=========================================="
echo "Built: ${BUILT[*]}"
echo "Skipped: ${SKIPPED[*]}"