Repository navigation
370 lines (356 loc) · 21.4 KB
/
Copy pathdocs-deploy.yml
File metadata and controls
370 lines (356 loc) · 21.4 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
name: Docs Deploy
# The ONE path by which this repository's docs site reaches production: the
# `deploy` job, Vercel project `objectstack`, Root Directory `apps/docs`.
#
# The Object UI docs site (www.objectui.org) was retired when its pages folded
# into this one. Its old URLs answer host-scoped permanent
# redirects from `apps/docs/redirects.mjs` (`objectuiRedirects`) once the
# objectui.org domains point at this project; nothing deploys it any more.
#
# ## Why the build runs here and not on Vercel
#
# Vercel bills Build CPU Minutes, and it bills them for deployments that do not
# end up building anything. Measured on 2026-10-12 against this project: ~600
# deployments a day, ~533 of them Git-integration PREVIEW deployments for
# `claude/*`, `gh-readonly-queue/*`, `board-archive*` and `changeset-release/*`
# branches. Each one cloned the monorepo, ran the old Ignored Build Step script
# for ~25 s and was then canceled — and was still billed: billed CPU-minutes
# divided by production-build wall-minutes came out at 12–15, more than the
# 8-vCPU build machine can produce on its own, so the canceled ones are in the
# bill. They were ~40% of this project's cost; the ~34 production builds a day
# that pushes to `main` triggered were most of the rest. Build CPU Minutes were
# 97% of the team's invoice.
#
# The maintainer's ruling, verbatim and untranslated:
# 「文档站应该只有主分支需要部署,而且应该用免费的」 — only `main` deploys the docs,
# and on free compute. This repository is public, so a standard
# `ubuntu-latest` runner costs nothing. So this job builds the site on that
# runner with `vercel build` and uploads the result with
# `vercel deploy --prebuilt`: Vercel stores and serves it and builds nothing.
# `apps/docs/vercel.json` turns the Git integration's deployments off
# (`git.deploymentEnabled: false`), so no branch push creates a Vercel
# deployment at all — billed, canceled or otherwise.
#
# ## Failure direction: a silent skip is the worst outcome
#
# A run that cannot deploy goes RED, never green-and-skipped. The site going
# quietly stale with no error anywhere is exactly what the old Ignored Build
# Step script was written around ("a wrong skip silently stops publishing
# documentation"), and moving the build here does not change which direction
# is the dangerous one. In particular a missing `VERCEL_TOKEN` secret (an
# objectstack-ai organization secret; a repository secret of the same name
# resolves identically) is an `::error::` and a failed run, never a notice:
# unlike an optional mirror, this job IS the publishing path, and without it
# nothing else publishes the docs.
on:
schedule:
# Every six hours, at :43 past 00, 06, 12 and 18 UTC. The maintainer's
# decision: the docs refresh at most six hours behind `main`, and
# "Run workflow" on this workflow's Actions page (workflow_dispatch below)
# publishes `main` immediately when that is too slow. Builds cost nothing
# here at any frequency; four a day (against ~87 commits a day on `main`)
# keeps this job from competing with CI for runners and needs no
# paths-filter list to keep in step with what the site is built from.
#
# The HOURS keep out of this repository's crowded scheduled windows, read
# from `grep -rn 'cron:' .github/workflows/` on the day this landed: 01–05
# UTC carry most of the nightlies (stale, CodeQL, validate-deps,
# coverage, the release-coverage and required-set patrols, the smokes and
# nightly tiers), 07 carries showcase-smoke, and the board
# snapshot owns :07 of 02, 08, 14 and 20. Of the six six-hour sets, only
# 0/6/12/18 and 1/7/13/19 have hours with nothing scheduled after :00; the
# first is taken because its :00 neighbours are short (release.yml's
# version-pr refresh, the ci/lint full runs), while 07:00 starts the
# showcase smoke. Since #25771 those ci/lint runs are 4-hourly
# (00/04/08/12/16/20 :00), so they now meet this set only at 00 and 12 and
# 06/18 lose that neighbour; the choice still holds and nothing moved. The MINUTE is off the top of the hour for the reason every
# patrol here gives: scheduled runs queue behind everyone else's :00 cron.
#
# This job spends almost nothing of the per-repository GITHUB_TOKEN budget
# (the checkout, and no API reads), so unlike the board readers it is not
# placed against that pool.
#
# ⚠️ GitHub delays scheduled runs under load and occasionally drops one. For
# docs that costs one more interval of staleness, which a dispatch buys back.
- cron: '43 0,6,12,18 * * *'
workflow_dispatch: {}
# Read the tree, nothing else. Vercel is reached with VERCEL_TOKEN, not with
# any GitHub scope.
permissions:
contents: read
# One production deploy at a time, and the newest one wins. Cancelling an
# in-flight run is safe HERE, unlike a backup: every run builds the tip of
# `main`, which contains everything an earlier run would have published, so a
# cancelled run loses nothing a later run does not deliver.
concurrency:
group: docs-deploy-production
cancel-in-progress: true
jobs:
deploy:
name: Build the docs site and deploy it to Vercel production
runs-on: ubuntu-latest
# A forced docs build (spec generators + `next build`) measures ~4 minutes
# on this runner class in ci.yml's Build Docs job; the rest is install and
# upload.
timeout-minutes: 30
env:
# Which Vercel project receives the deployment. These are identifiers,
# not credentials; with both set, the CLI needs no `.vercel/project.json`
# in the repository and no interactive `vercel link`.
VERCEL_ORG_ID: team_06nvlGKZCkwhzdXmRdxeCNnB
VERCEL_PROJECT_ID: prj_KbPkuEVCj8viErlaC0wBUgMIYZWe
# Pinned, so a CLI release cannot change how production is built between
# two runs of an unchanged tree. Moving it is a reviewed edit here.
VERCEL_CLI_VERSION: '60.1.3'
steps:
# The maintainer's ruling is "only main deploys". `schedule` always runs
# on the default branch, but `workflow_dispatch` offers a branch picker,
# and a dispatch from any other ref would publish that branch to
# production. Refused loudly rather than skipped: a skip reads as a
# successful run of the button somebody just pressed.
- name: Refuse any ref but main
if: github.ref != 'refs/heads/main'
run: |
echo "::error::Docs Deploy publishes to PRODUCTION and runs only from main; this run is on ${GITHUB_REF}. Re-run it with 'main' selected in the branch picker."
exit 1
# Checked before anything is built, so a missing credential costs seconds
# rather than a full build, and it fails RED: see the header.
- name: Require the Vercel token
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: |
if [ -z "${VERCEL_TOKEN:-}" ]; then
echo "::error::The secret VERCEL_TOKEN is not visible to this run, so the docs site cannot be deployed and production is NOT being updated. It is provided as an objectstack-ai ORGANIZATION secret: check that it still exists and that this repository is in its repository access list (org Settings -> Secrets and variables -> Actions). To replace it, create a token at vercel.com -> Account Settings -> Tokens scoped to the Object Stack team, and store it as VERCEL_TOKEN there (or as a repository secret of the same name). Then re-run this workflow."
exit 1
fi
echo "VERCEL_TOKEN is set."
- name: Checkout repository
uses: actions/checkout@v7
# The same key ci.yml's jobs use, so a scheduled run restores the store
# CI already saved for this lockfile instead of downloading it again.
# `vercel build` runs vercel.json's `installCommand` again; with the tree
# already installed from the frozen lockfile that pass has nothing to do,
# and a lockfile problem fails HERE, under its own name.
- name: Setup workspace
uses: ./.github/actions/setup-workspace
# ## Every Vercel command runs from the REPOSITORY ROOT, not apps/docs
#
# The project's Root Directory setting (`apps/docs`) comes down with
# `vercel pull`, and the CLI applies it relative to the directory it is
# run from: `vercel build` builds `<cwd>/<rootDirectory>` and writes
# `<cwd>/.vercel/output`, and `vercel deploy` checks that
# `<cwd>/<rootDirectory>` exists before uploading `<cwd>/.vercel/output`
# (read from vercel/vercel's packages/cli build and deploy commands). Run
# from `apps/docs`, the same setting would point at `apps/docs/apps/docs`.
# From the root, the build reads `apps/docs/vercel.json` and runs its
# `installCommand` / `buildCommand` with `apps/docs` as the working
# directory — the same command, in the same place, that ci.yml's Build
# Docs gate reads out of that file and runs on every docs PR.
- name: Pull the production project settings
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: npx --yes "vercel@${VERCEL_CLI_VERSION}" pull --yes --environment=production --token="$VERCEL_TOKEN"
- name: Build the site (vercel build --prod)
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
# Build THIS tree, never replay one. A fresh runner has no local turbo
# cache and this job passes no remote-cache credentials, so nothing
# could be replayed today; forcing keeps that true if either ever
# changes, for the reason ci.yml's Build Docs step gives: a replayed
# `.next` would publish a stale site and report success.
TURBO_FORCE: 'true'
run: npx --yes "vercel@${VERCEL_CLI_VERSION}" build --prod --token="$VERCEL_TOKEN"
# An exit code of 0 is not proof that the docs app was built — see
# ci.yml's "Assert the docs app actually built" for the measured case of a
# build command that matched no package and exited 0. Assert both the
# Next.js build and the Build Output API directory the upload reads.
- name: Assert the build produced a deployable output
run: |
set -euo pipefail
if [ ! -f apps/docs/.next/BUILD_ID ]; then
echo "::error file=apps/docs/vercel.json::vercel build exited 0 but produced no apps/docs/.next/BUILD_ID - the docs app was not built, so nothing is deployed."
exit 1
fi
if [ ! -f .vercel/output/config.json ]; then
echo "::error::vercel build exited 0 but wrote no .vercel/output/config.json at the repository root - there is no prebuilt output to deploy."
exit 1
fi
echo "Built docs app: BUILD_ID=$(cat apps/docs/.next/BUILD_ID)"
# A reading, not a gate: what this deploy is about to upload, by part
# (prerendered pages, function code, OG images, llms bodies, static
# files), in this log and in the run summary. It runs BEFORE the upload
# so the reading exists for exactly the runs that need it most, the ones
# whose upload aborts. `.vercel/output` alone undercounts: the function
# code rides in each function's `filePathMap` from the repository, which
# the script adds; its header says how the file count reproduces the
# CLI's own "Downloading N deployment files" line.
#
# `continue-on-error` on purpose, and the only step here that has it: a
# broken measurement must never stop the docs from publishing (the header's
# failure direction is about the PUBLISH going quietly stale; this step
# publishes nothing). A failure still shows as a warning annotation.
# `timeout-minutes` because `continue-on-error` does not absorb a hang:
# without it only the job's clock would end the step, with no deploy. The
# script is synchronous local reads (seconds); 5 minutes is the ceiling.
- name: Measure what this deploy uploads
continue-on-error: true
timeout-minutes: 5
run: |
set -euo pipefail
if ! node apps/docs/scripts/measure-deploy-output.mjs > "$RUNNER_TEMP/deploy-output-reading.txt"; then
echo "::warning::measure-deploy-output.mjs failed; the deploy goes ahead without a size reading."
exit 1
fi
cat "$RUNNER_TEMP/deploy-output-reading.txt"
{
echo "### Docs deploy output"
echo
echo '```text'
cat "$RUNNER_TEMP/deploy-output-reading.txt"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
# ## A bounded retry of the upload, and a failure that names what it saw
#
# Read from the logs of the failed runs 46421807466, 46487702664 and
# 46551161614 (2026-11-30 12:46Z to 2026-12-01 01:10Z, CLI 60.1.3,
# Node 22.23.5, the same runner image as the green runs before them):
# each upload stopped with ONE `fetch failed` 301-302 s after its
# `Uploading [---]` line, then `AbortError` for the other uploads in
# flight (one log also shows `Upload aborted` for the queued ones). A
# green upload of the same ~540 MB finishes in about 60 s, so that
# request was not slow: nothing answered it. 300 s is Node fetch's
# default response timeout (undici's headersTimeout / bodyTimeout); that
# it fired is inferred from the timing, since the CLI prints `fetch
# failed` without its cause. The 2026-11-21 failures stopped 56 s and
# 71 s in: another `fetch failed` with no HTTP status. WHY the request
# went unanswered is not shown: the network path, Vercel's upload
# endpoint, or one file that stalls every time are all still open.
#
# The CLI retries a failed file upload only when the error text matches
# ETIMEDOUT, ECONNRESET, ECONNREFUSED, ENOTFOUND, EAI_FAIL, `socket hang
# up` or `network socket disconnected` (`isClientNetworkError` in the
# 60.1.3 bundle). An undici timeout ("Headers Timeout Error") matches
# none of them, and neither did the cause of any failure above, so the
# CLI aborted every other upload and exited 1: one stalled request
# fails the whole deploy.
#
# So this step runs the deploy up to DEPLOY_ATTEMPTS times, and retries
# ONLY when the attempt never got a deployment URL AND either its fatal
# error line (`Error:` / `TypeError:`, not a warning earlier in stderr)
# carries a connection-failure text or it hit its own attempt cap. Each
# attempt is a new CLI process with new connections, and it asks the
# API again which files it lacks (the CLI's `missing_files` exchange)
# and uploads only those; how many that is depends on what Vercel kept
# from the aborted attempt, which no log shows.
#
# Never retried: CLI 60.1.3 prints the deployment URL at `created`,
# before Building, Ready and Aliased, so an attempt that printed a URL
# and then failed (a status poll's `fetch failed`, a cap hit waiting for
# Ready) has a deployment that Vercel goes on to finish; a retry would
# publish a second one. That run fails naming the URL, its final state
# unknown. Also never retried: any other error (a refused token, a
# config error, an HTTP error with a message) and an exit 0 with no URL.
#
# A deploy that needed a retry is green with a warning, so a recovered
# abort stays visible on the run page. When every attempt fails, the
# error lists each attempt's time and failing line. If retries keep
# failing the same way, the next reading is which file the stalled
# request carried: a run with `--debug` logs `File <sha> (<name>)
# uploaded` for each file, and the stalled one never gets that line.
#
# The CLI pin stays at 60.1.3: the same version deployed the ten green
# runs before the first failure, so the logs give no reason to move it.
#
# Budget: the deploy step started 5-6.5 minutes into the failed runs; a
# failed attempt took 307-312 s and a green one 74 s. ATTEMPT_LIMIT caps
# one attempt (`timeout` signals the CLI's whole process group, and
# `--kill-after` follows with SIGKILL 30 s later) so a hang outside the
# upload cannot eat the job: 3 x 6.5 min + the 30 s and 60 s waits is
# 21 minutes, about 27.5 with the build before it, inside the job's 30.
# Exit 137 is that SIGKILL; an out-of-memory kill of the CLI would also
# read 137 and be labelled the cap.
- name: Deploy the prebuilt output to production
id: deploy
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
DEPLOY_ATTEMPTS: '3'
ATTEMPT_LIMIT: '6m'
run: |
set -euo pipefail
url_file="$RUNNER_TEMP/vercel-deploy-url.txt"
err_file="$RUNNER_TEMP/vercel-deploy-stderr.txt"
retry_waits=(30 60)
transient='fetch failed|ECONNRESET|ETIMEDOUT|socket hang up|other side closed'
history=""
for attempt in $(seq 1 "$DEPLOY_ATTEMPTS"); do
echo "Deploy attempt ${attempt} of ${DEPLOY_ATTEMPTS} ($(date -u +%H:%M:%SZ))"
started=$(date +%s)
status=0
# stdout is the deployment URL and nothing else, into url_file.
# Progress and errors go to stderr: shown live in this log
# (its timestamps are how the 300 s stall was read) and kept in
# err_file for the retry decision.
timeout --kill-after=30s "$ATTEMPT_LIMIT" \
npx --yes "vercel@${VERCEL_CLI_VERSION}" deploy --prebuilt --prod --token="$VERCEL_TOKEN" \
2>&1 >"$url_file" | tee "$err_file" >&2 || status=${PIPESTATUS[0]}
elapsed=$(( $(date +%s) - started ))
# Anything on stdout means the CLI reached `created` (it prints
# nothing else there); `url` is the address it printed, for the
# messages and the step output.
created=""
if grep -q '[^[:space:]]' "$url_file"; then created=yes; fi
url=$(grep -oE 'https://[^[:space:]]+' "$url_file" | tail -n 1 || true)
# The CLI's fatal error lines; warnings it carries on past are not
# among them.
fatal=$(grep -E '^(Error|TypeError): ' "$err_file" || true)
first_fatal=${fatal%%$'\n'*}
if [ "$status" -eq 0 ] && [ -n "$url" ]; then
echo "url=${url}" >> "$GITHUB_OUTPUT"
echo "Deployed: ${url}"
if [ "$attempt" -gt 1 ]; then
echo "::warning::Docs deployed on attempt ${attempt} of ${DEPLOY_ATTEMPTS}, after a retry.${history}"
fi
exit 0
fi
if [ -n "$created" ]; then
# A deployment exists: see the header. Never retried.
url=${url:-$(grep -m1 '[^[:space:]]' "$url_file")}
reason=${first_fatal:-no error line}
if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then reason="stopped by the ${ATTEMPT_LIMIT} attempt cap"; fi
echo "url=${url}" >> "$GITHUB_OUTPUT"
echo "::error::vercel deploy created the deployment ${url} and then failed (exit ${status} after ${elapsed} s: ${reason}). Its final state (Ready, aliased to production) is unknown: open it in the Vercel dashboard. Not retried, since a retry would publish a second deployment."
exit 1
fi
if [ "$status" -eq 0 ]; then
echo "::error::vercel deploy exited 0 but printed no deployment URL, so whether it created a deployment is unknown: check the Vercel dashboard. Not retried, since a retry could publish a second deployment."
exit 1
fi
if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then
cause="stopped by the ${ATTEMPT_LIMIT} attempt cap, exit ${status}"
elif line=$(grep -m1 -E "$transient" <<<"$fatal"); then
cause="${line}"
else
first=$(grep -m1 . <<<"$fatal" || tail -n 1 "$err_file" || true)
echo "::error::vercel deploy failed (exit ${status}) before printing a deployment URL, with an error that is not a connection failure, so it is not retried: ${first:-no stderr}"
exit 1
fi
history="${history} Attempt ${attempt} failed after ${elapsed} s (${cause})."
echo "Attempt ${attempt} failed after ${elapsed} s: ${cause}."
if [ "$attempt" -lt "$DEPLOY_ATTEMPTS" ]; then
wait_s=${retry_waits[$(( attempt - 1 ))]:-60}
echo "Retrying in ${wait_s} s."
sleep "$wait_s"
fi
done
echo "::error::The Vercel upload failed on all ${DEPLOY_ATTEMPTS} attempts.${history} No attempt got a deployment URL back (CLI ${VERCEL_CLI_VERSION} prints it the moment a deployment is created), so this run created no deployment that the CLI knows of. A stop about 300 s after the Uploading line is one upload request that got no answer within Node fetch's 300 s timeout; a stop a minute or so in is a dropped connection. Why is not shown: if this repeats, find which file the stalled request carried (see the comment above this step)."
exit 1
- name: Publish the run to the summary
if: always()
run: |
{
echo "### Docs Deploy — ${{ job.status }}"
echo
echo "Commit: \`${{ github.sha }}\` (${{ github.event_name }})"
echo
echo "Deployment: ${{ steps.deploy.outputs.url || 'none (the run stopped before the deploy step finished)' }}"
} >> "$GITHUB_STEP_SUMMARY"