From d892207ac27cf81d364f84c75e7f07c746df05de Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 20:04:48 +0000 Subject: [PATCH] =?UTF-8?q?TU13:=20a=20product=20deploys=20by=20hand=20?= =?UTF-8?q?=E2=80=94=20Orunbase's=20Deploy=20button=20and=20Run=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Orunbase's Run and Deploy buttons dispatch a product's ci.yml on main with inputs component, environment and deploy_id (the deploys contract, DEPLOY_WORKFLOW in orun-cloud), and find the run by the deploy id in its name. ci.yml declared no workflow_dispatch, so GitHub refused every dispatch and the buttons were dead; a redeploy with nothing changed meant editing a redeploy marker and merging. ci.yml now: - declares workflow_dispatch with those three inputs (environment a choice of intent.yaml's environments, component optional: blank is every component) and a run-name that carries the deploy id; - plans a dispatch under the push-to-main binding, filtered with --env and --component, so each component runs exactly as a merge runs it (stage and prod apply and deploy, dev verifies). This needs nothing past the pinned orun v2.78.4: `orun plan --trigger github-push-main` gives the same plan as a push to main (same checksum on this tree), and --env / --component filter it; - refuses a dispatch started off main (that binding deploys stage and prod), reads the inputs from env and rejects anything that is not a component name, so nothing from the form reaches the shell; - leaves out, with a notice, a named component with nothing to run in the environment (orun refuses it as unmatched: a test suite in prod); a run left with nothing stays green with no lanes, which Orunbase reads as nothing selected. testing/coverage.test.sh holds ci.yml to the contract (the three inputs, the environment options equal to intent.yaml's, the deploy id in the run name, the push-main plan on dispatch, the main-only guard, the inputs read from env); each assertion was mutation-checked. The product README, the repository README's workflow table and ai/context/operations.md say how. Verified: the plan step run for real against this tree with orun v2.78.4 — stage web,db-migrate (both, in order), prod with no component (d1, migrate, site), prod web-tests (left out, green, no lanes), prod web,web-tests (web only), dev web (verify), a feature branch (refused), an injection attempt (refused), a push (unchanged: 10 jobs). Contract tests, docs check, leak and placement pass. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CJuLwDKfEaQGAEuBpJvN5Q --- .baseline/product/README.md | 8 +++ .github/workflows/ci.yml | 103 +++++++++++++++++++++++++++++++++--- README.md | 2 +- ai/context/operations.md | 1 + testing/coverage.test.sh | 47 ++++++++++++++++ 5 files changed, 152 insertions(+), 9 deletions(-) diff --git a/.baseline/product/README.md b/.baseline/product/README.md index cf96b15..d1b1785 100644 --- a/.baseline/product/README.md +++ b/.baseline/product/README.md @@ -89,6 +89,14 @@ brokered per run from the workspace's Cloudflare connection, and the database ids travel as Orun secrets; nothing provider-shaped is stored in the repository or in GitHub. +**Deploy by hand.** Orunbase's **Deploy** button on a component, or **Run +workflow** on the CI workflow in GitHub's Actions tab (on `main`), runs +`ci.yml` for the environment and components you pick, and each one deploys +exactly as a merge would deploy it. Leave the component blank to redeploy +every component in that environment, with nothing changed: after rotating a +secret, say. A component with nothing to run in that environment (a test +suite in `prod`) is left out with a notice. + ## Custom domain The site answers on workers.dev from its first deploy. To serve it on your diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e048ba..bbb5737 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,36 @@ on: push: branches: [main] pull_request: + # A MANUAL RUN. Orunbase's Run and Deploy buttons start this workflow on + # main with component names, an environment and the deploy record's id + # (the deploys contract: ci.yml on main; inputs component, environment, + # deploy_id); "Run workflow" in the Actions tab does the same by hand. The + # plan step plans those components in that environment under the + # push-to-main trigger, so each one runs exactly as a merge runs it: stage + # and prod apply and deploy, dev verifies. An empty `component` means + # every component in the environment, a redeploy with nothing changed. + workflow_dispatch: + inputs: + component: + description: "Component names, comma-separated (component.yaml metadata.name); empty for every component" + required: false + type: string + default: "" + environment: + description: "Target environment" + required: true + type: choice + options: [dev, stage, prod] + deploy_id: + description: "Orunbase deploy record (dpl_…), set by Orunbase; appears in the run name" + required: false + type: string + default: "" + +# A manual run names itself after what it runs: Orunbase finds a deploy's run +# by the id in this name (GitHub's dispatch API returns no run id). Every +# other event keeps GitHub's default name (an empty run-name falls back to it). +run-name: ${{ github.event_name == 'workflow_dispatch' && format('Deploy {0} → {1} · {2}', inputs.component || 'every component', inputs.environment, inputs.deploy_id || 'by hand') || '' }} # PR runs share a group per ref and superseded runs are cancelled (each # push re-plans anyway), which stops stale fan-outs from starving the @@ -61,18 +91,75 @@ jobs: # A successful push prints "✓ pushed catalog …"; ORUN_VERBOSE also makes # any skip/failure visible instead of silent. ORUN_VERBOSE: "1" + # A manual run's selection, read from the environment, never + # interpolated into the script. + DISPATCH_COMPONENT: ${{ inputs.component }} + DISPATCH_ENVIRONMENT: ${{ inputs.environment }} run: | set -euo pipefail - plan_args=( - --from-ci github - --event-file "$GITHUB_EVENT_PATH" - --intent intent.yaml - --output plan.json - --changed - ) + if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then + # A MANUAL RUN plans under the push-to-main trigger: the profiles + # a merge runs, filtered to the environment and the components it + # names. Not --changed: a redeploy is asked for when nothing has + # changed. Main only, because that trigger deploys stage and prod. + if [ "$GITHUB_REF" != "refs/heads/main" ]; then + echo "::error title=Orun CI::A manual run deploys main only; this one was started on ${GITHUB_REF}." + exit 1 + fi + plan_args=( + --trigger github-push-main + --env "$DISPATCH_ENVIRONMENT" + --intent intent.yaml + --output plan.json + ) + if [ -n "${DISPATCH_COMPONENT//[[:space:],]/}" ]; then + # Keep the named components that have something to run in this + # environment. orun refuses the others as unmatched (a test + # suite has no job in prod), and a run of only those is nothing + # selected, not a failure: it stays green with no lanes, which + # Orunbase reads as nothing selected. + orun plan --trigger github-push-main --env "$DISPATCH_ENVIRONMENT" \ + --intent intent.yaml --output env-plan.json --no-catalog-refresh >/dev/null + kept=0 + IFS=',' read -ra picked <<< "$DISPATCH_COMPONENT" + for c in "${picked[@]}"; do + c="${c//[[:space:]]/}" + [ -z "$c" ] && continue + if ! [[ "$c" =~ ^[a-z0-9][a-z0-9._-]{0,99}$ ]]; then + echo "::error title=Orun CI::'$c' is not a component name (component.yaml metadata.name)." + exit 1 + fi + if jq -e --arg c "$c" 'any(.jobs[]; .component == $c)' env-plan.json >/dev/null; then + plan_args+=(--component "$c") + kept=$((kept + 1)) + else + echo "::notice title=Orun CI::$c has nothing to run in ${DISPATCH_ENVIRONMENT} (or is not a component); left out." + fi + done + if [ "$kept" = 0 ]; then + jq '.jobs = [] | .lanes = []' env-plan.json > plan.json + plan_args=() + fi + fi + else + plan_args=( + --from-ci github + --event-file "$GITHUB_EVENT_PATH" + --intent intent.yaml + --output plan.json + --changed + ) + fi + + if [ "${#plan_args[@]}" -gt 0 ]; then + orun plan "${plan_args[@]}" + fi - orun plan "${plan_args[@]}" + # A manual run that selects nothing runs nothing, and says so. + if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ] && [ "$(jq '.jobs | length' plan.json)" = 0 ]; then + echo "::notice title=Orun CI::Nothing to run for ${DISPATCH_COMPONENT:-every component} in ${DISPATCH_ENVIRONMENT}." + fi # One matrix entry per LANE (execution.lanes in intent.yaml). A plan # without lanes gets one per job, exactly the old matrix, and # `orun run --lane ` on it is `--job `. diff --git a/README.md b/README.md index 5f2df08..d51dd2a 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,6 @@ if the two disagree. | Workflow | What it runs | Ships to a product | |---|---|---| -| `ci.yml` | the Orun pipeline, and the only workflow a product carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (packages type-checked, linted, tested and built, both test suites, the site built and dry-deployed per environment), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone is the check; a merge applies the D1 database, migrates it, then deploys stage → prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does | yes | +| `ci.yml` | the Orun pipeline, and the only workflow a product carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (packages type-checked, linted, tested and built, both test suites, the site built and dry-deployed per environment), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone is the check; a merge applies the D1 database, migrates it, then deploys stage → prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run (Orunbase's Deploy button, or Run workflow on `main`) plans the environment and components it names under the push-to-main trigger, so they deploy as a merge deploys them | yes | | `baseline.yml` | the baseline's own tiers: contract tests, the wiring path, the blueprint read by the pinned orun, the leak gate, the offline bootstrap with the product's own plan, the product built in the job tree, migrated, dry-deployed and served | no | | `tag.yml` | cuts a `baseline-vN` tag (manual) | no | diff --git a/ai/context/operations.md b/ai/context/operations.md index 4891fa5..ed735a1 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -132,6 +132,7 @@ orun integrations list --org --json && orun cloud check --org | change the schema | add `packages/db/src/migrations/_/up.sql` (idempotent: `IF NOT EXISTS`), list it in `src/manifest.ts`, `pnpm --filter @saas/db run manifest:fix`, merge — db-migrate applies it before the site redeploys | | try the schema locally | `pnpm --filter @app/web db:migrate:local` applies every migration to wrangler's local D1 | | deploy a change | merge to `main`; watch the run; failed lanes → `gh run rerun --failed` | +| deploy by hand | Orunbase's Deploy button, or `gh workflow run ci.yml --ref main -f environment= [-f component=]` — the named components (blank: every one) run in that environment as a merge runs them; started off `main` it is refused | | redeploy without a change | edit the last line of `apps/web/component.yaml` (`# orun: redeploy `) and merge — it is a deploy trigger, nothing reads it | | query a live database | `wrangler d1 execute --remote --command "SELECT count(*) FROM todos"` (the name is in the environment's `WIRING_CLOUDFLARE_D1`) | | add a binding (R2, KV, another D1) | a Terraform root under `infra/terraform/` that publishes `WIRING_`, a token in `wrangler.template.jsonc`, its fixture entry, the root in the build's `--components`, the `WIRING__` secretEnv and an enforced `dependsOn` on it in `apps/web/component.yaml` | diff --git a/testing/coverage.test.sh b/testing/coverage.test.sh index aa0abb8..3221b37 100755 --- a/testing/coverage.test.sh +++ b/testing/coverage.test.sh @@ -201,6 +201,53 @@ if on_push != ["ci.yml"]: f"it must be exactly ci.yml — orun.run/watch@v1 watches the newest run " f"for a commit from ANY workflow, so a second one hides the convergence") +# A MANUAL RUN (the deploys contract, packages/contracts DEPLOY_WORKFLOW in +# orun-cloud). Orunbase's Run and Deploy buttons dispatch ci.yml on main with +# inputs component, environment and deploy_id, then find the run by the deploy +# id in its name; GitHub refuses a dispatch whose inputs the workflow does not +# declare (422), so a product without them has dead buttons. The plan step +# must plan a dispatch under the push-to-main binding (what a merge deploys), +# on main only, and read the inputs from env, never interpolate them. +import yaml as _ydisp +_ci_path = root / ".github" / "workflows" / "ci.yml" +_ci = _ydisp.safe_load(_ci_path.read_text(encoding="utf-8")) or {} +_on = _ci.get("on", _ci.get(True)) or {} +_wd = _on.get("workflow_dispatch") if isinstance(_on, dict) else None +_inputs = (_wd or {}).get("inputs") or {} +if set(_inputs) != {"component", "environment", "deploy_id"}: + bad(f"ci.yml's workflow_dispatch declares inputs {sorted(_inputs) or 'none'}; Orunbase " + f"dispatches component, environment and deploy_id, and GitHub refuses unknown inputs") +else: + _intent = _ydisp.safe_load((root / "intent.yaml").read_text(encoding="utf-8")) or {} + _envs = set((_intent.get("environments") or {}).keys()) + _opts = set(_inputs["environment"].get("options") or []) + if _inputs["environment"].get("type") != "choice" or _opts != _envs: + bad(f"ci.yml's environment input offers {sorted(_opts)}; intent.yaml declares {sorted(_envs)}") + if "github-push-main" not in ((_intent.get("automation") or {}).get("triggerBindings") or {}): + bad("a manual run plans under intent.yaml's github-push-main binding, which is missing") +if "inputs.deploy_id" not in str(_ci.get("run-name", "")): + bad("ci.yml's run-name must carry inputs.deploy_id: Orunbase finds a deploy's run by that id") +_steps = (_ci.get("jobs") or {}).get("plan", {}).get("steps") or [] +_plan_step = next((s for s in _steps if "plan_args" in str(s.get("run", ""))), None) +if _plan_step is None: + bad("ci.yml's plan job has no step that builds plan_args") +else: + _run = _plan_step["run"] + for _needle, _why in ( + ('"$GITHUB_EVENT_NAME" = "workflow_dispatch"', "plans a dispatch on its own branch"), + ("--trigger github-push-main", "plans a dispatch as a merge to main"), + ('"$GITHUB_REF" != "refs/heads/main"', "refuses a dispatch started off main"), + ('--env "$DISPATCH_ENVIRONMENT"', "filters a dispatch to its environment"), + ): + if _needle not in _run: + bad(f"ci.yml's plan step no longer {_why} ({_needle!r} is gone)") + if "${{" in _run and "inputs." in _run: + bad("ci.yml's plan step interpolates inputs.* into its script; read them from env") + _env = _plan_step.get("env") or {} + if "inputs.component" not in str(_env.get("DISPATCH_COMPONENT", "")) \ + or "inputs.environment" not in str(_env.get("DISPATCH_ENVIRONMENT", "")): + bad("ci.yml's plan step must take DISPATCH_COMPONENT / DISPATCH_ENVIRONMENT from inputs in env") + if problems: print("FAIL: the blueprint and this repository disagree about what a product is:", file=sys.stderr)