Repository navigation
406 lines (367 loc) · 16.9 KB
/
Copy pathdoc-examples.yml
File metadata and controls
406 lines (367 loc) · 16.9 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# The documentation's shell examples (scripts/doc_examples.py).
#
# `examples` runs every enrolled page's examples, as written, against a stack of
# the page's own (scripts/doc_examples.py --run), in shards: `plan` asks the
# runner for them (--plan: by image profile, at most PAGES_PER_SHARD pages each;
# `dev` for the contributor pages, which also need a development virtual
# environment, built once in their shard) and `summary` fails unless every page
# ran exactly once and every block ran (--summarise). On a pull request the
# images are pre-built from the GHA cache first, by bake reading
# docker-compose.yml itself, so the documented
# `docker compose up -d --wait` starts them without rebuilding; on main, the
# nightly and a dispatch, compose builds from nothing, which is the path a
# reader takes.
#
# `render` checks the contract on every page the walk finds -- every shell fence
# tagged in the form the site renders as code, nothing a reader cannot paste,
# exact counts -- then builds the site with the site's own toolchain and checks
# every docs/ page rendered its fences as code. Two checks run only here, because
# they need what check() cannot assume (it also runs in core-build's copy, with
# no .git and no zsh): the walk against `git ls-files`, and the comment scanner
# against zsh's own lexer. It also runs the documentation regression tests,
# because the PR QA Gate skips unit tests on a pull request that changes only
# docs/, which is exactly the pull request that breaks a page.
#
# Not a required check (documentation merges without a CI gate; founder,
# 2026-09-24). A red run on main, the nightly or a dispatch files an issue.
name: Doc Examples
on:
pull_request:
push:
branches: [main]
schedule:
- cron: '30 2 * * *' # 02:30 UTC, after nightly-qa
workflow_dispatch:
permissions:
contents: read
concurrency:
group: doc-examples-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
render:
name: Doc Examples (render)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: backend/requirements.txt
# The regression tests import the API's schemas; the site toolchain comes
# from the one script docs.yml also runs.
- name: Install
run: |
pip install -r backend/requirements.txt
bash scripts/docs_toolchain.sh
# ubuntu-24.04 ships no zsh. The oracle below refuses without it, and the
# regression tests' zero-skip check fails, so a lost install is red here.
- name: Install zsh
run: |
start=$SECONDS
sudo apt-get update -qq
sudo apt-get install -y -qq zsh
echo "zsh installed in $((SECONDS - start)) s"
# Recorded because ubuntu-latest moves (to 26.04 in November 2026).
# bash -n in the contract refuses a bash below 4.4 itself.
- name: Tool versions
run: |
bash --noprofile --norc -c 'echo "bash $BASH_VERSION"'
zsh --version
# Every check below runs even when an earlier one failed, so a lost zsh
# install does not hide the contract, and one red hides no other.
- name: Contract (tags, contents, counts)
if: ${{ !cancelled() }}
run: python scripts/doc_examples.py --check
- name: The walk equals git ls-files
if: ${{ !cancelled() }}
run: python scripts/doc_examples.py --walk-vs-git
- name: Comments, against zsh's own lexer
if: ${{ !cancelled() }}
run: python scripts/doc_examples.py --zsh-oracle
# Nothing here may skip: the zsh oracle's unit tests skip where zsh is
# absent (Unit Tests, core-build), and this is where they must run. The
# skip check runs even when a test failed, so a failure hides no skip.
- name: Documentation regression tests
if: ${{ !cancelled() }}
env:
APP_ENV: test
TESTING: 'true'
run: |
rc=0
python -m pytest backend/tests/unit/docs/ backend/tests/unit/scripts/test_doc_examples.py \
-p no:cov -q -rs --junitxml=docs-junit.xml || rc=1
python3 scripts/check_junit_skips.py docs-junit.xml backend/tests/unit/docs backend/tests/unit/scripts || rc=1
exit "$rc"
# Rendered even when an earlier step failed: a tag that breaks the page is
# reported by both checks, and the render check is the one that sees the
# built HTML.
- name: Build the site
if: ${{ !cancelled() }}
run: mkdocs build
- name: Rendered as code
if: ${{ !cancelled() }}
run: python scripts/doc_examples.py --render site
# The shards: which pages run where is the runner's decision (--plan), from
# the enrolment, so a content batch never edits this file to add a page.
plan:
name: Doc Examples (plan)
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
matrix: ${{ steps.plan.outputs.matrix }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.11'
- name: Plan the shards
id: plan
run: |
set -euo pipefail
matrix=$(python scripts/doc_examples.py --plan)
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
examples:
name: Doc Examples (run ${{ matrix.profile }} ${{ matrix.shard }}/${{ matrix.of }})
needs: plan
runs-on: ubuntu-latest
# A shard holds at most PAGES_PER_SHARD pages (scripts/doc_examples.py),
# measured at 55-79 s each, so its run step stays under 8 minutes. The runner
# stops itself before this timeout, at the deadline the first step exports,
# so a hang is named rather than killed.
timeout-minutes: ${{ github.event_name == 'pull_request' && 15 || 20 }}
strategy:
# One red shard must not cancel the others: the summary would then report
# their pages as missing and bury the real failure.
fail-fast: false
matrix: ${{ fromJSON(needs.plan.outputs.matrix) }}
steps:
# First, so the runner's deadline counts from (within seconds of) the
# moment timeout-minutes starts counting. It is still taken after the
# job's clock starts (1-4 s across 90 shard jobs, 2026-09-30), so the
# deadline is that much late; accepted slack, well inside
# DEADLINE_MARGIN_SECONDS.
- name: Record the job start
run: echo "DOCEX_JOB_START=$(date +%s)" >> "$GITHUB_ENV"
- uses: actions/checkout@v7
# The runner itself needs only the standard library. The pip cache is for
# the dev shards' virtual environment (below), and only they ask for it.
- uses: actions/setup-python@v7
with:
python-version: '3.11'
cache: ${{ matrix.profile == 'dev' && 'pip' || '' }}
cache-dependency-path: backend/requirements.txt
# The contributor pages (environment stack-dev) start with `source
# venv/bin/activate` in a checkout whose venv has the backend's
# requirements, as docs/getting-started/python-virtual-env-setup.md sets
# one up. Built once per dev shard, before the run; the runner checks it
# through venv/bin/python and fails a page that cannot import what it
# runs. The commands are DEV_VENV_BUILD in scripts/doc_examples.py (a test
# holds the two equal).
- name: Build the development virtual environment
if: matrix.profile == 'dev'
run: |
python -m venv venv
venv/bin/pip install -r backend/requirements.txt
# docs/self-hosting/releases.md verifies the newest release's signature
# and SBOM with cosign, the way its reader does. No registry login: the
# page runs cosign with an empty DOCKER_CONFIG.
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Tool versions
run: |
docker version --format 'docker {{.Server.Version}}'
docker compose version
bash --version | head -1
jq --version
cosign version
- name: Set up Buildx
if: github.event_name == 'pull_request'
uses: docker/setup-buildx-action@v4
# The UTC date, passed to the image builds below as OS_PACKAGES_REFRESHED:
# a new date re-runs the Dockerfiles' OS package upgrade layer even when
# the build cache holds an older copy of it (see backend/Dockerfile).
- name: OS package refresh date
id: os-packages
run: printf 'date=%s\n' "$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
# The build definitions come from docker-compose.yml itself (no second
# copy); `source: .` builds the checkout, not the Git context. The
# profile picks the API's build target and the dashboard's build argument
# exactly as `docker compose` does.
- name: Pre-build the images compose would build (core)
if: github.event_name == 'pull_request' && (matrix.profile == 'core' || matrix.profile == 'dev')
uses: docker/bake-action@v7
with:
source: .
files: docker-compose.yml
targets: api,frontend
load: true
set: |
api.cache-from=type=gha,scope=docex-api
frontend.cache-from=type=gha,scope=docex-web
*.args.OS_PACKAGES_REFRESHED=${{ steps.os-packages.outputs.date }}
# The full API reads `api-full`, which security-scan already writes on
# main from the same Dockerfile and target, then `docex-api` for the
# layers the profiles share. The full dashboard's scope, `docex-web-full`,
# has no other writer; cache-warm below fills it.
- name: Pre-build the images compose would build (full)
if: github.event_name == 'pull_request' && matrix.profile == 'full'
uses: docker/bake-action@v7
env:
EXPERIMENTLY_PROFILE: full
with:
source: .
files: docker-compose.yml
targets: api,frontend
load: true
set: |
api.cache-from=type=gha,scope=api-full
api.cache-from=type=gha,scope=docex-api
frontend.cache-from=type=gha,scope=docex-web-full
*.args.OS_PACKAGES_REFRESHED=${{ steps.os-packages.outputs.date }}
# PYTHONUNBUFFERED as well as the runner's own line buffering, so a job
# killed mid-page still shows the page it was on. The timeout is the
# job's timeout-minutes expression, character for character (a test holds
# the two identical); the runner stops DEADLINE_MARGIN_SECONDS before it.
- name: Run the documentation's examples
env:
PYTHONUNBUFFERED: '1'
DOCEX_JOB_TIMEOUT_MINUTES: ${{ github.event_name == 'pull_request' && 15 || 20 }}
SHARD: ${{ matrix.profile }}:${{ matrix.shard }}/${{ matrix.of }}
REPORT: docex-report/${{ matrix.profile }}-${{ matrix.shard }}.json
run: python scripts/doc_examples.py --run --shard "$SHARD" --report "$REPORT"
# Even when the run failed or stopped at its deadline: the summary needs
# every shard's report. `overwrite`, because artifacts are immutable and a
# re-run of one shard uploads the same name again.
- name: Keep the shard's report
if: always()
uses: actions/upload-artifact@v7
with:
name: doc-examples-report-${{ matrix.profile }}-${{ matrix.shard }}
path: docex-report/
if-no-files-found: warn
overwrite: true
retention-days: 7
# The only job that notices a shard that never ran, a page no shard ran, or a
# block that stopped being reached: what must have run comes from the
# enrolment, not from the matrix. `!cancelled()` rather than `always()`, so a
# pull request run superseded by a newer push is not also reported red.
summary:
name: Doc Examples (summary)
needs: [plan, examples]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
issues: read
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.11'
# No report at all is the summary's to judge (it fails), so a download
# that finds nothing must not end the job before it.
- name: Collect the shard reports
uses: actions/download-artifact@v8
continue-on-error: true
with:
pattern: doc-examples-report-*
path: docex-reports
merge-multiple: true
- name: Every page ran once, and every block ran
run: python scripts/doc_examples.py --summarise docex-reports
# Advisory: check() holds only the shape of `bug #N: ...`, because it runs
# where there is no network; whether the issue is still open is asked here.
- name: The issues that bug skips name are open
if: ${{ !cancelled() }}
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
numbers=$(python scripts/doc_examples.py --bug-issues)
for number in $numbers; do
state=$(gh issue view "$number" --repo "$REPO" --json state --jq .state 2>/dev/null || echo UNKNOWN)
if [ "$state" = OPEN ]; then
echo "bug #$number: open"
else
echo "::warning::a skip reason names bug #$number, which is $state; fix the page or the reason"
fi
done
# GHA caches written from a pull request are visible to that pull request only;
# only the default branch's are shared, so main fills the cache the pull
# requests read. The full API's layers are `api-full`, which security-scan
# already writes on main; only the full dashboard has no other writer.
cache-warm:
name: Doc Examples (cache)
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'schedule'
timeout-minutes: 45
steps:
- uses: actions/checkout@v7
- uses: docker/setup-buildx-action@v4
# The UTC date, passed to the image builds below as OS_PACKAGES_REFRESHED:
# a new date re-runs the Dockerfiles' OS package upgrade layer even when
# the build cache holds an older copy of it (see backend/Dockerfile).
- name: OS package refresh date
id: os-packages
run: printf 'date=%s\n' "$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
- uses: docker/bake-action@v7
with:
source: .
files: docker-compose.yml
targets: api,frontend
set: |
api.cache-to=type=gha,scope=docex-api,mode=max
frontend.cache-to=type=gha,scope=docex-web,mode=max
*.output=type=cacheonly
*.args.OS_PACKAGES_REFRESHED=${{ steps.os-packages.outputs.date }}
- uses: docker/bake-action@v7
env:
EXPERIMENTLY_PROFILE: full
with:
source: .
files: docker-compose.yml
targets: frontend
set: |
frontend.cache-to=type=gha,scope=docex-web-full,mode=max
*.output=type=cacheonly
*.args.OS_PACKAGES_REFRESHED=${{ steps.os-packages.outputs.date }}
failure-issue:
name: File an issue on failure
runs-on: ubuntu-latest
# Not cache-warm: a cold cache is not a red documentation page. The
# summary, because a shard that never ran is red only there.
needs: [render, examples, summary]
# A shard that reaches timeout-minutes concludes `cancelled`, not `failure`
# (measured: E0b's tamper run 36270360056), so a cancelled job is red here
# too. The summary also fails then, for the missing report; this does not
# depend on it. `!cancelled()` still leaves out a run that was itself
# cancelled.
if: ${{ github.event_name != 'pull_request' && !cancelled() && (failure() || contains(needs.*.result, 'cancelled')) }}
permissions:
contents: read
issues: write
steps:
- name: Open or update the issue
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
set -euo pipefail
TITLE="Documentation examples are red"
BODY="Doc Examples failed on $(date -u '+%Y-%m-%d') (${GITHUB_EVENT_NAME}, commit ${GITHUB_SHA})."$'\n\n'"Run: ${RUN_URL}"
# `|| true`: the label does not exist yet on the first red run.
EXISTING=$(gh issue list --repo "$REPO" --state open --label doc-examples-failure \
--json number --jq '.[0].number // empty' 2>/dev/null || true)
if [ -n "$EXISTING" ]; then
gh issue comment "$EXISTING" --repo "$REPO" --body "$BODY"
else
gh label create doc-examples-failure --repo "$REPO" --color B60205 \
--description "Doc Examples failed" 2>/dev/null || true
gh issue create --repo "$REPO" --title "$TITLE" \
--label doc-examples-failure --body "$BODY"
fi