Skip to content

ci(deploy): deploy main to production from a manual workflow - #81

Merged
HMarzban merged 3 commits into
mainfrom
ci/deploy-workflow
Nov 15, 2026
Merged

HMarzban merged 3 commits into
mainfrom
ci/deploy-workflow

Conversation

@HMarzban

Copy link
Copy Markdown
Contributor

What

A manual Deploy workflow for production, .github/workflows/deploy.yml:

gh workflow run deploy.yml                 # tip of main
gh workflow run deploy.yml -f ref=<sha>    # a commit of main

On the runner (it never checks out or runs repo code; read-only token plus actions: read):

  • resolves the ref, and refuses a commit that isn't on main or whose ci.yml run on main didn't pass (it waits for a run still in progress);
  • SSHes to the host with strict host-key checking.

On the host, the key's authorized_keys entry is restrict,command="…/scripts/deploy.sh", so the key can only run scripts/deploy.sh. The script:

  • accepts only a full SHA on origin/main;
  • refuses local changes and never moves backwards;
  • checks its tools are on PATH;
  • builds Next.js in a second checkout (the site keeps serving), restarts Hocus from ecosystem.config.cjs, then swaps .next (keeping .next.prev) and restarts Next.js;
  • puts the previous build back if Next.js doesn't answer within 90 s.

Deploys are serialised by the workflow's concurrency group and a flock on the host.

Tests

  • tests/unit/ci/deploy-script.test.ts: the script is executable, and it rejects every non-SHA input (injection attempts included) with exit 2 before running anything.
  • The existing workflow guard tests pass for deploy.yml: read-only default token, no unpinned actions.
  • shellcheck and actionlint are clean.
  • bun run check, lint, typecheck and test pass.

Deploy note (one-time, operator)

These steps are in docs/operations/deploy-runbook.md:

  • host checks: tools on a plain SSH session's PATH, fetch without an agent, PM2 env vs ecosystem.config.cjs;
  • a deploy key with the forced command;
  • the production environment, limited to main, with DEPLOY_HOST, DEPLOY_USER, DEPLOY_SSH_KEY and DEPLOY_KNOWN_HOSTS (plus DEPLOY_PORT if needed);
  • one git pull --ff-only on the host, so deploy.sh exists before the first run.

Builds on #80, so the highlight-rewrite flag is in the file every deploy restarts from.

gh workflow run deploy.yml checks the commit is on main with green CI,
then SSHes to the host with a key whose forced command is
scripts/deploy.sh. The script builds in a second checkout, restarts Hocus,
swaps .next and puts the old build back if Next.js does not answer.
…first run

The script now fails before touching anything if bun, git, flock or curl
is missing from the forced-command session's PATH, and runs as one
function so a fast-forward cannot change it mid-run. The runbook adds the
host checks, the main-only environment policy and the one-time pull that
puts deploy.sh on the host before the first run.
@HMarzban
HMarzban merged commit e93169d into main Nov 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant