From 73dd2f3f741ab074f0ddaa094a72d36161f75825 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 25 Nov 2026 22:17:03 -0800 Subject: [PATCH 1/2] ci: deploy staging from main and live from release (backport #305) Backports only the deploy workflow and its docs from main's f78ce0a, so release proves the live half without main's unreleased /huh work. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/deploy.yml | 63 ++++++++++++++++++++++++++++++++++++ .github/workflows/pr.yml | 2 +- AGENTS.md | 4 +-- README.md | 13 ++++++-- justfile | 7 ++-- 5 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..1b1e329f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,63 @@ +name: deploy + +# main deploys staging and release deploys live, each through `just deploy`'s +# build and upload recipes. +on: + push: + branches: ["main", "release"] + +permissions: + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + timeout-minutes: 30 + environment: ${{ github.ref_name == 'release' && 'live' || 'staging' }} + # Never cancel a run mid-upload, and queue every pending run: the default + # single pending slot would let a late run for an older push evict the + # tip's. The queue doesn't keep pushes in order, so the tip check below + # makes the tip's run the last to upload. + concurrency: + group: deploy-${{ github.ref_name }} + cancel-in-progress: false + queue: max + env: + MODE: ${{ github.ref_name == 'release' && 'live' || 'staging' }} + + steps: + - uses: actions/checkout@v7 + with: + submodules: true + # bun install builds @moq/libav from the moq submodule's flake. Accepting + # its nixConfig pulls the build from the nix.moq.dev cache. + - uses: cachix/install-nix-action@3dc140bfc76c49fbd4dd958429132e3746bcb086 # v31 + with: + extra_nix_config: accept-flake-config = true + - uses: oven-sh/setup-bun@v2 + with: + bun-version-file: package.json + no-cache: true + # just from the flake's locked nixpkgs, the same one the dev shell uses. + - run: echo "$(nix build --no-link --print-out-paths --inputs-from . 'nixpkgs#just^out')/bin" >> "$GITHUB_PATH" + + - run: bun install --frozen-lockfile + - run: just build "$MODE" + + # A newer push's run deploys after this one, so uploading now would only + # roll the site back until it does. + - id: tip + run: | + tip=$(gh api "repos/$GITHUB_REPOSITORY/branches/$GITHUB_REF_NAME" --jq .commit.sha) + if [ "$tip" = "$GITHUB_SHA" ]; then + echo "current=true" >> "$GITHUB_OUTPUT" + else + echo "::notice::Skipping the upload: $GITHUB_REF_NAME moved to $tip, whose run deploys it." + fi + env: + GH_TOKEN: ${{ github.token }} + + - if: steps.tip.outputs.current == 'true' + run: just deploy-upload "$MODE" + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 99e3f476..ab42ca87 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -2,7 +2,7 @@ name: pr on: pull_request: - branches: ["main"] + branches: ["main", "release"] # Cancel a superseded run so a newer push to the PR frees its runner. concurrency: diff --git a/AGENTS.md b/AGENTS.md index 56051a27..f92e4bc2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,12 +2,12 @@ Read `README.md` for the three sites (moq.dev, moq.pub, moq.watch), setup, and t # Rules -- Never deploy to any environment, including staging, without the user's explicit permission for that deployment. A coding task or quest does not authorize a deploy. +- Merging to main deploys staging. Ask before merging into or pushing to `release`, or running `just deploy`. - Protocol, player, and publisher fixes belong upstream in moq-dev/moq (`@moq/publish`, `@moq/watch`, ...). Fix them there first, then bump the `moq` submodule here; the `@moq/*` packages build from it. # Development -PRs target `main` and land as squash merges. +PRs target `main` and land as squash merges. Release PRs from `main` into `release` land as merge commits. Dependabot PRs need no review once CI passes. Verify in the dev server (`just dev`, `just dev-pub`, `just dev-watch`). Hand-drawn art ships as SVG: `just trace` the drawn PNG, compare the two, then commit only the SVG. diff --git a/README.md b/README.md index af3a3c5a..23a802c1 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,16 @@ URLs together. For a local moq.pro stack, override `PUBLIC_API_URL` and ## Deploy -`just deploy` builds and uploads all three sites to Cloudflare, staging by -default; `just deploy live` goes to production. Deploy and seed the private -`try` project in the matching moq.pro environment before deploying these clients. +GitHub Actions (`.github/workflows/deploy.yml`) deploys all three sites to +Cloudflare: every push to `main` deploys staging (new.moq.dev, new.moq.pub, +new.moq.watch), and every push to the protected `release` branch deploys +production. To release, open a PR from `main` into `release` and land it as a +merge commit; backports are PRs onto `release`. Before merging a release PR, +check that the private `try` project in moq.pro's live environment is deployed +and seeded for these clients. + +`just deploy` builds and uploads from a laptop instead, staging by default; +`just deploy live` goes to production. ## License diff --git a/justfile b/justfile index 09f90088..5ff45163 100644 --- a/justfile +++ b/justfile @@ -65,8 +65,11 @@ build mode="live": bun vite build sites/pub --mode {{mode}} bun vite build sites/watch --mode {{mode}} -# Deploy all three sites to Cloudflare. -deploy env="staging": (build env) +# Build and deploy all three sites to Cloudflare. +deploy env="staging": (build env) (deploy-upload env) + +# Upload the already built sites to Cloudflare. +deploy-upload env="staging": bun wrangler deploy --config sites/pub/wrangler.jsonc --env {{env}} bun wrangler deploy --config sites/watch/wrangler.jsonc --env {{env}} bun wrangler deploy --env {{env}} From f6dcaefdb4d498a3f6d11b707a9b264e5f10fb3e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 25 Nov 2026 22:51:12 -0800 Subject: [PATCH 2/2] docs(agents): ask before any hand deploy, including wrangler deploy Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index f92e4bc2..913249d5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ Read `README.md` for the three sites (moq.dev, moq.pub, moq.watch), setup, and t # Rules -- Merging to main deploys staging. Ask before merging into or pushing to `release`, or running `just deploy`. +- Merging to main deploys staging. Ask before merging into or pushing to `release`, or deploying by hand (`just deploy*`, `wrangler deploy`). - Protocol, player, and publisher fixes belong upstream in moq-dev/moq (`@moq/publish`, `@moq/watch`, ...). Fix them there first, then bump the `moq` submodule here; the `@moq/*` packages build from it. # Development