diff --git a/.baseline/product/README.md b/.baseline/product/README.md index 09db5e2..98eb860 100644 --- a/.baseline/product/README.md +++ b/.baseline/product/README.md @@ -74,6 +74,14 @@ Cloudflare token and account id are brokered per run from the workspace's Cloudflare connection; 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 fa13742..8d1565b 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 1061e3e..fd29309 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,6 @@ Analytics beacon (stands in for the Vercel adapter's web analytics). | Workflow | What it runs | Ships to a site | |---|---|---| -| `ci.yml` | the Orun pipeline, and the only workflow a site carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the site built and dry-deployed per environment — they do not type-check, lint or run the tests; `baseline.yml`'s e2e tier runs those before each tag, and a site's README asks its developers to run them before a push), except the bootstrap's own landings (`orun/BASE-*`), which are checked in the box before they are pushed (`checks: local`) and whose PR runs `plan` alone; a merge 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 site carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the site built and dry-deployed per environment — they do not type-check, lint or run the tests; `baseline.yml`'s e2e tier runs those before each tag, and a site's README asks its developers to run them before a push), except the bootstrap's own landings (`orun/BASE-*`), which are checked in the box before they are pushed (`checks: local`) and whose PR runs `plan` alone; a merge 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 blueprint read by the pinned orun, the leak gate, the offline bootstrap, the site built, 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 7a45930..c2910c3 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -94,6 +94,7 @@ orun integrations list --org --json && orun cloud check --org |---|---| | add a page | add `apps/web/src/pages/.astro` (`export const prerender = true` to build it as a static asset), 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 | | serve a custom domain | attach it to the Worker in Cloudflare; set `SITE_URL` for the environment in `intent.yaml` so the deployment record probes it, and replace the placeholder `astro-boilerplate.example.com` in `intent.yaml`'s `BASE_DOMAIN` (dev, stage and prod) with it (README, "Custom domain") | | cache `/ssr-with-swr-caching` at the edge | a Cloudflare Cache Rule for the route; the page already sends `s-maxage` and `stale-while-revalidate` | diff --git a/testing/coverage.test.sh b/testing/coverage.test.sh index cb0b4f3..6ecab23 100755 --- a/testing/coverage.test.sh +++ b/testing/coverage.test.sh @@ -203,6 +203,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)