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
14 changes: 14 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: release
# 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*"]
concurrency:
group: release
cancel-in-progress: false
jobs:
python:
uses: ./.github/workflows/python.yml
worker:
uses: ./.github/workflows/worker.yml
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:
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 }}
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"
1 change: 1 addition & 0 deletions .github/workflows/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches: [main]
paths: ["worker/**", ".github/workflows/worker.yml"]
workflow_call:
jobs:
test:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions docs/features/hosted-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 `<KYPP_PUBLIC_URL>/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.
Expand Down
9 changes: 6 additions & 3 deletions worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ 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 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.

Expand Down
16 changes: 16 additions & 0 deletions worker/deploy-production.mjs
Original file line number Diff line number Diff line change
@@ -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")) { 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");
run("deploy", "--env", "production");
2 changes: 1 addition & 1 deletion worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading