Skip to content
Merged
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
63 changes: 63 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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 }}
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
80 changes: 19 additions & 61 deletions quest/m2/auto-deploy.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,31 @@
# [S] Deploy staging from main and live from release
# [XS] Deploy staging from main and live from release

## Goal

Every push to `main` deploys moq.dev, moq.pub and moq.watch to staging from
GitHub Actions, and every push to a protected `release` branch deploys them
live, so production changes only when `release` moves. Today every deploy is
a manual `just deploy [live]` from a laptop's wrangler login, so merged work
sits undeployed until someone remembers.
live, so production changes only when `release` moves.

Non-goals: what each mode builds (the unreleased-route gate from
[#300](https://github.com/moq-dev/moq.dev/pull/300) stays, so `/huh` ships to
staging and not live), and moq.pro's deploys.

## Plan

Decided 2026-11-25 (maintainer, `/quest-run` then `/quest-plan`):

- ✅ Staging on every push to `main`, live on every push to `release`
(rejected: live behind a protected-environment approval on `main`'s
workflow; staging only; dropping it). This keeps the intent of
[#102](https://github.com/moq-dev/moq.dev/pull/102), which removed the old
live-on-`main` workflow: production still moves only on a person's merge.
- ✅ `main` reaches `release` through a PR that the maintainer merges, and
backports go in as PRs onto `release`, as in moq.pro (rejected: a
workflow_dispatch that fast-forwards `release`; direct pushes).
- ✅ Reword the AGENTS.md deploy rule to: "Merging to main deploys staging.
Ask before merging into or pushing to `release`, or running
`just deploy`." (rejected: keeping staging behind explicit permission,
which defeats deploy-on-push).

Recommendations:

- One workflow on `push` to `main` and `release` that runs the `just deploy`
steps with `staging` or `live`, so the laptop path and CI share one recipe.
Use one GitHub environment per target, each limited to its branch, holding
the Cloudflare token. A GitHub-hosted runner fits a short deploy job.
Serialize runs per environment and don't cancel one mid-upload (the
workflow [#102](https://github.com/moq-dev/moq.dev/pull/102) removed set
`cancel-in-progress: true`). A concurrency group doesn't keep pushes in
order, and its default single pending slot lets a late run for an older
push evict the tip's queued run. So queue every pending run, and right
before uploading, skip the upload when the run's commit is no longer its
branch's tip; the tip's run then always deploys last. The job needs what
`pr.yml`'s `check` job sets up: submodules, Nix with
`accept-flake-config` (`bun install` builds `@moq/libav` from the `moq`
submodule's flake), and Bun, plus `just`.
- Credentials: `bws` holds `cloudflare-admin-token`, which can reach the
`moq.dev` account (`dd618f5d…`, the `account_id` in `wrangler.jsonc`).
Try minting an account-owned token with it, scoped to deploying these
Workers and their custom domains, and store that token as the environments'
secret. If the admin token can't mint one, add a `Maintainer:` item naming
the exact scopes.
- Create `release` at the commit live runs now; the 2026-11-25 deploy was
`e67ab91`. moq.pro protects its `release` with a per-repo ruleset
(no deletion, no force push, required checks); dotfiles'
`bin/repo-settings` has no `release` branch standard yet. Add one there
that both repos share rather than copying moq.pro's by hand.
- This repo allows only squash merges. Squash-merging a `main` to `release`
PR leaves `release` off `main`'s history, so each later release PR
re-diffs from the old merge base and conflicts with backports. Allow merge
commits for PRs into `release` (moq.pro allows them; `main`'s ruleset
already requires linear history), and merge release PRs with a merge
commit.
- `pr.yml` checks only PRs into `main`; make it check PRs into `release` too.
- Update README's Deploy section to match.
- The README says to deploy moq.pro's `try` project before these clients.
Staging may now briefly run a client ahead of moq.pro staging; that's
acceptable. The release PR is where the maintainer checks the moq.pro side
before going live.
- Verify each half on its real surface: a merge to `main` updates
new.moq.dev, and a release PR's merge updates moq.dev. Both need the
maintainer's merge.
[#305](https://github.com/moq-dev/moq.dev/pull/305) added
`.github/workflows/deploy.yml` and
[kixel-ai/dotfiles#362](https://github.com/kixel-ai/dotfiles/pull/362) the
`release` branch standard, and the environments, their tokens and the
`release` branch were set up on 2026-11-25. What remains is protecting
`release` under `Waiting`, then checking each half on its real surface: a
merge to `main` updates new.moq.dev, new.moq.pub and new.moq.watch, and a
release PR's merge updates moq.dev, moq.pub and moq.watch. Delete this quest
once both have deployed.

## Waiting

- Maintainer: once
[kixel-ai/dotfiles#362](https://github.com/kixel-ai/dotfiles/pull/362)
merges, run `repo-settings apply`, which protects `release` and allows merge
commits; an agent may not change live repository settings. Check with
`repo-settings check`, which should print nothing for moq-dev/moq.dev.