From e09c83bd60e410df6a19625d94e8880e75a877ae Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 20:09:58 +0000 Subject: [PATCH] =?UTF-8?q?CM8:=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), 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. ci.yml now declares workflow_dispatch with those inputs and a run-name that carries the deploy id, and plans a dispatch under the push-to-main binding filtered by --env and --component, so each component runs exactly as a merge runs it (stage and prod deploy, dev verifies). It needs nothing past the pinned orun v2.78.4. A dispatch off main is refused; the inputs are read from env and must be component names; a named component with nothing to run in the environment is left out with a notice, and a run left with nothing stays green with no lanes (Orunbase: nothing selected). The same change as sourceplane/turso-starter#15. testing/coverage.test.sh holds ci.yml to the contract; the product README and ai/context/operations.md say how to deploy by hand. Verified locally: the contract tests, the docs check, leak and placement. 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 c353e35..74d2440 100644 --- a/.baseline/product/README.md +++ b/.baseline/product/README.md @@ -149,6 +149,14 @@ apply — and the bucket names travel as Orun secrets; nothing provider-shaped is stored in the repository or in GitHub. Shopify's facts are Worker secrets, set once on the Workers themselves. +**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. + ## How it maps to Vercel | Vercel | Here | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e262a92..21e1451 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 5d9ccdc..b80c74b 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,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 (the R2 root planned for stage and prod, the storefront built and dry-deployed per environment; they neither lint nor run the tests, which `baseline.yml`'s e2e tier runs before every tag), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone runs and nothing waits for it (the landing checked its commit in the box); a merge applies the R2 bucket, 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 (the R2 root planned for stage and prod, the storefront built and dry-deployed per environment; they neither lint nor run the tests, which `baseline.yml`'s e2e tier runs before every tag), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone runs and nothing waits for it (the landing checked its commit in the box); a merge applies the R2 bucket, 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, dry-deployed, served, browsed and added to the cart | no | | `tag.yml` | cuts a `baseline-vN` tag (manual) | no | diff --git a/ai/context/operations.md b/ai/context/operations.md index f6d05e6..f61fb55 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -141,6 +141,7 @@ orun integrations list --org --json && orun cloud check --org | connect Shopify | the README's "Connecting Shopify": three Worker secrets per environment and the webhooks; no merge needed | | change the demo catalogue | `apps/web/lib/demo/catalogue.ts` and its images in `apps/web/public/demo`, merge | | 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 | | empty the data cache | revalidate through the webhook route (a `products/update` or `collections/update` topic), or delete the bucket's `incremental-cache/` objects | | add a binding (D1, KV, another bucket) | 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 67027c5..0903bd0 100755 --- a/testing/coverage.test.sh +++ b/testing/coverage.test.sh @@ -202,6 +202,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)