magicciv/.forgejo/workflows/deploy-next.yml
Natalie 3c0d1660f1 chore(@projects/@magic-civilization): 🔧 increase deploy timeout to 60 minutes
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-04-18 08:01:35 -07:00

118 lines
5.6 KiB
YAML

# Magic Civilization — auto-deploy dev guide on push to main.
#
# Implements objective p1-17 (`.project/objectives/p1-17-guide-next-auto-deploy.md`)
# on top of p1-15's infra. After a push to main touches the guide / simulator
# / guide-engine surface, this workflow rebuilds WASM and pushes the dev bundle
# to https://mc.next.black.local via `./run deploy:guide:next`.
#
# Runner: the same apricot self-hosted runner as ci.yml (see `.forgejo/RUNNER_SETUP.md`).
# Apricot's `~/.ssh/config` has `Host black → id_ed25519_black`, which is
# already authorised on `lilith@black.local`. `./run deploy:guide:next`
# uses that alias via `NEXT_DEPLOY_HOST=black`.
#
# Budget: median completion <= 5 min. If WASM compile dominates, add a cache
# step reusing `.local/build/wasm/` across runs.
name: deploy-next
on:
push:
branches:
- main
paths:
# Only redeploy when the guide, simulator, or shared guide-engine /
# engine-ts packages change. An objective-file edit should NOT trigger
# a new static bundle.
- 'public/games/age-of-dwarves/guide/**'
- 'public/games/age-of-dwarves/data/**'
- 'public/resources/**'
- 'src/packages/guide/**'
- 'src/packages/engine-ts/**'
- 'src/simulator/**'
- 'scripts/run/deploy.sh'
- '.forgejo/workflows/deploy-next.yml'
# Manual trigger from the Forgejo Actions UI (or POST api/.../dispatches)
# so a first-run smoke can happen without a sacrificial commit.
workflow_dispatch:
# One deploy at a time. A later push supersedes an in-flight deploy so we
# never leave the remote out of sync with main for long.
concurrency:
group: deploy-next-main
cancel-in-progress: true
jobs:
deploy:
name: deploy dev guide to mc.next.black.local
runs-on: [self-hosted, linux, apricot]
# Empirically: WASM build ~1min + pnpm install ~30s + vite build ~15s +
# 6-scenario sim-cache bake ~7min/scenario ≈ 42min bake + rsync of
# ~6.6 GB to black ≈ 3min over LAN. 30min was too tight; 60 leaves
# headroom and keeps us below Forgejo's default 6h cap.
timeout-minutes: 60
env:
# `./run deploy:guide:next` defaults to `lilith@black.local`, which
# apricot's SSH config doesn't have a specific identity for. The
# `black` alias IS in apricot's ~/.ssh/config (Host black →
# HostName 10.0.0.11, IdentityFile id_ed25519_black, IdentitiesOnly yes),
# so overriding to the alias is the path of least friction.
NEXT_DEPLOY_HOST: black
# Bake all canonical sim-cache scenarios on every deploy. Apricot has
# the CPU budget; ~15 min added to the job for ~6.6 GB of frames.
DEPLOY_BAKE_SCENARIOS: all
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
# ── PATH setup ───────────────────────────────────────────────────
# The forgejo-runner systemd unit's `Environment=PATH=...` deliberately
# excludes per-user dirs so jobs start from a clean slate. Prepend:
# - `~/.cargo/bin` for `wasm-pack` (rustup-installed).
# - `~/.local/share/fnm/aliases/default/bin` for `node` + `pnpm`
# (fnm-managed; the `default` alias stays stable even when node
# versions rotate).
# Both come from `.forgejo/RUNNER_SETUP.md` prereqs.
- name: Prime PATH for cargo + node tools
run: |
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
echo "$HOME/.local/share/fnm/aliases/default/bin" >> "$GITHUB_PATH"
# ── WASM build ───────────────────────────────────────────────────
# `./run deploy:guide:next` errors out if `.local/build/wasm/magic_civ_physics.js`
# is missing (the Vite alias must resolve). Fresh checkouts have no
# `.local/`, so build it here. Apricot already has wasm-pack + rustup
# (prereqs documented in .forgejo/RUNNER_SETUP.md).
- name: build WASM
working-directory: src/simulator
run: bash build-wasm.sh
# ── Install deps ─────────────────────────────────────────────────
# Fresh checkouts have no node_modules/. `./run deploy:guide:next`
# calls `pnpm build` inside the guide workspace, which needs the
# `vite` + `@magic-civ/guide-engine` packages wired up by a workspace
# install at repo root.
- name: pnpm install
run: pnpm install --frozen-lockfile --prefer-offline
# ── Deploy ───────────────────────────────────────────────────────
# cmd_deploy_guide_next does: WASM prereq check → VITE_DEV_GUIDE=1 pnpm build
# → SSH reachability probe → rsync -az --delete → curl HTTP 200 verify.
- name: deploy
run: ./run deploy:guide:next
# ── Deploy log artifact ──────────────────────────────────────────
# On failure, the deploy log and the dist/ manifest are the two
# things we'll want to diff against the last green run. `dist/`
# alone is ~12 MB; capping retention at 7 days to match ci.yml.
- name: Upload deploy artifact
if: failure()
uses: actions/upload-artifact@v3
with:
name: deploy-next-${{ github.sha }}
path: |
public/games/age-of-dwarves/guide/dist/**
retention-days: 7