Repository navigation
ci: deploy staging from main and live from release #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c59d0b5
chore(quest): claim quest/m2/auto-deploy.md
kixelated 2a340f5
ci: deploy staging from main and live from release
kixelated 5ed4e77
fix: name the upload recipe deploy-upload so the deploy approval rule…
kixelated 8c75022
quest(m2): auto-deploy setup is done; only protecting release remains
kixelated 364ce34
Merge remote-tracking branch 'origin/main' into quest/m2/auto-deploy
kixelated 6ef93e7
ci(deploy): don't cache Bun, so a live run can't restore a binary a m…
kixelated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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 }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.