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
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 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

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