Skip to content

feat(deploy): deploy staging from the rc/* release candidate, production from a v* tag - #185

Merged
aRustyDev merged 1 commit into
mainfrom
feat/deploy-from-rc
Nov 15, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
feat/deploy-from-rc

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

PR 2 of the CI/CD plan (.agents/plans/cicd-review/PLAN.md), following the owner's decision of 2026-11-14:

  • Staging deploys each release candidate (release-plz's rc/<timestamp> branch, or an rc/manual-* one).
  • Production deploys from a v* release tag, behind the reviewers.
  • main never deploys.

How a release candidate reaches staging

The obvious design, deploy.yml on a workflow_run of ci filtered to rc/**, can't work. GitHub checks an environment's branch rule against the run's own ref, and a workflow_run always runs on main. So once staging takes only rc/*, a workflow_run deploy would be refused.

Instead:

  1. ci runs on the release-candidate PR in full, whatever its diff. The diff against main is only CHANGELOG.md and the version, but its gate is what lets the commit reach staging. Also, release-plz builds the candidate on whatever main was, whether or not main's own run passed.

  2. When that run is green, deploy.yml plans dispatch. A new dispatch job runs gh workflow run deploy.yml --ref <rc branch> -f environment=staging -f sha=<commit>. It has actions: write and no secret.

  3. The dispatched run is on rc/*, so staging accepts it. It checks everything again:

    • the branch is an rc/<name> of this repository;
    • the branch is still at that commit; if release-plz moved it, the run skips and the newer commit's own ci run takes over;
    • the commit's gate passed;
    • the gated environments have reviewers.

    Then it builds, attests and deploys as before.

A dispatch is one of the two events a workflow's own token may start a run with, so no App token is needed here.

I rejected adding a push trigger on rc/** to ci.yml. It would run the full suite twice per candidate, once for the push and once for the PR. It would also put two gate reports on one commit, and assert-sha-checks.sh requires every report to be SUCCESS, so a PR run still in progress would block the deploy.

Changes

File Change
ci.yml A PR whose head is this repository's rc/* runs everything
deploy.yml Triggered by a workflow_run of ci on rc/**; new dispatch job. A manual run deploys the commit it runs from. The ref input is replaced by sha, the commit the branch must still be at. The deploy build stops saving a cache no later run could read (a cache is readable only from its own ref, and every candidate is a new branch)
plan-deploy.sh dispatch only for this repository's rc/<name> PR, and only while THRUST_DEPLOY_ENABLED is true (kept as the off switch for the automatic path). Staging only from refs/heads/rc/<name>. Production only from refs/tags/v<version> whose commit is on main. One path segment after the prefix, matching the rulesets: rc/a/b is not protected by them, so it's refused
verify-bundle.sh Now takes the bundle's source ref and asks gh for exactly that ref. Any ref other than rc/<name> or v<version> is refused before gh is asked. The action passes the run's own ref
fetch-previous-assets.sh Looks only at artifacts from this repository's own runs (head_repository_id == repository_id, so never a fork's) on an rc/* branch or a v* tag, and verifies each on the ref its run was on
cicd.md, deploy.md, PLAN.md The new trigger, the environment branch rules, the release App now live, and what was built and why

Tests

  • test-plan-deploy.sh checks every combination: 1,344 workflow_run and 2,304 workflow_dispatch (10,097 checks). The expected answer is restated in the test, not read from the script.
  • test-verify-bundle.sh covers 12 refs that must be refused without asking gh: main, a feature branch, rc/a/b, a PR ref, bare names and look-alikes.
  • test-fetch-previous-assets.sh covers refs that don't deploy, a fork's artifact named like ours, and a newer fork artifact that must not hide ours.
  • 22 hand mutants of the three scripts, each breaking one rule. Every one was caught by its test.
  • Locally: every ci-scripts test and every deps guard, with sh as dash; lint-workflow.sh; actionlint.

Not verified until it runs

Owner steps after merging

Restrict staging and staging-do-lifecycle to rc/* branches. I held this back until now because it would refuse today's main-based runs:

PUT replaces an environment's protection rules, so staging-do-lifecycle's body repeats its required reviewer (you):

R=repos/arustydev/thrust
gh api -X PUT "$R/environments/staging" --input - <<'EOF'
{ "deployment_branch_policy": { "protected_branches": false, "custom_branch_policies": true } }
EOF
gh api -X PUT "$R/environments/staging-do-lifecycle" --input - <<'EOF'
{ "prevent_self_review": false, "reviewers": [ { "type": "User", "id": 36318507 } ],
  "deployment_branch_policy": { "protected_branches": false, "custom_branch_policies": true } }
EOF
gh api -X POST "$R/environments/staging/deployment-branch-policies" -f name='rc/*' -f type=branch
gh api -X POST "$R/environments/staging-do-lifecycle/deployment-branch-policies" -f name='rc/*' -f type=branch

Refs: #49

🤖 Generated with Claude Code

…ion from a v* tag

The owner's decision of 2026-11-14: staging deploys every release
candidate, production deploys from the release tag behind reviewers,
and main never deploys. An environment's branch rule is checked against
the run's own ref, and a workflow_run always runs on main, so staging
restricted to rc/* cannot be reached from workflow_run alone.

- ci.yml: a release-candidate pull request (head rc/* in this
  repository) runs everything, whatever its diff: its gate is what lets
  the commit reach staging, and release-plz builds it on whatever main
  was.
- deploy.yml: a green ci on such a pull request plans `dispatch`; the
  new dispatch job (actions: write, no secret) starts deploy.yml again
  with workflow_dispatch ON the rc branch, for that commit, and that run
  deploys. A manual run deploys the commit it runs from; the `ref`
  input is replaced by `sha`, the commit the branch must still be at.
  The deploy build stops saving a cache no later run could read.
- plan-deploy.sh: dispatch only for this repository's rc/<name> pull
  request with THRUST_DEPLOY_ENABLED true; staging only from
  refs/heads/rc/<name>, production only from refs/tags/v<version> whose
  commit is on main; one segment after the prefix, as the rulesets
  match; a branch that moved since the dispatch skips.
- verify-bundle.sh takes the bundle's source ref and asks for exactly
  that, refusing any ref but rc/<name> and v<version> before asking gh;
  the action passes the run's own ref.
- fetch-previous-assets.sh looks only at artifacts of this repository's
  own runs on an rc/* branch or a v* tag, and verifies each on the ref
  its run was on.
- cicd.md and deploy.md describe the new trigger, the branch rules and
  the release App now live; PLAN.md records what was built and why it
  differs from the first sketch.

Tests: test-plan-deploy.sh over every combination (1344 workflow_run,
2304 workflow_dispatch), test-verify-bundle.sh and
test-fetch-previous-assets.sh with must-fail refs; 22 hand mutants of
the three scripts, each caught by its test.

Refs: #49
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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