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 SITE_NAME seam in apps/web/app/site.ts (the upstream template's own heading, `Blog.`); `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. The upstream template's directory (`examples/cms-sanity` in Vercel's next.js repository) shares the slug and is protected from the rename.",
"slug": "cms-sanity",
"pascal": "CmsSanity",
"productName": "Blog.",
"domain": "cms-sanity.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
142 changes: 142 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# cms-sanity

A blog whose posts, authors and settings live in a [Sanity](https://www.sanity.io)
dataset — read over GROQ with `next-sanity`, with draft mode and live preview
through Sanity's Presentation tool, and the Sanity Studio embedded at
`/studio` — running on **Cloudflare Workers + Static Assets** through
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare). It is
Vercel's [Blog with Sanity CMS](https://github.com/vercel/next.js/tree/canary/examples/cms-sanity)
template, ported to Workers.

## 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 blog deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 02-docs:end -->

## Connecting Sanity

The blog deploys and serves before it has a Sanity project: until its build
is given a project id it shows a few **sample posts** bundled with it, under
a notice that says so, and `/studio` explains how to connect instead of
opening a Studio with nothing behind it. To make it read your content:

1. **Create a project** at [sanity.io/manage](https://www.sanity.io/manage)
(or `cd apps/web && pnpm run setup`, which runs `sanity init`). Note the
project id and the dataset — usually `production`.
2. **Give the build your project**, once per deployed environment. Both are
public values `next build` bakes in, stored as this repository's Orun
secrets so stage and prod can each name their own:

```bash
orun secrets set SANITY_PROJECT_ID --env stage # prompts for the value
orun secrets set SANITY_DATASET --env stage # optional: production when unset
orun secrets set SANITY_PROJECT_ID --env prod
orun secrets set SANITY_DATASET --env prod
```

Then **redeploy the blog**: a secret is read when the blog builds, and
setting one builds nothing. Change the stamp on the last line of
`apps/web/component.yaml` (`# orun: redeploy …`) and merge; the sample
posts and the notice are gone from that deploy on.
3. **Allow the site's origins** in the project (API → CORS origins):
`https://cms-sanity-web-stage.your-workers-subdomain.workers.dev`,
`https://cms-sanity-web-prod.your-workers-subdomain.workers.dev` and any
custom domain, each **with credentials allowed** — the Studio signs in
from them.
4. **Add a read token for draft mode** (optional; published posts need
none). Create a Viewer token (API → Tokens) and store it as a Worker
secret in each environment — Cloudflare's, so deploys leave it alone:

```bash
pnpm --filter @app/web exec wrangler secret put SANITY_API_READ_TOKEN --name cms-sanity-web-stage
pnpm --filter @app/web exec wrangler secret put SANITY_API_READ_TOKEN --name cms-sanity-web-prod
```

Without it the Studio's live preview is refused (the draft-mode route
answers 401 and says why); everything else works.

Then write at `/studio`. Published changes show on the blog within a minute
(Sanity's API CDN cache) — no deploy.

## What is here

| Surface | Where |
|---|---|
| Home, `/posts/[slug]`, the draft-mode banner and action | `apps/web/app/(blog)` |
| The Studio at `/studio` | `apps/web/app/(sanity)`, `apps/web/sanity.config.ts` |
| Draft mode enable route | `apps/web/app/api/draft-mode/enable/route.ts` |
| Client, queries, `sanityFetch`, image URLs | `apps/web/sanity/lib` |
| The sample posts an unconnected blog shows | `apps/web/sanity/lib/sample.ts` |
| Schemas, Studio plugins, generated types | `apps/web/sanity/schemas`, `apps/web/sanity/plugins`, `apps/web/sanity.types.ts` |
| The blog's name until its Settings document gives one | `apps/web/app/site.ts` |
| Workers build and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.jsonc`, `component.yaml` |
| Tests | `tests/web` (vitest) |

## Getting started

```bash
pnpm install
pnpm typecheck
pnpm lint
pnpm test
pnpm build # typegen + next build + opennextjs-cloudflare build → apps/web/.open-next
```

That needs no Sanity project (Checks runs exactly this). With one:

```bash
cd apps/web
cp .env.example .env.local # NEXT_PUBLIC_SANITY_PROJECT_ID, NEXT_PUBLIC_SANITY_DATASET, SANITY_API_READ_TOKEN
cd ../..
pnpm --filter @app/web dev # http://localhost:3000, the Studio at /studio
```

For the Worker locally, the project id and dataset are read at build time
and the token is a Worker secret:

```bash
cd apps/web
cp .dev.vars.example .dev.vars # SANITY_API_READ_TOKEN=<a Viewer token>
NEXT_PUBLIC_SANITY_PROJECT_ID=<id> NEXT_PUBLIC_SANITY_DATASET=<dataset> pnpm build
pnpm preview # wrangler dev over the built Worker
```

| Variable | Read | What it does |
|---|---|---|
| `NEXT_PUBLIC_SANITY_PROJECT_ID` | build time | The Sanity project. Deployed builds take it from the `SANITY_PROJECT_ID` secret of their environment. Unset, the blog is unconnected: sample posts and a notice. |
| `NEXT_PUBLIC_SANITY_DATASET` | build time | The dataset (`SANITY_DATASET`); `production` when unset. |
| `SANITY_API_READ_TOKEN` | request time, in the Worker | A Viewer token for draft mode and live preview. Optional. |
| `NEXT_PUBLIC_CF_BEACON_TOKEN` | build time | Optional Cloudflare Web Analytics token. Unset, no script is rendered. |

## 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 blog builds once per
environment, with that environment's Sanity project, and deploys — to
`stage`, then to `prod` once stage has converged on the same commit; `dev`
only verifies. The Worker is `cms-sanity-web-<env>` on your account's
workers.dev subdomain, and every deploy is smoke-tested over HTTP: the home
page must render and the draft-mode route must refuse a request without a
preview secret. `checks.yml` runs install, typecheck, lint, test and build
on every pull request. (A push to `main` runs `ci.yml` alone, which builds
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.

## Custom domain

The blog answers on workers.dev from its first deploy. To serve it on your
own domain, add the domain to the Cloudflare account the blog deploys into
and attach it to the Worker (dashboard → Workers & Pages →
`cms-sanity-web-prod` → Settings → Domains & Routes → Add → Custom domain),
then add it to the Sanity project's CORS origins. Nothing in the repository
changes: the blog renders no absolute link to itself.
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 blog 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 blog's repository is born and linked, the whole blog lands in one pull request, and one convergence deploys it to stage and prod — serving its sample posts until a Sanity project is connected
affects:
- web
- web-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked
- main convergence green (build, deploy and smoke on stage and prod)
- the blog answers 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 blog'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: []
136 changes: 136 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
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 the one product phase,
# that a placed tree comes up branded and carrying nothing of the factory —
# and plans the blog onto stage and prod on a merge — and that the blog it
# produces installs, builds, deploys (dry) and serves with no Sanity project
# behind it.
#
# ─── WHY THIS IS NOT IN ci.yml OR checks.yml ──────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory into every blog built from this repository. These jobs run
# `testing/*.sh`, and `testing/` is deliberately not placed — so in a blog 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 blog'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 a product would carry, derived by the
# floor too), and the placement tier (the offline bootstrap: both phases
# placed and finished by the blueprint's own hooks, then the product's own
# `orun plan` for the 01-product merge, under the product's lane pin,
# below).
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-blog \
--set "productname=Acme Blog" \
--set productdomain=acme.dev \
--set githuborg=acme-inc
- name: the leak gate — what a product carries
run: bash testing/leak.test.sh
# The placement tier ENDS with the product's own `orun plan` — what the
# product's ci.yml runs — so it runs under the product's lane pin, not
# the bootstrap floor: the plan a convergence waits on is the lane
# pin's (its optional secret refs included), and the test refuses an
# orun older than the pin rather than assert the wrong CLI's plan. Its
# placements are valid under either.
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.78.4
- name: placement — the offline bootstrap, and the product'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 BLOG IT PRODUCES WORKS, WITH NO SANITY PROJECT: its one
# landing under the checks its pull request waits on, the stage lane's own
# structure check, build, output check and dry deploy in the tree orun
# stages, and the built Worker served and smoke-tested with the component's
# own smoke command — the sample posts, the "connect your Sanity project"
# notice, the Studio's connect page and draft mode's refusal. Pinned at the
# product's lane version, because that is the orun the product's CI runs.
blog:
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 blog 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
24 changes: 18 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 blog converged. On main the convergence builds and tests the blog
# 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 All @@ -33,6 +40,11 @@ jobs:
# Templated deployables render their wrangler config from the committed
# fixture; an unresolved wiring token fails here, not at deploy time.
- run: pnpm run wire:fixture
# …and the render is what is committed. The deploy lane checks that the
# config exists before it builds, so wrangler.jsonc is in the tree as the
# fixture render; a template edited without re-rendering fails here.
- name: the committed wrangler config is the fixture render
run: git diff --exit-code
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm test
Expand Down
Loading
Loading