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 name, `Simple 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 links (microcmsio/simple-blog-with-microcms, its Vercel demo) name microCMS but not this slug, so no rule touches them.",
"slug": "microcms-blog",
"pascal": "MicrocmsBlog",
"productName": "Simple Blog",
"domain": "microcms-blog.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
166 changes: 166 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# microcms-blog

A blog whose posts, tags and writers live in a [microCMS](https://microcms.io)
service — read through microCMS's SDK, code blocks highlighted on the server,
posts by tag, full-text search, pages of ten, and drafts previewed by their
draft key — running on **Cloudflare Workers + Static Assets** through
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare). It is
Vercel's [Next.js Blog with microCMS](https://github.com/microcmsio/simple-blog-with-microcms)
template (microCMS's Simple Blog), 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 the blog uses 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 -->

## Connect microCMS

The blog deploys and serves before it has a microCMS service: until its
Worker holds a service id and an API key it shows three **sample posts**,
under a notice that says so. To make it read your content:

1. **Create a service** at [app.microcms.io](https://app.microcms.io/signup)
(the free Hobby plan is enough), choosing **Create your own**. Its
**service ID** is the `xxxx` of `https://xxxx.microcms.io`.
2. **Add the three list APIs** the blog reads, all in the **list** format —
`apps/web/microcms-template.json` is the template's own export of them:

| API | Endpoint | Fields (field ID: kind) |
|---|---|---|
| tag | `tags` | `name`: text |
| writer | `writers` | `name`: text, `profile`: text area, `image`: image |
| blog | `blog` | `title`: text, `description`: text area, `content`: rich editor, `thumbnail`: image, `tags`: multiple content references → tag, `writer`: content reference → writer |

Then write a tag, a writer and a post, and **publish** them (create the
tag and the writer first: a post refers to them).
3. **Store the service and its key**, once per deployed environment: the
service ID and the **default** API key from **API keys** (it reads
published content; a draft needs its draft key as well). They are this
repository's Orun secrets, and stage and prod can each name their own
service:

```bash
orun secrets set MICROCMS_SERVICE_DOMAIN --env stage # prompts for the value
orun secrets set MICROCMS_API_KEY --env stage
orun secrets set MICROCMS_SERVICE_DOMAIN --env prod
orun secrets set MICROCMS_API_KEY --env prod
```

4. **Redeploy the blog**: setting a secret deploys nothing. Use **Deploy by
hand** below, or change the stamp on the last line of
`apps/web/component.yaml` (`# orun: redeploy …`) and merge. The deploy
pushes both to the Worker as secrets (`microcms-blog-web-stage`,
`microcms-blog-web-prod`), never into a build, and every page reads them
when it renders; the sample posts and the notice are gone from that deploy
on.

**Drafts.** In microCMS, the blog API's **preview** setting (API settings →
Screen preview) takes the URL a draft opens at; point it at
`https://microcms-blog-web-prod.your-workers-subdomain.workers.dev/blogs/{CONTENT_ID}?dk={DRAFT_KEY}`
(and one for stage, or your custom domain). A page with `?dk=` reads the
draft, and is never cached.

Published changes show on the next visit: every page is rendered when it is
requested, from microCMS's content API, with no deploy and no webhook.

## What is here

| Surface | Where |
|---|---|
| Home, `/p/[current]`, `/blogs/[slug]`, `/tags/[tagId]`, `/search` | `apps/web/app` |
| The microCMS reads (the SDK's client, per request) | `apps/web/libs/microcms.ts` |
| The sample posts an unconnected blog shows, and its notice | `apps/web/libs/sample.ts`, `apps/web/public/sample`, `apps/web/components/ConnectMicroCMS` |
| Rich text and code highlighting, dates | `apps/web/libs/utils.ts` |
| The three APIs, as microCMS exports them | `apps/web/microcms-template.json` |
| The blog's name | `apps/web/app/site.ts` |
| Workers build and deploy contract | `apps/web/next.config.js`, `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 # next build + opennextjs-cloudflare build → apps/web/.open-next
```

That needs no microCMS service, and is what to run before you push: a pull
request builds the blog but does not lint or run its tests. With a service:

```bash
cd apps/web
cp .env.example .env.local # MICROCMS_SERVICE_DOMAIN, MICROCMS_API_KEY
cd ../..
pnpm --filter @app/web dev # http://localhost:3000
```

For the Worker locally, the service and its key are Worker secrets:

```bash
cd apps/web
cp .dev.vars.example .dev.vars # MICROCMS_SERVICE_DOMAIN, MICROCMS_API_KEY
pnpm build
pnpm preview # wrangler dev over the built Worker
```

| Variable | Read | What it does |
|---|---|---|
| `MICROCMS_SERVICE_DOMAIN` | request time, in the Worker | The service ID. Deployed Workers get it from the `MICROCMS_SERVICE_DOMAIN` secret of their environment, pushed by each deploy. Unset, the blog is unconnected: sample posts and a notice. |
| `MICROCMS_API_KEY` | request time, in the Worker | The service's API key. Both it and the service ID are needed to connect. |
| `BASE_URL` | build time | The site's public origin, for its Open Graph and canonical URLs. The deploy sets it per environment; not a secret. |

## 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 no microCMS value in its environment, so no bundle can
carry one — then pushes that environment's microCMS secrets to the Worker
and deploys: to `stage`, then to `prod` once stage has converged on the same
commit; `dev` only verifies. The Worker is `microcms-blog-web-<env>` on your
account's workers.dev subdomain, and every deploy is smoke-tested over HTTP:
the home page must render, and an article that does not exist must be a
404. A pull request runs the same pipeline's verify lanes: the blog built
and dry-deployed for each environment, with nothing deployed and no secret
pushed. They do not lint or run the tests, so run `pnpm typecheck`,
`pnpm lint` and `pnpm test` before you push. (A push to `main` builds,
deploys and smoke-tests.)

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.

**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 storing or
rotating a microCMS secret, say. A component with nothing to run in that
environment (a test suite in `prod`) is left out with a notice.

**Caching.** The template's `CDN-Cache-Control` header (60 s, then 300 s
stale while it revalidates; a draft never) is kept for a CDN in front of the
blog. Cloudflare does not cache a Worker's responses on workers.dev, so as
deployed every view reads microCMS, whose own CDN fronts its content API.

## 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 →
`microcms-blog-web-prod` → Settings → Domains & Routes → Add → Custom domain).
The blog's Open Graph and canonical URLs name its origin, so set
`SITE_URL: https://<your domain>` in that environment's `env:` in
`intent.yaml` — the next deploy builds with it — and point microCMS's draft
preview at it. The repository also names the domain as `BASE_DOMAIN` in
`intent.yaml` (dev, stage and prod), which the blog was born with as the
reserved placeholder `microcms-blog.example.com`. Replace it with your domain
in the same change.
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 microCMS service 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: []
157 changes: 157 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
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 microCMS service
# behind it, and then with one (a local stand-in for microCMS's content API).
#
# ─── WHY THIS IS NOT IN ci.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, render)
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 render; do
echo "── $t"
bash "testing/$t.test.sh"
done
# Every component's docs/{overview,architecture,runbook}.md is generated
# from what the component declares (its manifest, Worker config,
# Terraform, migrations, package scripts). A pull request that changes
# one of those facts without regenerating the pages fails here.
- name: Component docs match their manifests
run: python3 tooling/catalog/gen-component-docs.py --check

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
# Pinned at v2.96.0, not the blog's lane pin: at or above the bootstrap
# floor (v2.88.0, BOOTSTRAP.md), and the first orun that reads a
# component's `spec.preview`, so the placement's `orun validate` checks the
# blog's live preview too. 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, below).
blueprint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.96.0
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
# This job installs nothing either: with no lockfile hook the offline
# bootstrap never runs pnpm, so there is no store, and the pnpm cache
# setup-node v5 turns on by itself (package.json names a packageManager)
# fails the job saving a path that does not exist whenever no earlier
# cache exists for the lockfile.
package-manager-cache: false
- 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 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 needs an orun at the product's lane pin
# (v2.78.4) or newer: 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. The
# offline bootstrap before it reads the blueprint, which takes the
# bootstrap floor (v2.88.0: the one `secrets` reconcile, the task set-up
# in the background, the landings checked in the box), so this tier
# runs v2.96.0, at or above the floor and the first orun that reads
# `spec.preview`, which is newer than the lane pin.
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.96.0
- 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 MICROCMS SERVICE, AND WITH ONE: each
# landing installed, its fixture rendered, type-checked, linted, tested and
# built, 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
# under the "not connected" notice, the 404s, the cache headers — then
# served again connected to a local stand-in for microCMS's content API:
# the posts, an article with its writer, a draft, a tag, a search. Pinned at v2.96.0, above the bootstrap floor
# (v2.88.0), the first orun that reads `spec.preview`: the offline bootstrap
# reads the blueprint, and the pin is newer than the product's lane pin
# (v2.78.4), which is all the lane steps need.
blog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.96.0
- 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
Loading
Loading