Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
103 changes: 95 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <job id>` on it is `--job <job id>`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
1 change: 1 addition & 0 deletions ai/context/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ orun integrations list --org <ws> --json && orun cloud check --org <ws>
| change the schema | add `packages/db/src/migrations/<NNN>_<name>/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=<env> [-f component=<a,b>]` — 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 <reason> <stamp>`) and merge — it is a deploy trigger, nothing reads it |
| query a live database | `wrangler d1 execute <name> --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_<ROOT>`, a token in `wrangler.template.jsonc`, its fixture entry, the root in the build's `--components`, the `WIRING_<ROOT>_<ENV>` secretEnv and an enforced `dependsOn` on it in `apps/web/component.yaml` |
Expand Down
47 changes: 47 additions & 0 deletions testing/coverage.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading