From 520ef783fa4f08cde1e919ca0c3c7e0a3c30a4bf Mon Sep 17 00:00:00 2001 From: vu1n <2105991+vu1n@users.noreply.github.com> Date: Wed, 11 Nov 2026 01:17:28 +0000 Subject: [PATCH 1/3] Deploy kypp.vu1n.dev from v* tags, not main; run Python CI on push to main --- .github/workflows/python.yml | 14 ++++++++++++++ .github/workflows/release.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/worker.yml | 1 + docs/features/hosted-worker.md | 2 ++ worker/README.md | 7 ++++--- 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 640c999..70b45e2 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -12,6 +12,20 @@ on: - ".github/workflows/python.yml" - "pyproject.toml" - "uv.lock" + push: + branches: [main] + paths: + - "kypp/**" + - "tests/**" + - "worker/src/**" + - "worker/test/**" + - "worker/migrations/**" + - "docs/features/**" + - "scripts/featuremap.py" + - ".github/workflows/python.yml" + - "pyproject.toml" + - "uv.lock" + workflow_call: workflow_dispatch: concurrency: group: python-${{ github.ref }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..26fbec9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: release +# A v* tag is the release: once both test suites pass on the tagged commit, `release` moves to it, +# and Workers Builds deploys kypp.vu1n.dev from `release`, never from main. +on: + push: + tags: ["v*"] +concurrency: + group: release + cancel-in-progress: false +jobs: + python: + uses: ./.github/workflows/python.yml + worker: + uses: ./.github/workflows/worker.yml + promote: + needs: [python, worker] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # Fast-forward only: an older tag can't roll production back. Roll back by tagging a revert. + - name: move release to the tag + run: git push origin "$GITHUB_SHA:refs/heads/release" + - name: GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1 || gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes --title "$GITHUB_REF_NAME" diff --git a/.github/workflows/worker.yml b/.github/workflows/worker.yml index b627a8f..dea516a 100644 --- a/.github/workflows/worker.yml +++ b/.github/workflows/worker.yml @@ -5,6 +5,7 @@ on: push: branches: [main] paths: ["worker/**", ".github/workflows/worker.yml"] + workflow_call: jobs: test: runs-on: ubuntu-latest diff --git a/docs/features/hosted-worker.md b/docs/features/hosted-worker.md index 932bc8e..83a2a06 100644 --- a/docs/features/hosted-worker.md +++ b/docs/features/hosted-worker.md @@ -74,6 +74,8 @@ TypeSafe API's shape, for GitHub Actions OIDC tokens (`worker/src/oidc.ts`) and `env.production`, which repeats every binding and var because envs don't inherit them. Change one, change both. Deploy the install only with `npm run deploy:production`: a plain `wrangler deploy` targets the template and turns workers.dev back on. +- kypp.vu1n.dev deploys from the `release` branch (Workers Builds), which only `release.yml` moves, and + only to a `v*` tag whose tests passed. A push to main deploys nothing. - The OAuth resource id is exactly `/mcp`. A path or query suffix on the MCP URL breaks token audience checks, so the project travels as a tool argument or the `X-Kypp-Project` header. diff --git a/worker/README.md b/worker/README.md index ecfdbdc..610d794 100644 --- a/worker/README.md +++ b/worker/README.md @@ -158,9 +158,10 @@ npm run deploy # applies migrations, then deploys; The owner's install (`kypp.vu1n.dev`) is the `production` environment in `wrangler.jsonc`: its D1 and KV ids, custom domain, `workers_dev: false` and vars are committed there, and the top level stays the template the button copies. Deploy it with `npm run deploy:production` (migrations, then -`wrangler deploy --env production`). To deploy it on every push to main without keeping a Cloudflare -token in GitHub, connect the Worker to the repo with Workers Builds (Worker > Settings > Builds): root -`worker`, deploy command `npm run deploy:production`, no build variables. A deploy without +`wrangler deploy --env production`). It deploys on release, not on every push: a `v*` tag runs +`.github/workflows/release.yml`, which fast-forwards the `release` branch to the tag once both test +suites pass on it, and Workers Builds (root `worker`, deploy command `npm run deploy:production`, no +build variables) deploys `release`. No Cloudflare token lives in GitHub. Roll back by tagging a revert. A deploy without `--env production` targets the template and would turn workers.dev back on, so don't run plain `wrangler deploy` against this install. For your own install, add your own env block the same way. From 7a89962bfd75956ccbff1e0ed30e90b818488ded Mon Sep 17 00:00:00 2001 From: vu1n <2105991+vu1n@users.noreply.github.com> Date: Wed, 11 Nov 2026 01:20:56 +0000 Subject: [PATCH 2/3] Deploy from the tag through tumbler OIDC; Workers Builds skips --- .github/workflows/release.yml | 25 ++++++++++++++++++------- docs/features/hosted-worker.md | 4 ++-- worker/README.md | 8 +++++--- worker/deploy-production.mjs | 16 ++++++++++++++++ worker/package.json | 2 +- 5 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 worker/deploy-production.mjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 26fbec9..862e543 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,6 @@ name: release -# A v* tag is the release: once both test suites pass on the tagged commit, `release` moves to it, -# and Workers Builds deploys kypp.vu1n.dev from `release`, never from main. +# A v* tag is the release: once both test suites pass on the tagged commit, this job deploys +# kypp.vu1n.dev. A push to main never deploys. on: push: tags: ["v*"] @@ -12,18 +12,29 @@ jobs: uses: ./.github/workflows/python.yml worker: uses: ./.github/workflows/worker.yml - promote: + deploy: needs: [python, worker] runs-on: ubuntu-latest permissions: contents: write + id-token: write # the job's OIDC token is its tumbler caller (token row kypp-release) + defaults: + run: + working-directory: worker steps: - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - fetch-depth: 0 - # Fast-forward only: an older tag can't roll production back. Roll back by tagging a revert. - - name: move release to the tag - run: git push origin "$GITHUB_SHA:refs/heads/release" + node-version: "22.21" + - run: npm ci + - name: deploy kypp.vu1n.dev + env: + TUMBLER_URL: https://tumbler.vu1n.dev + run: | + curl -fsSL "$TUMBLER_URL/cli" -o "$RUNNER_TEMP/tumbler" && chmod +x "$RUNNER_TEMP/tumbler" + export TUMBLER_TOKEN=$(curl -fsS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ + "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$TUMBLER_URL" | jq -r .value) + "$RUNNER_TEMP/tumbler" run -p kypp --scope workers:write -k CLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID -- npm run deploy:production - name: GitHub release env: GH_TOKEN: ${{ github.token }} diff --git a/docs/features/hosted-worker.md b/docs/features/hosted-worker.md index 83a2a06..5966787 100644 --- a/docs/features/hosted-worker.md +++ b/docs/features/hosted-worker.md @@ -74,8 +74,8 @@ TypeSafe API's shape, for GitHub Actions OIDC tokens (`worker/src/oidc.ts`) and `env.production`, which repeats every binding and var because envs don't inherit them. Change one, change both. Deploy the install only with `npm run deploy:production`: a plain `wrangler deploy` targets the template and turns workers.dev back on. -- kypp.vu1n.dev deploys from the `release` branch (Workers Builds), which only `release.yml` moves, and - only to a `v*` tag whose tests passed. A push to main deploys nothing. +- kypp.vu1n.dev deploys only from `release.yml` on a `v*` tag whose tests passed. `deploy:production` + skips under Workers Builds (`WORKERS_CI`), which still builds main, so a push to main deploys nothing. - The OAuth resource id is exactly `/mcp`. A path or query suffix on the MCP URL breaks token audience checks, so the project travels as a tool argument or the `X-Kypp-Project` header. diff --git a/worker/README.md b/worker/README.md index 610d794..c894301 100644 --- a/worker/README.md +++ b/worker/README.md @@ -159,9 +159,11 @@ The owner's install (`kypp.vu1n.dev`) is the `production` environment in `wrangl and KV ids, custom domain, `workers_dev: false` and vars are committed there, and the top level stays the template the button copies. Deploy it with `npm run deploy:production` (migrations, then `wrangler deploy --env production`). It deploys on release, not on every push: a `v*` tag runs -`.github/workflows/release.yml`, which fast-forwards the `release` branch to the tag once both test -suites pass on it, and Workers Builds (root `worker`, deploy command `npm run deploy:production`, no -build variables) deploys `release`. No Cloudflare token lives in GitHub. Roll back by tagging a revert. A deploy without +`.github/workflows/release.yml`, which runs both test suites on the tag and then `npm run +deploy:production` with a Cloudflare key from tumbler. The job's GitHub OIDC token is its caller (token +row `kypp-release`, bound to `repo:vu1n/kypp:ref:refs/tags/v*`), so no Cloudflare token lives in GitHub. +`deploy:production` refuses anything but a clean v* checkout, and under Workers Builds (still connected, +building main) it skips. Roll back by tagging a revert. A deploy without `--env production` targets the template and would turn workers.dev back on, so don't run plain `wrangler deploy` against this install. For your own install, add your own env block the same way. diff --git a/worker/deploy-production.mjs b/worker/deploy-production.mjs new file mode 100644 index 0000000..f2264d1 --- /dev/null +++ b/worker/deploy-production.mjs @@ -0,0 +1,16 @@ +// `npm run deploy:production`: deploys kypp.vu1n.dev, only from a v* tag (release.yml runs it). +import { execFileSync } from "node:child_process"; + +// Workers Builds still runs this on every push to main; a push to main must not deploy. +if (process.env.WORKERS_CI) { + console.log("kypp: skipped. Production deploys from v* tags (.github/workflows/release.yml), not from main."); + process.exit(0); +} +const git = (...a) => execFileSync("git", a, { encoding: "utf8" }).trim(); +const tag = git("tag", "--points-at", "HEAD", "--list", "v*").split("\n")[0]; +if (!tag) { console.error("kypp: HEAD is not a v* tag; production deploys only a release"); process.exit(1); } +if (git("status", "--porcelain", "--untracked-files=no")) { console.error(`kypp: ${tag} has uncommitted changes`); process.exit(1); } +console.log(`kypp: deploying ${tag}`); +const run = (...a) => execFileSync("npx", ["wrangler", ...a], { stdio: "inherit" }); +run("d1", "migrations", "apply", "DB", "--remote", "--env", "production"); +run("deploy", "--env", "production"); diff --git a/worker/package.json b/worker/package.json index 70e3e40..eafe0f6 100644 --- a/worker/package.json +++ b/worker/package.json @@ -9,7 +9,7 @@ "typecheck": "tsc --noEmit", "test": "node --test --experimental-strip-types test/*.test.ts", "db:migrate": "wrangler d1 migrations apply DB --remote", - "deploy:production": "wrangler d1 migrations apply DB --remote --env production && wrangler deploy --env production" + "deploy:production": "node deploy-production.mjs" }, "dependencies": { "@cloudflare/workers-oauth-provider": "^1.2.1", From 257eac091d6471c52ed44cf360147c33f3221083 Mon Sep 17 00:00:00 2001 From: vu1n <2105991+vu1n@users.noreply.github.com> Date: Wed, 11 Nov 2026 01:30:41 +0000 Subject: [PATCH 3/3] deploy-production: refuse untracked files too; wrangler reads migrations from disk --- worker/deploy-production.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/deploy-production.mjs b/worker/deploy-production.mjs index f2264d1..e05ae0f 100644 --- a/worker/deploy-production.mjs +++ b/worker/deploy-production.mjs @@ -9,7 +9,7 @@ if (process.env.WORKERS_CI) { const git = (...a) => execFileSync("git", a, { encoding: "utf8" }).trim(); const tag = git("tag", "--points-at", "HEAD", "--list", "v*").split("\n")[0]; if (!tag) { console.error("kypp: HEAD is not a v* tag; production deploys only a release"); process.exit(1); } -if (git("status", "--porcelain", "--untracked-files=no")) { console.error(`kypp: ${tag} has uncommitted changes`); process.exit(1); } +if (git("status", "--porcelain")) { console.error(`kypp: ${tag} has uncommitted or untracked files (wrangler would deploy or migrate them too)`); process.exit(1); } console.log(`kypp: deploying ${tag}`); const run = (...a) => execFileSync("npx", ["wrangler", ...a], { stdio: "inherit" }); run("d1", "migrations", "apply", "DB", "--remote", "--env", "production");