Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

ci: read TEND_BOT_TOKEN from an environment in every job (#3748)

Maximilian Roos59c7320a78a9
diff --git a/.github/CLAUDE.md b/.github/CLAUDE.md
index bcf1e29c9..a5ce004bf 100644
--- a/.github/CLAUDE.md
+++ b/.github/CLAUDE.md
@@ -11,10 +11,11 @@ Workflows check `user.login == 'worktrunk-bot'` directly.
## Tokens
-| Token | Purpose |
-|-------|---------|
-| `TEND_BOT_TOKEN` | Every workflow acting as `worktrunk-bot`, including the winget and Homebrew publish jobs |
-| `CLAUDE_CODE_OAUTH_TOKEN` | Authenticates Claude Code to the Anthropic API |
+| Token | Purpose | Stored in |
+|-------|---------|-----------|
+| `TEND_BOT_TOKEN` | Every workflow acting as `worktrunk-bot`, including the winget and Homebrew publish jobs | `tend` and `release` environments |
+| `CLAUDE_CODE_OAUTH_TOKEN` | Authenticates Claude Code to the Anthropic API | repo level |
+| `CODECOV_TOKEN` | Uploads coverage from `ci.yaml` and `coverage.yaml` | repo level, allowlisted in `.config/tend.yaml` |
## Merge restriction
@@ -25,22 +26,55 @@ Only the repo owner (`@max-sixty`, admin) can merge to `main`.
## Environment protection
-Release credentials live in GitHub Environments so no other workflow the repo
-runs can read them. Each environment holds what one phase needs, since a job
-that joins an environment can read every secret in it:
+Credentials that grant write access live in a GitHub Environment so no other
+workflow the repo runs can read them. Each environment holds what one phase
+needs, since a job that joins an environment can read every secret in it:
-| Environment | Secret | Read by |
-|-------------|--------|---------|
-| `release` | `AUR_SSH_PRIVATE_KEY` | `publish-aur` |
-| `signing` | `SIGNPATH_API_TOKEN` | `build-local-artifacts` |
+| Environment | Admits | Secret | Read by |
+|-------------|--------|--------|---------|
+| `tend` | `main` | `TEND_BOT_TOKEN` | every `tend-*.yaml` job but `relay`, `append-gist`, both `create-issue-on-*-failure` jobs |
+| `release` | `v*` tags | `AUR_SSH_PRIVATE_KEY`, `TEND_BOT_TOKEN` | `publish-aur`, `publish-winget`, `publish-homebrew` |
+| `signing` | `v*` tags | `SIGNPATH_API_TOKEN` | `build-local-artifacts` |
+| `github-pages` | `main` | none — OIDC only | `deploy-docs` |
-Both restrict deployments to `v*` tags and neither has a reviewer rule, so
-joining a job to one costs no approval step.
+The deployment branch policy is the gate: a job naming an environment runs
+only from a ref the policy admits, so a workflow pushed to a feature branch is
+refused before its first step. `worktrunk-bot` can push branches but cannot
+update `main` (the "Merge access" ruleset) or move tags (the "Tag operations"
+ruleset, admin-only), which is what makes both admitted sets unreachable to
+it. No environment has a reviewer rule, so joining a job to one costs no
+approval step.
+
+`TEND_BOT_TOKEN` is stored in two environments rather than shared, because a
+policy admits branches or tags but the token is needed under both: the bot's
+own workflows run on `main`, the publish jobs on a `v*` tag. Adding the tag to
+`tend` is not an option — `tend check` pins that policy to exactly the
+protected branches and its `--fix` deletes anything else.
+
+Jobs name `tend` as `{name: tend, deployment: false}`. GitHub files a
+deployment record for every job that names an environment, against whatever
+ref the run belongs to — under `pull_request_target` that is the pull request
+itself, so an omission posts a "worktrunk-bot deployed to tend" line on every
+push to every PR. `deployment: false` drops the record and keeps the gate. The
+release jobs keep their records: a tag-push deployment lands in no PR
+timeline, and it reads as what it is.
+
+The generated `tend-*.yaml` files still carry the bare `environment: tend`,
+because they are regenerated by the published `tend` rather than edited here —
+`tend check`'s `environment-deployments` fails until a `uvx tend@latest init`
+regen lands them on tend ≥ 0.1.14.
crates.io publishing holds no stored token — it uses Trusted Publishing.
crates.io mints a short-lived one only for an OIDC claim from `release.yaml`
running in that same `release` environment.
+`CLAUDE_CODE_OAUTH_TOKEN` is still at repo level, so `tend check`'s
+`repo-secret-allowlist` fails until it moves. It cannot be read back from
+GitHub, so moving it means pasting the value or re-minting with
+`claude setup-token`; only the generated workflows read it, and all of them
+name the `tend` environment, so nothing else breaks when the repo-level copy
+goes.
+
## Build environment
`Swatinem/rust-cache` hashes `CARGO*` and `RUST*` env vars into the cache key.
diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml
index 5b1692add..33701fd8e 100644
--- a/.github/workflows/benchmarks.yaml
+++ b/.github/workflows/benchmarks.yaml
@@ -73,13 +73,37 @@ jobs:
name: benchmark-results-${{ github.run_id }}
path: target/criterion
- # Time-series benchmark store, owned by worktrunk-bot:
- # https://gist.github.com/worktrunk-bot/19bb23cb9658722abfe69479d0a4f9bf
- #
- # Cron-only: workflow_dispatch runs aren't appended (would pollute the
- # time series). Skipped on forks: `TEND_BOT_TOKEN` is not exposed there.
+ # Time-series benchmark store, owned by worktrunk-bot:
+ # https://gist.github.com/worktrunk-bot/19bb23cb9658722abfe69479d0a4f9bf
+ #
+ # Cron-only: workflow_dispatch runs aren't appended (would pollute the
+ # time series). Skipped on forks: the environment's secrets aren't exposed
+ # there.
+ #
+ # Its own job so the token stays off `benchmarks`. The copy this job reads
+ # is in the `tend` environment, whose policy admits `main` alone, so a job
+ # naming it is refused on every other ref — which would take
+ # workflow_dispatch against a chosen branch with it. A job GitHub skips
+ # never requests its environment, so the cron gate above keeps the gate off
+ # the dispatch path.
+ append-gist:
+ needs: benchmarks
+ if: github.repository_owner == 'max-sixty' && github.event_name == 'schedule'
+ runs-on: ubuntu-24.04
+ environment:
+ name: tend
+ # A secret scope, not a deploy target — see .github/CLAUDE.md.
+ deployment: false
+ permissions:
+ contents: read
+ steps:
+ - name: 📦 Download benchmark results
+ uses: actions/download-artifact@v8
+ with:
+ name: benchmark-results-${{ github.run_id }}
+ path: target/criterion
+
- name: 💾 Append results to gist
- if: github.repository_owner == 'max-sixty' && github.event_name == 'schedule'
env:
GITHUB_TOKEN: ${{ secrets.TEND_BOT_TOKEN }}
GIST_ID: 19bb23cb9658722abfe69479d0a4f9bf
@@ -111,9 +135,15 @@ jobs:
git -C /tmp/gist push
create-issue-on-benchmark-failure:
- needs: benchmarks
+ needs:
+ - benchmarks
+ - append-gist
if: always() && contains(needs.*.result, 'failure') && github.repository_owner == 'max-sixty' && github.event_name == 'schedule'
runs-on: ubuntu-24.04
+ environment:
+ name: tend
+ # A secret scope, not a deploy target — see .github/CLAUDE.md.
+ deployment: false
permissions:
contents: read
issues: write
diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml
index 2b1838e26..d81a6e452 100644
--- a/.github/workflows/nightly.yaml
+++ b/.github/workflows/nightly.yaml
@@ -426,6 +426,13 @@ jobs:
- link-check
if: always() && contains(needs.*.result, 'failure') && github.repository_owner == 'max-sixty' && github.event_name == 'schedule'
runs-on: ubuntu-24.04
+ environment:
+ name: tend
+ # A secret scope, not a deploy target — see .github/CLAUDE.md. The cron
+ # gate above keeps this off the workflow's pull_request and
+ # workflow_dispatch triggers, whose refs the `tend` policy can refuse;
+ # its push trigger is `main`-only, which the policy already admits.
+ deployment: false
permissions:
contents: read
issues: write
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index d235ba761..8ce7750c6 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -406,6 +406,7 @@ jobs:
- plan
- host
runs-on: ubuntu-24.04
+ environment: release
if: ${{ needs.plan.outputs.publishing == 'true' }}
env:
GH_TOKEN: ${{ secrets.TEND_BOT_TOKEN }}
@@ -428,6 +429,7 @@ jobs:
- plan
- host
runs-on: "ubuntu-24.04"
+ environment: release
env:
GITHUB_USER: "worktrunk-bot"
GITHUB_EMAIL: "[email protected]"