Skip to content

Workflows rendered from the declaration: triggers on env/<name>, auto-promotion, packages from main - #126

Merged
davidjalbers merged 21 commits into
stacks-3from
davidjalbers/plx-303-workflows-rendered-from-the-declaration
Dec 6, 2026
Merged

davidjalbers merged 21 commits into
stacks-3from
davidjalbers/plx-303-workflows-rendered-from-the-declaration

Conversation

@davidjalbers

@davidjalbers davidjalbers commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Milestone 3 of the environment branches: the workflows are rendered from the environments a repo declares.

Behaviours

  1. on_push runs on each declared env/<name>, by name, and on no other branch.
    repo-turbo renders on_push.yml only for a package repo or a repo that declares an environment, with branches: [env/<a>, env/<b>] taken from the declaration.
    on_commit runs on every other branch (branches-ignore the same list), main among it; with no declaration it runs on '**'.
    The deploy job deploys the environment of its branch (plx deploy without --environment).
  2. Auto-promotion.
    Each environment with auto_promote: true gets .github/workflows/promote-<name>.yml: workflow_run of [on_commit, on_push] (operations: [on_commit, deploy]), types: [completed], branches: [<source>], a job-level if on the run's conclusion, plx-ci setup promote, a second checkout with the App's token and fetch-depth: 0, then plx -y promote <name>.
    Only plx promote fast-forwards; it fails and changes nothing otherwise.
    It promotes the source's head as it stands when the job runs, which can be newer than the commit whose green run started the job: for an environment whose source is another environment, the target can so receive a commit whose run on the source has not finished.
    The workflow's comments and the header of setup promote say so, and that the newer push's own run promotes again; whether that changes is the maintainer's.
  3. The promoting push uses the App's token.
    plx-ci setup promote mints it with contents: write and workflows: write.
    The fast-forward can bring a changed file under .github/workflows onto the branch.
    GitHub's docs ask the Workflows permission of an App that edits files in .github/workflows ("Choosing permissions for a GitHub App"); that the forge refuses a push of existing commits that change one without it is relied on and not verified.
  4. on_push checks out the whole history with its tags (fetch-depth: 0 in the job repo); plx-ci image already refused a shallow clone.
  5. A package repo publishes from main by changesets: unchanged, and tested as such.
  6. A repo without stacks or a declaration has no env/ trigger: no on_push, no deploy.yml, no promotion.
  7. plx update lands on main: consumers.ts names no branch and lands on origin's default branch; every newborn of this checkout is on main.
  8. plx-ci setup refuses a deploy job off a declared env/<name> in any workflow (the operations repo's deploy, started by hand, among them), before anything is read.
  9. No workflow holds a conditional on an environment's name: a render test checks every if: of every rendered workflow.
  10. plx deploy --environment <name> refuses a name the repo does not declare, naming those it does; a repo that declares none, or whose declaration is invalid, deploys nowhere, with the option as without.
  11. The stack template renders one environment file per declared environment at birth (birth-only), none where none is declared; the stop-gaps STACK_FILE_ENVIRONMENTS, FILE_ENVIRONMENTS and declared are gone, and a newborn with a stack and no declaration passes the doctor.

Readings

  1. each, a new manifest key of plx-template.
    A template cannot loop over files, and one workflow and one environment file per declared environment need one.
    each: {<source path>: <list variable>} renders the source once per item with _item bound; generic, and it knows nothing of Plexus.
  2. declared_environments, a read plx computes.
    No template spells env/: templateAnswers (lib declaredEnvironments.ts) gives every render (plx new, plx update on both sides, plx apply, plx doctor's judge) a list of {name, branch, source, auto_promote}, empty where the declaration is invalid; it is never written into a marker.
    The question's help text of environments in both repo templates, which predates this branch, still names env/<name> in prose.
  3. The read defaults to [].
    The plx of an earlier version renders the new side of an update with the marker's answers alone; without the default every update from 0.138.0 would fail.
    With it, a repo taken by an older plx renders as one that declares nothing; plx apply on the new version renders the declared workflows.
  4. plx new -a environments=... gives the answer as text, so newSite renders twice: once to resolve the answers, once with the declaration computed from them.
  5. The job-level if on github.event.workflow_run.conclusion.
    The rule "a step is one command with no workflow condition" binds steps; the promotion's job condition reads the run's outcome, not an environment's name.
    Alternative: let plx-ci setup promote refuse a red run, which would mark every promotion after a red run red as well.
  6. The operations repo follows the branch model.
    Its deploy.yml runs on each declared env/<name>, deploys the environment of its branch, queues per branch (deploy-${{ github.ref }}), and has no paths filter, so that a promotion that creates a branch starts it.
    Alternative: keep deploy.yml on main with a named environment, which PLX-Delivery/NoWorkflowLogic and the "no conditional on a name" rule leave no room for.
  7. PLX-273 is gone: a hand-started deploy on a tag or another branch fails in one line in plx-ci setup, before any host.
  8. The promotion workflow is written twice, once per repo template, differing in the workflow it follows; no template both repo templates take holds workflows.
  9. The promotion hands its setup OP_SERVICE_ACCOUNT_TOKEN where ci_service_account is true (in the operations repo through a read with default true).
    A repo that deploys reads the vault, so the App's credentials may be there (PLX-Delivery/CIVault lets only a repo that reads nothing else from it hold them on the forge, and does not oblige it to), and the step is handed the token to find them; setup takes the forge's copy where both are set.
  10. each takes any item: an item may name a path below the source's directory (a/b lands at a/b), and one that leaves the output is the error any such path is; the engine checks nothing else, and plx bounds the items (an environment's name is one lowercase word).

Not covered by a test

  • That the forge starts on_push on a push made with the App's token, and none on one made with a workflow's own token: GitHub's documented behaviour, relied on, not exercised.
  • That workflow_run with branches filters on the head branch of the run it follows, and runs from the default branch's copy of the workflow.
  • A person writing declared_environments into a marker: plx replaces it on every render and plx doctor does not report it.
  • An environment declared after a stack's birth: plx apply adds no file (the files are birth-only); PLX-Stack/DeclaredHasFile tells only where no stack has a file for it.

Left

  • PLEXUS_COMMIT_SHA is still delivered by packages/lib/src/deploy.ts and packages/lib/src/compose.ts (§ 7.8), outside this issue's sections.

Release notes

The branch model moves from main/develop to main plus env/<name>, and the workflows follow the environments a repo declares.
Walked once with the packed tools, a repo of 0.138.0 taking this checkout as 0.139.0, in scratch repos with bare remotes.

What the plx of 0.138.0 does with this version.

  • A repo with a stack: the plx of 0.138.0 cannot take this version; the update fails before any branch is pushed.
    The engine of 0.138.0 cannot read the template stack of this version: template.yml: unknown key each and the policy of {{ _item.name }}.yaml.jinja is merge or born-once, not birth-only.
    birth-only is already on stacks-3, so this holds for stacks-3 without this branch as well; each is a second reason.
    Its scheduled plx-update shows one red run a day and pushes nothing; the version is taken by hand with the new plx (below).
  • A repo without a stack (the reviewer's run): the pull request has base develop in an app repo, and main in an operations repo.
    It deletes on_push.yml (or deploy.yml), sets on_commit to branches: ['**'], and writes environments: {}.
    Its body says "Nothing needs a hand: every site merged clean.", as does the plx of this version; the update prints unknown key each for the repo template, which is harmless.
    After the merge nothing tells the person anything: plx doctor passes, and the body carries no steps.
    An app repo without a stack that moves to main closes that pull request against develop and takes the version on main with the new plx (steps 2 and 3 below).
    Such a repo deploys nothing; an app repo without a stack also stops publishing images, since only an environment's branch does.

An app repo with a stack (0.138.0 deploys main to production and develop to staging).
The order that keeps the gap smallest, with the commands:

  1. Release develop once more the old way: git switch main && git pull && git merge origin/develop && git push.
    The push to main runs the old on_push, which deploys production; push nothing to develop from here on, where the old on_push would still deploy staging.
  2. Make main the default branch: gh repo edit --default-branch main.
    The promotion runs only from the default branch's copy of its workflow.
  3. Take the version with its own plx: mise exec npm:@plexus-ms/cli@<version> -- plx update --to <version> ..
    It pushes plexus/<version> and opens the pull request against main.
  4. On that branch: git fetch && git switch plexus/<version>; in the root marker replace environments: {} with the declaration matching the stack's files, for example {staging: {promotes_from: main, auto_promote: true}, production: {promotes_from: staging}}; then plx apply (the branch pins the new plx), plx doctor, commit and git push.
    plx apply adds on_push.yml on [env/staging, env/production] and promote-staging.yml, and turns on_commit to ignore the two branches.
    A push here runs on_pr; nothing deploys.
  5. Merge the pull request into main.
    The push to main runs on_commit only, and nothing deploys from main.
    Once it is green, promote-staging.yml creates env/staging at the head of main, and that push runs on_push, which publishes the images and deploys staging.
    Without auto_promote: plx promote staging.
  6. Once on_push on env/staging is green: plx promote production.
    It creates env/production, whose push runs on_push and deploys production.
    Promoting it while staging's run is still going deploys production from a commit staging has not finished with; plx promote production before step 5 is refused (env/staging … is not on the remote yet).
  7. Move branch protections and forge environments from main/develop to env/*, then git push origin :develop.

Production runs what step 1 deployed until step 6; a push to main between steps 1 and 6 deploys nowhere.

An operations repo with a stack (0.138.0 deploys main to production through deploy.yml):

  1. Take the version with its own plx: mise exec npm:@plexus-ms/cli@<version> -- plx update --to <version> ..
  2. On plexus/<version>: declare the environments in the root marker, for example {production: {promotes_from: main}}, matching the stacks' files; plx apply adds deploy.yml on [env/production]; plx doctor, commit, push.
  3. Merge into main: on_commit runs, and nothing deploys.
  4. plx promote production creates env/production, whose push runs deploy.
    With auto_promote: true, promote-production.yml does it after every green on_commit on main.

Production runs what it ran until step 4; a push to main between steps 3 and 4 deploys nowhere.

A package repo: nothing beyond taking the version.

Every repo:

  • A repo whose default branch is not main gets no promotion: the forge runs a workflow_run workflow only from the default branch's copy.
  • A push to main that changes only Markdown starts no run (paths-ignore: ['**/*.md']), and so no promotion, until the next push that does.
  • A repo that declares environments and has no stack fails PLX-Stack/DeclaredHasFile.
  • plx deploy --environment <name> refuses a name the root marker does not declare, and a repo that declares none deploys nowhere.
  • An operations repo can no longer deploy a branch by hand before it is merged: plx-ci setup refuses a deploy off a declared env/<name>.
  • An environment declared after a stack was born gets no file from plx apply; write stack/<name>.yaml by hand.
  • The tenant's App needs Contents: write and Workflows: write (already held for plx update).

In the walk, plx doctor on the update branch reported PLX-Repo/Verbs (the scratch shims mise) and, in the operations repo, PLX-Stack/Layout (the fixture's one stack sits at stacks/docs); the stacks passed.

What the pages say otherwise

The compendium at stacks-3 (5a8c7c3) says what this builds; nothing found that says otherwise.
Not on the pages:

  • That a repo taken by an older plx renders as one without environments until plx apply on the new version (reading 3).
  • That a repo with a stack cannot take this version by the plx of 0.138.0 (release notes).
  • That a repo declaring environments with no stack fails PLX-Stack/DeclaredHasFile, so declaring environments needs a stack first.
  • The lint checkout /home/albers/dev.worktrees/scratch/stacks-3-lint/compendium stands at e0be761, behind origin/stacks-3 (5a8c7c3); the citation lint passes against both.

Verification

  • TURBO_FORCE=true mise run test at c89e2bd: exit 0, Tasks: 7 successful, 7 total, Cached: 0 cached, 7 total, Finished in 393.55s; the pre-push hook's test passed as well.
  • Newborns against the packed tools at 0743777: repo-turbo 14/14, repo-operations 9/9; at 77d71c3: pipeline 4/4, deploy-job 15/15, app-nextjs 15/15, e2e-playwright with helpers 48/48, update-released 20/20.
  • mise run e2e once at 77d71c3: 203 pass, 1 fail, runner-host-mail, on a DNS failure of the container's apt; run again alone, 13/13.
  • Each new test broken once: each.test.ts fails with only the first item rendered (7), with an item's slashes flattened (2), with a path outside the output not refused for an item (1), with an unedited removed file kept (3), with an edited removed file deleted (1); the render test fails with a promotion job whose if: names the environment (promote-production.yml: … 'production' != '').
  • The walk of the release notes: a scratch variant of update-released, not committed, with bare remotes; every step as written there passed.

🤖 Generated with Claude Code

davidjalbers and others added 15 commits December 6, 2026 10:32
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A template's manifest names under each, by source path, a variable of its
scope that holds a list; the file is rendered once per item with _item bound.
The environment files of a stack and the promotion workflow of each
environment are one file per declared environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a render is given the declaration

A newborn repo with a stack and no declaration passes the doctor: its stack is
born with no environment file. The stop-gap declaration of the two names the
stack template wrote is gone from newSite.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er is given the declaration

templateAnswers adds declared_environments, each environment's name, branch,
source and auto_promote, to the answers of every render plx makes (new, apply,
update, doctor): no template spells a branch. The stack template renders one
environment file per item, birth-only, so a newborn repo with a stack and no
declaration passes the doctor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
on_push runs on the branch of each declared environment, listed by name,
and on_commit on every other branch; a repo without a declaration has no
on_push. An environment that promotes itself gets a workflow that
fast-forwards its branch with plx promote after a green run on its source,
pushed with the App's token. The operations repo deploys the same way.
The newborns move off develop and declare their environments.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The renders that read on_push or deploy.yml declare an environment; the
pins and the held app pipeline are checked with and without one, the
triggers and the whole-history checkout left out of what is held.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
on_push of an app repo and deploy of an operations repo run on a push to
the branch of each declared environment, listed by name, and on no other;
on_commit runs on every other branch, main among them. A repo that
declares none has neither, and on_commit runs on every branch. The job
repo of on_push checks out the whole history with its tags. Each
environment that promotes itself has a workflow that runs plx promote
after a green run on its source and pushes as the tenant's App. The
operations repo deploys the environment of its branch, queued per branch.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt's branch

setup promote mints the App's token with contents and workflows write, so
that the promoting push starts the pipeline of the environment's branch.
A job deploy is refused off a declared environment's branch in whatever
workflow mounts it, the operations repo's deploy among them.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… branch in any workflow

setup promote mints the App's token with contents and workflows write for
the job that fast-forwards an environment's branch. The refusal of a run
on a branch that deploys nowhere covers a deploy job in whatever workflow
mounts it, so that a deploy started by hand on another branch or a tag
fails before any host is reached.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eclare

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The name given must be an environment of the root marker's declaration;
any other is refused before anything is read, naming those declared, and
a repo that declares none, or whose declaration is invalid, deploys
nowhere, with --environment as without.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plx of an earlier version hands the templates of the version a repo
takes the marker's answers alone; the templates then render as a repo
that declares no environment, rather than fail the update.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
So that the plx of an earlier version, which hands the templates of the
version a repo takes the answers alone, renders them as for a repo that
declares no environment instead of failing the update.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A repo taken by the plx of an earlier version, or declaring no
environment, has no on_push or deploy.yml after the update; one born
with a declaration keeps its workflow, moved to the version. A repo of
0.138.0 deploying from main and develop gets its environments' workflows
once it declares them and runs plx apply.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A repo that declares environments and has no stack fails the doctor's
check for a file of each, so the newborn whose verbs run declares none,
and the workflows are read from a second newborn that does.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidjalbers davidjalbers self-assigned this Dec 6, 2026
davidjalbers and others added 6 commits December 6, 2026 12:14
An item taken out of the list deletes its file, or keeps an edit to it as
a conflict; an item added adds one, a rename does both, and an emptied
list deletes every file. An item may name a path below the source's
directory, and one outside the output is refused.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ations it is rendered with

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The promotion workflow and the header of setup promote say that the head
of the source as it stands when the job runs is promoted, whichever run
started the job, and that a newer push's run promotes again; why the
App's token has workflows write; and why setup is handed the vault's
token where the repo holds no App credentials on the forge.

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s keeps the App's credentials there

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and that the token finds them

PLX-303

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidjalbers
davidjalbers merged commit 9bc10d9 into stacks-3 Dec 6, 2026
2 checks passed
@davidjalbers
davidjalbers deleted the davidjalbers/plx-303-workflows-rendered-from-the-declaration branch December 6, 2026 12:29
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