Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 deletions .github/workflows/cms.yml

This file was deleted.

991 changes: 0 additions & 991 deletions .github/workflows/pages.yml

This file was deleted.

288 changes: 288 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
# The site on one Worker (spec docs/specs/2026-11-29-unified-astro-emdash.md, Delivery and Implementation Plan 4.1;
# WP12). Replaces pages.yml: one site build (`yarn build:worker`, the Astro handler, the route manifest and the Run
# resources of a pinned data commit), the WP11 harness on the runner without a browser, then one Worker version with
# the D1 migrations applied before it, in the protected environment `www`.
# Runs on the same triggers pages.yml had: after watch, sync and collect finish on main (they push the data branch
# with GITHUB_TOKEN, which starts no workflow), on push to main, daily and by hand. So a code change and a data refresh
# each release a new version. An editorial publication is no trigger: it commits to D1 with the Worker in place.
# Two jobs. `build` has no environment and decides from repository variables alone (`yarn om release settings`,
# lib/release/settings.ts): with none set the run builds and checks, ends green and says it released nothing; a
# partial or malformed set fails red, so a half setup never deploys. `release` runs on main only, in environment `www`,
# deploys the build it downloads (never a second build) and needs the secrets CLOUDFLARE_API_TOKEN and OM_PURGE_TOKEN.
# The release attaches no route and no domain: www and the old hosts move to the Worker by the operator's switch
# (docs/RUNBOOK.md, Main site on the Worker). The harness's browser checks (the calculator and the e2e suites) are the
# owner's step on the Mac before the switch and after a change of the pages (same RUNBOOK section); here they are the
# only checks the gate lets pass as not run.
# No third-party module code runs here: the build reads the data branch the night wrote, as pages.yml did.
name: release

on:
push:
branches:
- main
workflow_run:
workflows:
- watch
- sync
- collect
types:
- completed
branches:
- main
schedule:
- cron: "47 5 * * *"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: release
cancel-in-progress: false

defaults:
run:
shell: bash

env:
# the main site with Run under /run (the route matrix's BUILD_ENV, test/pages/route-matrix.ts): fixed for the one
# production layout, no longer repository variables
SITE_URL: https://www.openmercato.com
BASE_PATH: /run
HOME_PATH: /modules
PAGES_MERGED: "1"
WRANGLER_SEND_METRICS: "false"

jobs:
build:
name: build
# Off while the repository is private (nothing to publish yet); it starts once the repository is public.
if: ${{ !github.event.repository.private && (github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success') }}
runs-on: ubuntu-latest
timeout-minutes: 45
outputs:
release: ${{ steps.settings.outputs.release }}
settings: ${{ steps.settings.outputs.digest }}
commit: ${{ steps.checkout.outputs.commit }}
data: ${{ steps.data.outputs.commit }}
env:
ASTRO_TELEMETRY_DISABLED: "1"
MCP_URL: ${{ vars.MCP_URL }}
WEBMCP_OT_TOKENS: ${{ vars.WEBMCP_OT_TOKENS }}
# the build reads the Access team domain (astro.worker.config.ts, the EmDash adapter); unset, a placeholder
CF_ACCESS_TEAM_DOMAIN: ${{ vars.CF_ACCESS_TEAM_DOMAIN }}
steps:
- name: Checkout
id: checkout
# main as it is now (a pending run builds the newest commit); a run on another ref builds the commit it was
# started on and releases nothing
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.ref == 'refs/heads/main' && 'main' || github.sha }}
persist-credentials: false

- name: Set up Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc

- name: Enable Corepack
run: corepack enable

- name: Install
run: yarn install --immutable

- name: Check release settings
id: settings
# Repository variables only: a job without an environment sees no environment secret, and the variables are
# no secrets. release=true needs all of them, well formed, on main.
env:
ON_MAIN: ${{ github.ref == 'refs/heads/main' }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
SITE_D1_DATABASE_ID: ${{ vars.SITE_D1_DATABASE_ID }}
SITE_D1_DATABASE_NAME: ${{ vars.SITE_D1_DATABASE_NAME }}
SITE_R2_BUCKET: ${{ vars.SITE_R2_BUCKET }}
SITE_KV_ID: ${{ vars.SITE_KV_ID }}
CF_ACCESS_AUDIENCE: ${{ vars.CF_ACCESS_AUDIENCE }}
OM_PURGE_ZONE_ID: ${{ vars.OM_PURGE_ZONE_ID }}
run: |
echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
yarn om release settings

- name: Read data branch
id: data
# Empty data only when the branch does not exist. A fetch that fails for any other reason (network,
# credentials) stops the release instead of publishing an empty catalog over the live one.
run: |
err="$RUNNER_TEMP/data-fetch.err"
if git fetch --no-tags --depth=1 origin +refs/heads/data:refs/remotes/origin/data 2>"$err"; then
git worktree add --detach .data origin/data
echo "commit=$(git -C .data rev-parse HEAD)" >> "$GITHUB_OUTPUT"
elif grep -q "couldn't find remote ref" "$err"; then
mkdir -p .data
echo "commit=none" >> "$GITHUB_OUTPUT"
echo "No data branch yet: building on empty data." | tee -a "$GITHUB_STEP_SUMMARY"
else
cat "$err"
echo "::error::Cannot read the data branch; not releasing."
exit 1
fi

- name: Build the Worker
# The one site build: the emitter on the pinned data commit, then the Astro server build to dist-worker/.
run: yarn build:worker

- name: Check the Worker
# The files released clients read without following redirects (the Worker serves the root copies from these),
# wrangler's own bundle and checks of the built config, offline and without the token, then the account's
# limits (compressed size, asset files). The build is kept apart before the harness rebuilds dist-worker/.
# wrangler uploads dotfolders as assets (it skips only .assetsignore, _headers and _redirects), so
# .well-known/ goes up as built. The MCP server card is there only with MCP_URL (finding of 25 Oct).
run: |
site=dist-worker/client/run
for f in .well-known/agent-skills/index.json modules.json templates.json picker.json llms.txt; do
test -f "$site/$f" || { echo "::error::$site/$f is missing"; exit 1; }
done
test -d "$site/schema" || { echo "::error::$site/schema is missing"; exit 1; }
test -f dist-worker/server/wrangler.json || { echo "::error::dist-worker/server/wrangler.json is missing"; exit 1; }
if [ -n "${MCP_URL:-}" ]; then
test -f "$site/.well-known/mcp/server-card.json" || { echo "::error::$site/.well-known/mcp/server-card.json is missing"; exit 1; }
fi
yarn wrangler deploy --dry-run --config dist-worker/server/wrangler.json --outdir "$RUNNER_TEMP/bundle" 2>&1 | tee "$RUNNER_TEMP/dry-run.log"
yarn om release limits --dist dist-worker --wrangler-log "$RUNNER_TEMP/dry-run.log"
rm -rf "$RUNNER_TEMP/release-build"
cp -R dist-worker "$RUNNER_TEMP/release-build"

- name: Run the harness
# The WP11 harness (scripts/worker-harness.ts) without a browser: route matrix, smoke, Access, media, the
# concurrent walk, Run and editorial parity, compare-live, SEO, OG cards, the www build tests on the Worker,
# the publish guard. The gate passes only when every check that ran passed and the only checks not run are
# the browser checks (lib/release/gate.ts); those are the owner's (docs/RUNBOOK.md).
timeout-minutes: 30
run: |
code=0
node scripts/worker-harness.ts --no-browser --data .data --out out/worker-harness || code=$?
yarn om release gate --report out/worker-harness/report.json --exit "$code"

- name: Upload harness report
if: ${{ always() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: worker-harness
path: |
out/worker-harness/report.txt
out/worker-harness/report.json
out/worker-harness/logs
if-no-files-found: ignore
retention-days: 7

- name: Upload the Worker
# Only for a release (artifact storage counts against the account quota), kept 7 days: the release job waits
# for the approval of environment `www`, which may come the next day.
if: ${{ steps.settings.outputs.release == 'true' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: worker
path: ${{ runner.temp }}/release-build
include-hidden-files: true
if-no-files-found: error
retention-days: 7

release:
name: release
needs: build
if: ${{ needs.build.outputs.release == 'true' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
timeout-minutes: 20
environment:
name: www
url: https://www.openmercato.com/
env:
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
SITE_D1_DATABASE_ID: ${{ vars.SITE_D1_DATABASE_ID }}
SITE_D1_DATABASE_NAME: ${{ vars.SITE_D1_DATABASE_NAME }}
SITE_R2_BUCKET: ${{ vars.SITE_R2_BUCKET }}
SITE_KV_ID: ${{ vars.SITE_KV_ID }}
CF_ACCESS_TEAM_DOMAIN: ${{ vars.CF_ACCESS_TEAM_DOMAIN }}
CF_ACCESS_AUDIENCE: ${{ vars.CF_ACCESS_AUDIENCE }}
OM_PURGE_ZONE_ID: ${{ vars.OM_PURGE_ZONE_ID }}
steps:
- name: Checkout
# The commit the build job built: wrangler from its lockfile, and lib/emdash/migrations for the D1 migrations
# (the built config names them relative to dist-worker/server/).
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.build.outputs.commit }}
persist-credentials: false

- name: Set up Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc

- name: Enable Corepack
run: corepack enable

- name: Install
run: yarn install --immutable

- name: Check secrets
# Every variable and both secrets, or the job fails red: a release started without them is a half setup. The
# variables must be the ones the build job read (a variable of environment `www` would override one here only).
env:
ON_MAIN: ${{ github.ref == 'refs/heads/main' }}
BUILD_SETTINGS: ${{ needs.build.outputs.settings }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
OM_PURGE_TOKEN: ${{ secrets.OM_PURGE_TOKEN }}
run: yarn om release settings --secrets --require --digest "$BUILD_SETTINGS"

- name: Download the Worker
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: worker
path: dist-worker

- name: Write the production config
# The built config with the production D1, R2 and KV ids and the Access and purge variables; no route.
run: yarn om release write --config dist-worker/server/wrangler.json

- name: Record the D1 recovery point
# Time Travel's bookmark of the database before the migrations: the restore point of docs/RUNBOOK.md,
# Recovery, if a migration or this version has to be undone.
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
yarn wrangler d1 time-travel info DB --config dist-worker/server/wrangler.json --json | tee "$RUNNER_TEMP/d1-bookmark.json"
{
echo "D1 recovery point before this release:"
echo '```'
cat "$RUNNER_TEMP/d1-bookmark.json"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

- name: Apply D1 migrations
# The site's migrations (lib/emdash/migrations) not yet in d1_migrations, before the version that needs them.
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: yarn wrangler d1 migrations apply DB --remote --config dist-worker/server/wrangler.json

- name: Deploy
# One Worker version of the downloaded build, with the purge token as a Worker secret (written to a file only
# this step reads, removed after). The version id is the rollback handle (`wrangler rollback <id>`).
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
OM_PURGE_TOKEN: ${{ secrets.OM_PURGE_TOKEN }}
COMMIT: ${{ needs.build.outputs.commit }}
DATA: ${{ needs.build.outputs.data }}
run: |
secrets="$RUNNER_TEMP/worker-secrets.json"
trap 'rm -f "$secrets"' EXIT
yarn om release secrets --to "$secrets"
yarn wrangler deploy --config dist-worker/server/wrangler.json --secrets-file "$secrets" \
--message "commit ${COMMIT:0:12} data ${DATA:0:12}" 2>&1 | tee "$RUNNER_TEMP/deploy.log"
version="$(grep -oE 'Current Version ID: [0-9a-f-]+' "$RUNNER_TEMP/deploy.log" | sed 's/.*: //' || true)"
{
echo "Worker released: version ${version:-see the wrangler output} of commit \`$COMMIT\`, data \`$DATA\`."
echo ""
echo "The hosts it serves are the operator's routes (docs/RUNBOOK.md, Main site on the Worker)."
} >> "$GITHUB_STEP_SUMMARY"
Loading