-
Notifications
You must be signed in to change notification settings - Fork 305
215 lines (186 loc) · 6.8 KB
/
docs.yml
File metadata and controls
215 lines (186 loc) · 6.8 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
207
208
209
210
211
212
213
214
215
name: Publish docs
on:
push:
branches: [master]
release:
types: [published]
workflow_dispatch:
inputs:
version:
type: string
description: "Docs version (leave empty for dev build)"
required: false
latest:
type: boolean
description: "Set as 'latest' alias (ignored for dev builds; uncheck when republishing old versions)"
default: true
permissions:
contents: write
jobs:
discover-languages:
runs-on: ubuntu-latest
outputs:
languages: ${{ steps.find.outputs.languages }}
steps:
- uses: actions/checkout@v6
with:
sparse-checkout: docs
- name: Find language directories
id: find
run: |
# Find all directories under docs/ that contain mkdocs.yml
langs=$(find docs -maxdepth 2 -name "mkdocs.yml" -exec dirname {} \; | xargs -n1 basename | sort | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "languages=$langs" >> $GITHUB_OUTPUT
echo "Found languages: $langs"
build:
needs: discover-languages
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lang: ${{ fromJson(needs.discover-languages.outputs.languages) }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install Dependencies
run: pip install mkdocs-material mkdocs-enumerate-headings-plugin mkdocs-quiz
- name: Build ${{ matrix.lang }} docs
run: mkdocs build -f docs/${{ matrix.lang }}/mkdocs.yml -d ${{ github.workspace }}/site-${{ matrix.lang }}
- uses: actions/upload-artifact@v7
with:
name: site-${{ matrix.lang }}
path: site-${{ matrix.lang }}/
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Set version and alias
id: version
run: |
# Determine version based on trigger
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
ALIAS="latest"
IS_RELEASE="true"
elif [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
# Check if this should be set as latest (default true for releases)
if [ "${{ github.event.inputs.latest }}" = "false" ]; then
ALIAS=""
else
ALIAS="latest"
fi
IS_RELEASE="true"
else
VERSION="0.dev"
ALIAS="development"
IS_RELEASE="false"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "ALIAS=$ALIAS" >> $GITHUB_ENV
echo "IS_RELEASE=$IS_RELEASE" >> $GITHUB_ENV
echo "Building docs version: $VERSION (alias: $ALIAS, is_release: $IS_RELEASE)"
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- uses: actions/download-artifact@v8
with:
path: artifacts
- name: Combine language builds
run: |
mkdir -p combined
# English goes to root
cp -r artifacts/site-en/* combined/
# Other languages go to subdirectories (discover from artifacts)
for dir in artifacts/site-*; do
lang=$(basename "$dir" | sed 's/site-//')
if [ "$lang" != "en" ] && [ -d "$dir" ]; then
mkdir -p "combined/$lang"
cp -r "$dir"/* "combined/$lang/"
fi
done
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Deploy to gh-pages
run: |
# Move build artifacts out of the way before checkout
mv artifacts /tmp/artifacts
mv combined /tmp/combined
# Fetch gh-pages if it exists
git fetch origin gh-pages:gh-pages 2>/dev/null || true
# Check if gh-pages exists
if git show-ref --verify --quiet refs/heads/gh-pages; then
git checkout gh-pages
# Remove old version directories
rm -rf "$VERSION"
[ -n "$ALIAS" ] && rm -rf "$ALIAS"
else
git checkout --orphan gh-pages
git rm -rf . 2>/dev/null || true
fi
# Copy combined site to version directory
cp -r /tmp/combined "$VERSION"
[ -n "$ALIAS" ] && cp -r /tmp/combined "$ALIAS"
# Update versions.json for mike compatibility
python3 << 'EOF'
import json
import os
from pathlib import Path
version = os.environ["VERSION"]
alias = os.environ.get("ALIAS", "")
is_release = os.environ["IS_RELEASE"] == "true"
versions_file = Path("versions.json")
if versions_file.exists():
versions = json.loads(versions_file.read_text())
else:
versions = []
# Remove existing entry for this version
versions = [v for v in versions if v.get("version") != version]
if alias == "latest":
# Remove 'latest' alias from other versions (only when setting new latest)
for v in versions:
if "aliases" in v:
v["aliases"] = [a for a in v["aliases"] if a != "latest"]
# Create new entry
new_entry = {
"version": version,
"title": version,
"aliases": [alias] if alias else []
}
if is_release:
# Insert at the beginning (most recent release first)
versions.insert(0, new_entry)
else:
# Dev version goes at the end
versions.append(new_entry)
versions_file.write_text(json.dumps(versions, indent=2))
EOF
# Commit and push
git add -A
git commit -m "Deploy $VERSION docs" --allow-empty
# Use --force for dev builds to handle any conflicts
if [ "$IS_RELEASE" = "true" ]; then
git push origin gh-pages
else
git push origin gh-pages --force
fi
- name: Pin GitHub Codespaces version
if: env.IS_RELEASE == 'true'
run: |
# Update Codespaces links to use the release version
find "$VERSION" -type f -exec sed -i "s|ref=master|ref=$VERSION|g" {} +
git add "$VERSION"
if [ -n "$ALIAS" ]; then
find "$ALIAS" -type f -exec sed -i "s|ref=master|ref=$VERSION|g" {} +
git add "$ALIAS"
fi
git status
git commit -m "[automated] Pin GitHub Codespaces link versions" || true
git push origin gh-pages