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
9 changes: 9 additions & 0 deletions .baseline/identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_comment": "THIS TREE'S OWN IDENTITY — the FROM side of every rebrand. tooling/rebrand/rebrand.mjs reads it to know what to rename AWAY from; a product's identity is the --values file, which is the TO side. Change a value here only together with the tree: these strings must be what the tree actually contains, or the rename silently misses and the product ships carrying this baseline's name. `productName` is the API_NAME seam in apps/api/src/identity.ts; `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner in the source links the docs carry.",
"slug": "hono-api",
"pascal": "HonoApi",
"productName": "Hono API",
"domain": "hono-api.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
102 changes: 102 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# hono-api

A [Hono](https://hono.dev) API on one **Cloudflare Worker**. Hono's `fetch`
handler is the Worker's — no adapter, no framework build: wrangler bundles
`apps/api/src/index.ts` and Cloudflare runs it. Every merge to `main` deploys
it to stage, then prod.

## Live deployment

<!-- 02-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace and the secrets inventory into
[ai/context/deployment.md](ai/context/deployment.md); how the API deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 02-docs:end -->

## Routes

| Route | Answers |
|---|---|
| `GET /` | the welcome text (`Hello Hono!` and a pointer to Hono's Workers guide) |
| `GET /health` | `{"status":"ok","name":"<API_NAME>","environment":"<env>"}` — what the deploy's smoke and an operator's probe read |
| anything else | `404 Not Found` |

## What is here

| Surface | Where |
|---|---|
| The routes | `apps/api/src/index.ts` |
| The API's name (what `/health` answers with) | `apps/api/src/identity.ts` |
| Worker config (name, compatibility date, per-environment vars) | `apps/api/wrangler.jsonc` |
| Deploy contract | `apps/api/component.yaml` (`cloudflare-worker-turbo`) |
| Tests | `tests/api` (vitest, drives the app in-process with `app.request()`) |

## Getting started

```bash
pnpm install
pnpm typecheck
pnpm lint
pnpm test
pnpm build # wrangler deploy --dry-run → apps/api/dist (the bundle, no upload)
```

Run the Worker locally under workerd and call it:

```bash
pnpm --filter @app/api dev # http://localhost:8787
curl http://localhost:8787/ # Hello Hono! …
curl http://localhost:8787/health # {"status":"ok",…,"environment":"local"}
```

Add a route with `app.get(...)` (or `post`, `route`, middleware) in
`apps/api/src/index.ts`; `wrangler dev` reloads on save. Keep `/health`: the
deploy's smoke reads it.

## How it deploys

Merges to `main` converge through [Orun](https://github.com/sourceplane/orun):
`.github/workflows/ci.yml` plans the changed components and runs each lane
against the workspace in `intent.yaml`. The API deploys to `stage`, then to
`prod` once stage has converged on the same commit; `dev` only verifies. The
Worker is `hono-api-api-<env>` on your account's workers.dev subdomain, and
every deploy is smoke-tested over HTTP: `/health` must answer `"status":"ok"`
for that environment. `checks.yml` runs install, typecheck, lint, test and
build on every pull request. (A push to `main` runs `ci.yml` alone, which
builds, tests and deploys.)

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. The
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.

## Adding a binding or a secret

The Worker binds nothing today, so `wrangler.jsonc` is committed as it
deploys. To give it a KV namespace, a D1 database or an R2 bucket, add the
resource under `infra/` as its own component and have `apps/api/component.yaml`
depend on it; `tooling/wire/` renders a wrangler template from the ids that
component publishes. A runtime secret (an API key for a service the API
calls) is an Orun secret: `orun secrets set <KEY> --org <ws> --env <env>`,
declared in the component's `optionalSecretEnv` and named in its
`runtimeSecrets`, then pushed to the Worker after each deploy. Until it is
set, the route that needs it should say so rather than fail.

## Custom domain

The API answers on workers.dev from its first deploy. To serve it on your own
domain, add the domain to the Cloudflare account the API deploys into and
attach it to the Worker (dashboard → Workers & Pages → `hono-api-api-prod` →
Settings → Domains & Routes → Add → Custom domain); do the same for stage
with a subdomain if you want one. The workers.dev URL keeps answering, and the
deploy's smoke keeps reading it — unless the environment sets `DEPLOYED_URL`
in `intent.yaml`, which the smoke reads instead:

```yaml
environments:
prod:
env:
DEPLOYED_URL: https://hono-api.example.com
```
23 changes: 23 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Task contract template for the 01-product landing — the whole API in one
# pull request. Unbound to a key on purpose: `orun.task/ensure@v1` seals and
# attaches it to the key the allocator issues. It lives under `.baseline/`,
# not `tasks/`, because `tasks/` is this repository's own work tree
# (`intent.yaml` `work:`), where an unkeyed contract is an error. gates: [] is
# a DECLARATION — merge alone finishes this task; the main convergence is the
# gate the bootstrap watches, not one the plane observes as a PR check.
#
# `affects` names COMPONENTS, by metadata.name: the phase's retouch hook reads
# this list to decide which component.yaml files get the redeploy marker, so
# the deploy set and the task plane's statement of the work are one list.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The API's repository is born and linked, the whole API lands in one pull request, and one convergence deploys it to stage and prod
affects:
- api
- api-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked
- main convergence green (build, deploy and smoke on stage and prod)
- /health answers 200 on both workers.dev URLs
gates: []
13 changes: 13 additions & 0 deletions .baseline/tasks/02-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Task contract template for the 02-docs landing. See 01-product's header.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The live deployment is recorded from verified facts as agent-readable state in the API's repo
affects:
- ai/context/deployment.md
- ai/context/operations.md
- README.md
doneWhen:
- committed deployment manifest matches probed reality
- prod waits on stage again, and dev verifies every merge to main again
gates: []
124 changes: 124 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Baseline CI

# THE FACTORY'S OWN LANES — this repository tested as a BASELINE: that its
# build document parses with the orun a bootstrap actually runs, that its card
# agrees with it, that every component is placed by exactly one phase, that a
# placed tree comes up branded and carrying nothing of the factory, and that
# the API it produces installs, builds, deploys (dry) and serves.
#
# ─── WHY THIS IS NOT IN ci.yml OR checks.yml ──────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory into every API built from this repository. These jobs run
# `testing/*.sh`, and `testing/` is deliberately not placed — so in a product
# they would be steps that cannot pass, red on its very first pull request. This
# file is in the blueprint's `ignore` list, and `testing/coverage.test.sh`
# fails on any workflow that reads `testing/` and is not.

on:
push:
branches: [main]
pull_request:

concurrency:
group: baseline-ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
# Tier 0. bash, python3 and git; node for the tools. No workspace install,
# no network, no credential — the job that most certainly fails a PR.
baseline-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v5
with:
node-version: 22
# setup-node v5 turns on the pnpm cache by itself when package.json
# names a packageManager, and then fails on a runner with no pnpm.
# This job installs nothing.
package-manager-cache: false
- name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer)
run: |
set -euo pipefail
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
for t in manifest phases coverage rebrand retouch bootstrap-defer; do
echo "── $t"
bash "testing/$t.test.sh"
done

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
# Pinned at the bootstrap floor (BOOTSTRAP.md), not the API's lane pin:
# every test here reads YAML with PyYAML, which parses anything well-formed;
# only the pinned orun can say whether the document is one a bootstrap can
# run. `--status` parses it, validates every hook against the action
# registry, compiles every `when` and narration template, and writes
# nothing. Then the leak gate (what an API would carry, and what its files
# say) and the placement tier (the offline bootstrap: both phases placed and
# finished by the blueprint's own hooks, then the API's own `orun plan` for
# the push that merges 01-product).
blueprint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.58.11
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
- name: repo-blueprint.yaml, read by the pinned CLI
run: |
set -euo pipefail
orun --version
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
# Required inputs must be supplied for the document to resolve; the
# values are arbitrary and nothing is written.
orun new --blueprint repo-blueprint.yaml --status \
--out "$(mktemp -d)" \
--set reponame=acme-api \
--set "productname=Acme API" \
--set productdomain=acme.dev \
--set githuborg=acme-inc
- name: the leak gate — what an API carries
run: bash testing/leak.test.sh
- name: placement — the offline bootstrap, and the API's own plan
run: |
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/placement.test.sh

# Tier 2. THE API IT PRODUCES WORKS: both landings under the checks their
# pull requests wait on, every run step of the stage lane's pull-request
# plan (the structure check before any build, the build, the typecheck, the
# dry deploy) in the job tree orun stages, and the Worker served by
# `wrangler dev --env stage` and smoke-tested with the component's own smoke
# command. Pinned at the API's lane version, because that is the orun the
# API's CI runs.
api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: e2e — the bootstrapped API builds, deploys (dry) and serves
run: |
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/e2e.test.sh
19 changes: 13 additions & 6 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
name: Checks

# Credential-free verification: install, render the offline wrangler fixtures,
# typecheck, lint, test and build. Runs on every push and pull request and is
# the merge gate until the product is linked to an Orun workspace, at which
# point `ci.yml` (Orun plan/run with brokered Cloudflare credentials) takes
# over — it stays gated behind the `ORUN_CI` repository variable until then.
# typecheck, lint, test and build, on every pull request, linked or not.
# `ci.yml` is the Orun pipeline beside it (plan/run with brokered Cloudflare
# credentials, deploys on merge); it plans nothing until intent.yaml names a
# workspace.
#
# PULL REQUESTS ONLY — not pushes to main. A push to main must start exactly
# one workflow, `ci.yml`, because the bootstrap's convergence watch
# (`orun.run/watch@v1` with `sha:`) takes the newest run for the merge commit
# from ANY workflow. With this one on push too, the first live bootstrap
# watched this run go green while ci.yml's deploy lanes had failed, and called
# the product converged. On main the convergence builds and tests the API
# anyway. The baseline's coverage gate holds the rule.
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

concurrency:
group: checks-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
Expand Down
40 changes: 31 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,38 @@ permissions:

jobs:
plan:
if: ${{ vars.ORUN_CI == 'true' }}
runs-on: ubuntu-latest
outputs:
lane-matrix: ${{ steps.matrix.outputs.lane-matrix }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: sourceplane/orun-action@v1.2.0
# A TREE THAT NAMES NO WORKSPACE PLANS NOTHING. `ws_CHANGE_ME` is the
# placeholder this repository ships with until someone links it; every
# remote op of a plan here would be refused, so the job says so and
# stops green, and `run` below has no lanes to start. A product built by
# an Orun bootstrap never carries the placeholder — the bootstrap writes
# the product's own workspace into intent.yaml — and a bootstrap that had no
# workspace to write leaves `ws_SET_ME`, which is NOT skipped: it fails
# here loudly rather than deploying nothing in silence.
#
# This replaced an `ORUN_CI` repository variable, which a bootstrap has
# no way to set: every product it built would have converged on nothing.
- id: linked
run: |
if grep -Eq '^[[:space:]]*workspace:[[:space:]]*ws_CHANGE_ME[[:space:]]*$' intent.yaml; then
echo "::notice title=Orun CI::intent.yaml names no Orun workspace (ws_CHANGE_ME) — nothing to plan. Link this repository (orun cloud link) and set execution.state.workspace to turn the pipeline on."
echo "linked=false" >> "$GITHUB_OUTPUT"
else
echo "linked=true" >> "$GITHUB_OUTPUT"
fi
- if: steps.linked.outputs.linked == 'true'
uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.0
- env:
version: v2.78.4
- if: steps.linked.outputs.linked == 'true'
env:
# Surface the best-effort catalog auto-sync (execution.state.autopushCatalog).
# A successful push prints "✓ pushed catalog …"; ORUN_VERBOSE also makes
# any skip/failure visible instead of silent.
Expand All @@ -57,20 +77,22 @@ jobs:
# without lanes gets one per job, exactly the old matrix, and
# `orun run --lane <job id>` on it is `--job <job id>`.
- id: matrix
if: steps.linked.outputs.linked == 'true'
run: |
echo "lane-matrix=$(jq -c 'if ((.lanes // []) | length) > 0
then [.lanes[] | {"lane": .id, "name": .name}]
else [.jobs[] | {"lane": .id, "name": .checkName}] end' plan.json)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v7
- if: steps.linked.outputs.linked == 'true'
uses: actions/upload-artifact@v7
with:
name: orun-plan
path: plan.json

run:
needs: plan
runs-on: ubuntu-latest
# A BOOTSTRAP LANDING IS CHECKED BY `plan` ALONE. Every phase of the
# baseline bootstrap lands on a branch named for its task — the provenance
# A BOOTSTRAP LANDING IS CHECKED BY `plan` ALONE. Every phase of an Orun
# bootstrap lands on a branch named for its task — the provenance
# pen's `orun/<KEY>-<slug>`, and the bootstrap's tasks are all `BASE-n` —
# and is merged by `orun.pr/land@v1` as soon as this workflow is green.
# On those pull requests `plan` above is the check: the intent, every
Expand Down Expand Up @@ -124,7 +146,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.0
version: v2.78.4
# exec-id is the RUN id alone (no attempt suffix): a `gh run rerun
# --failed` then RESUMES the same orun execution — jobs that succeeded in
# a prior attempt stay completed, so re-run lanes' cross-job dependencies
Expand Down Expand Up @@ -174,7 +196,7 @@ jobs:
env:
# GITHUB_TOKEN is the only credential CI holds — GitHub-issued and
# ephemeral. Every provider credential (the Cloudflare token and
# account id — this baseline has no second provider) is an
# account id — this product has no second provider) is an
# orun-managed secret:
# brokered fresh per run from the workspace's integrations, resolved
# lease-bound by the jobs that declare it (profile secretBindings or
Expand Down
Loading
Loading