ci(deploy): refuse to publish an empty or truncated page build (#18)
`wrangler pages deploy .vercel/output/static` replaces the whole live site, and nothing between the build and that upload ever looked inside the directory. next-on-pages is fail-closed against its own crash, not against exiting 0 with an empty or half-written output — that would have been published as-is and blanked status.openshopgraph.org through a fully green run. A status page that is silently empty is the one outage nothing else here reports. scripts/verify-pages-output.sh asserts the worker entrypoint, the routes manifest, at least one client chunk, and a floor of 20 files (a correct build of main measures 49). deploy.yml runs it directly after the build, so a broken build stops the job before `terraform apply` — production is never touched. Co-authored-by: OSG Agent <agent@openshopgraph.org> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>pull/216/head
parent
f9aaded756
commit
18d5ff7fe4
|
|
@ -86,6 +86,16 @@ jobs:
|
|||
run: |
|
||||
npx @cloudflare/next-on-pages
|
||||
|
||||
# The "Upload pages" step at the end of this job REPLACES the live site
|
||||
# with the contents of .vercel/output/static. The build above is
|
||||
# fail-closed against its own crash — a non-zero exit stops the job — but
|
||||
# not against exiting 0 with an empty or truncated directory, and until
|
||||
# now nothing between the build and the upload looked inside it. Assert
|
||||
# the output here, before `terraform apply`, so a broken build stops the
|
||||
# run while Cloudflare is still untouched.
|
||||
- name: Verify page build output
|
||||
run: scripts/verify-pages-output.sh
|
||||
|
||||
- name: Create D1 database and tables
|
||||
run: |
|
||||
python3 deploy/init_d1.py # This sets D1_ID in GITHUB_ENV
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Publish gate for .github/workflows/deploy.yml.
|
||||
#
|
||||
# `npx wrangler pages deploy .vercel/output/static` REPLACES the whole site:
|
||||
# whatever sits in that directory becomes status.openshopgraph.org, and every
|
||||
# file absent from it is gone from the live site. The generating step
|
||||
# (`npx @cloudflare/next-on-pages`) is fail-closed against its own *process*
|
||||
# failure only — a non-zero exit stops the job. Nothing asserted that the
|
||||
# directory it hands on actually contains a site, so an empty or truncated
|
||||
# build directory would have been published as-is and taken the status page
|
||||
# down without a single red step in the run. A status page that is silently
|
||||
# blank is the one outage nothing else in this system reports.
|
||||
#
|
||||
# This script is that assertion. deploy.yml runs it directly after the build
|
||||
# and therefore BEFORE the first production mutation (`terraform apply`), so a
|
||||
# broken build costs nothing in production: the job stops while Cloudflare is
|
||||
# still untouched.
|
||||
#
|
||||
# Thresholds are measured against a real build of main at f9aaded
|
||||
# (@cloudflare/next-on-pages 1.13.12, next 14.2.28, node 22.17.0):
|
||||
# 49 files total | _worker.js/index.js 27423 bytes | 18 files under
|
||||
# _next/static, of which 16 are .js chunks.
|
||||
# MIN_FILES is deliberately far below the measured 49. This gate exists to
|
||||
# catch "empty" and "half", not to police the size of a legitimate change.
|
||||
#
|
||||
# Deliberately NOT checked: index.html. This site has no prerendered index —
|
||||
# `/` and `/incidents` are rendered at request time by _worker.js, and a
|
||||
# correct build of main produces no index.html at all (measured: only 404.html
|
||||
# and 500.html exist at the root). Asserting it would be red on arrival.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DIR="${1:-.vercel/output/static}"
|
||||
MIN_FILES=20
|
||||
|
||||
fail() {
|
||||
echo "::error::publish gate: $1"
|
||||
echo "publish gate REFUSED the deploy: $DIR is not a complete build." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -d "$DIR" ] ||
|
||||
fail "$DIR does not exist — the page build produced no output directory."
|
||||
|
||||
# The Pages entrypoint. Without it Cloudflare serves the static assets only,
|
||||
# and every real route of the status page (/, /incidents, /api/data) is a 404.
|
||||
[ -s "$DIR/_worker.js/index.js" ] ||
|
||||
fail "$DIR/_worker.js/index.js is missing or empty — nothing would serve / or /incidents."
|
||||
|
||||
# Tells Pages which paths go to the worker instead of the asset store. Missing
|
||||
# it, requests never reach the entrypoint above.
|
||||
[ -s "$DIR/_routes.json" ] ||
|
||||
fail "$DIR/_routes.json is missing or empty — Pages would route no request to the worker."
|
||||
|
||||
[ -d "$DIR/_next/static" ] ||
|
||||
fail "$DIR/_next/static does not exist — the client bundle was not emitted."
|
||||
|
||||
chunks=$(find "$DIR/_next/static" -type f -name '*.js' | wc -l | tr -d ' ')
|
||||
[ "$chunks" -ge 1 ] ||
|
||||
fail "no JavaScript chunk under $DIR/_next/static — the page would load without its client bundle."
|
||||
|
||||
files=$(find "$DIR" -type f | wc -l | tr -d ' ')
|
||||
[ "$files" -ge "$MIN_FILES" ] ||
|
||||
fail "only $files files in $DIR, expected at least $MIN_FILES — the build looks truncated."
|
||||
|
||||
echo "publish gate OK: $files files, $chunks client chunks, worker entrypoint present."
|
||||
Loading…
Reference in New Issue