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
6 changes: 3 additions & 3 deletions .agents/skills/github-prs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ make pr-merge PR="<PR> [<PR> ...]" # merges every green PR now, reports the
make pr-merge PR=<PR> ARGS=--dry-run # says what it would do
```

- **Green** means `local-ci` and the section attest the exact head, GitHub can merge it without conflicts, and the checks passed. It squash-merges with `--match-head-commit <head>`, so only the attested head lands; behind `main` is fine. Where Actions cannot run (no CI job ran, or GitHub never started them), it merges on `local-ci` alone and says so.
- Anything else (draft, unattested, pending, failing, conflicting, stacked) is reported with its next step; the script never waits. Only a conflict needs rebase, push, attest.
- **Green** means `local-ci` and the section attest the exact head, GitHub can merge it without conflicts, and the checks passed. It squash-merges with `--match-head-commit <head>`, so only the attested head lands. A head behind `main` is refused ("rebase onto origin/main and re-attest"): the merged tree must be the one you verified. Where Actions cannot run (no CI job ran, or GitHub never started them), it merges on `local-ci` alone and says so.
- Anything else (draft, unattested, pending, failing, conflicting, stacked) is reported with its next step; the script never waits. A head behind `main` or a conflict needs rebase, push, run what it needs, attest; after each merge in a burst, rebase the next PR.
- **After each merge, check its deploy** (a follow-up, never a gate; merge the next PR now): it prints `make pr-merge ARGS="--check-deploy <squash sha>"`. Run it once "Deploy staging" has run for that commit. Failed or refused: top priority, fix forward. Cancelled by a newer main deploy: `make pr-merge ARGS=--check-staging` checks main's head. A dry run (`RAILWAY_DEPLOY` not `true`) deployed nothing. After a burst, `ARGS=--then-check-staging` follows main's deploy (bounded).
- **Stacked children** are retargeted to `main` before their parent merges. Then `git rebase --onto origin/main <old parent head> <child>`, `git push --force-with-lease`, attest.
- Integration branches (`feat/<x>`): `make pr-merge PR=<PR> ARGS=--any-base`.
Expand All @@ -77,7 +77,7 @@ make pr-merge PR=<PR> ARGS=--dry-run # says what it would do

## 7. Staging deploys itself

`main` runs no CI. "Deploy staging" deploys a push to Railway staging only when `make ci-local` attested it (`cilocal attest`): the squash of an attested PR head, or a commit with its own `local-ci`. Two verified PRs merged together are not themselves verified; a clash surfaces on staging and is fixed forward. The hourly "Staging catch-up" deploys `main` whenever staging is behind and `main` is attested. Never wait for a deploy or for another PR to settle: merge each PR when its own head is attested and conflict-free, and stack the next at once; check its deploy afterwards (section 5); "Post-merge report" comments on the PR when a push workflow on its commit fails. A failed deploy is fixed forward in parallel and blocks no unrelated merge.
`main` runs no CI. "Deploy staging" deploys a push to Railway staging only when `make ci-local` attested it (`cilocal attest`): the squash of an attested PR head, or a commit with its own `local-ci`. `make pr-merge` refuses a head behind `main`, so every squash is a tree someone verified. The hourly "Staging catch-up" deploys `main` whenever staging is behind and `main` is attested. Never wait for a deploy or for another PR to settle: merge each PR when its own head is attested and conflict-free, and stack the next at once; check its deploy afterwards (section 5); "Post-merge report" comments on the PR when a push workflow on its commit fails. A failed deploy is fixed forward in parallel and blocks no unrelated merge.

An unattested `main` is the top priority: both workflows fail and say why. Fix it forward: `git worktree add --detach <dir> <sha>`, run what the commits since the last attested one need (`make ci` when there is none, as in a new project's first attestation), then `make ci-local COMMIT=<sha> RAN="…"` there. It refuses a dirty tree, a commit off `origin/main` or one that already failed, and posts `local-ci` on the commit; then dispatch "Deploy staging".

Expand Down
6 changes: 3 additions & 3 deletions .claude/skills/github-prs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ make pr-merge PR="<PR> [<PR> ...]" # merges every green PR now, reports the
make pr-merge PR=<PR> ARGS=--dry-run # says what it would do
```

- **Green** means `local-ci` and the section attest the exact head, GitHub can merge it without conflicts, and the checks passed. It squash-merges with `--match-head-commit <head>`, so only the attested head lands; behind `main` is fine. Where Actions cannot run (no CI job ran, or GitHub never started them), it merges on `local-ci` alone and says so.
- Anything else (draft, unattested, pending, failing, conflicting, stacked) is reported with its next step; the script never waits. Only a conflict needs rebase, push, attest.
- **Green** means `local-ci` and the section attest the exact head, GitHub can merge it without conflicts, and the checks passed. It squash-merges with `--match-head-commit <head>`, so only the attested head lands. A head behind `main` is refused ("rebase onto origin/main and re-attest"): the merged tree must be the one you verified. Where Actions cannot run (no CI job ran, or GitHub never started them), it merges on `local-ci` alone and says so.
- Anything else (draft, unattested, pending, failing, conflicting, stacked) is reported with its next step; the script never waits. A head behind `main` or a conflict needs rebase, push, run what it needs, attest; after each merge in a burst, rebase the next PR.
- **After each merge, check its deploy** (a follow-up, never a gate; merge the next PR now): it prints `make pr-merge ARGS="--check-deploy <squash sha>"`. Run it once "Deploy staging" has run for that commit. Failed or refused: top priority, fix forward. Cancelled by a newer main deploy: `make pr-merge ARGS=--check-staging` checks main's head. A dry run (`RAILWAY_DEPLOY` not `true`) deployed nothing. After a burst, `ARGS=--then-check-staging` follows main's deploy (bounded).
- **Stacked children** are retargeted to `main` before their parent merges. Then `git rebase --onto origin/main <old parent head> <child>`, `git push --force-with-lease`, attest.
- Integration branches (`feat/<x>`): `make pr-merge PR=<PR> ARGS=--any-base`.
Expand All @@ -77,7 +77,7 @@ make pr-merge PR=<PR> ARGS=--dry-run # says what it would do

## 7. Staging deploys itself

`main` runs no CI. "Deploy staging" deploys a push to Railway staging only when `make ci-local` attested it (`cilocal attest`): the squash of an attested PR head, or a commit with its own `local-ci`. Two verified PRs merged together are not themselves verified; a clash surfaces on staging and is fixed forward. The hourly "Staging catch-up" deploys `main` whenever staging is behind and `main` is attested. Never wait for a deploy or for another PR to settle: merge each PR when its own head is attested and conflict-free, and stack the next at once; check its deploy afterwards (section 5); "Post-merge report" comments on the PR when a push workflow on its commit fails. A failed deploy is fixed forward in parallel and blocks no unrelated merge.
`main` runs no CI. "Deploy staging" deploys a push to Railway staging only when `make ci-local` attested it (`cilocal attest`): the squash of an attested PR head, or a commit with its own `local-ci`. `make pr-merge` refuses a head behind `main`, so every squash is a tree someone verified. The hourly "Staging catch-up" deploys `main` whenever staging is behind and `main` is attested. Never wait for a deploy or for another PR to settle: merge each PR when its own head is attested and conflict-free, and stack the next at once; check its deploy afterwards (section 5); "Post-merge report" comments on the PR when a push workflow on its commit fails. A failed deploy is fixed forward in parallel and blocks no unrelated merge.

An unattested `main` is the top priority: both workflows fail and say why. Fix it forward: `git worktree add --detach <dir> <sha>`, run what the commits since the last attested one need (`make ci` when there is none, as in a new project's first attestation), then `make ci-local COMMIT=<sha> RAN="…"` there. It refuses a dirty tree, a commit off `origin/main` or one that already failed, and posts `local-ci` on the commit; then dispatch "Deploy staging".

Expand Down
8 changes: 4 additions & 4 deletions docs/CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ It runs from cron on the dev box (the machine with Docker, `gh` and the `CI_RUNN

## Required checks and staging

The main ruleset should require `Secret scan` and `Local verification` from GitHub Actions on every pull request, and nothing else from CI. A pull request can add a workflow of its own whose job takes a required check's name; requiring the `local-ci` status as well closes that, because only someone with write access can post it, and `make pr-merge`, which runs on the merger's machine, makes the same checks itself. It need not require a head to be up to date with its base, and neither does `make pr-merge`: only a conflict stops it. A repository whose Actions cannot run (billing, or turned off) requires the `local-ci` status itself instead ([below](#when-actions-cannot-run)).
The main ruleset should require `Secret scan` and `Local verification` from GitHub Actions on every pull request, and nothing else from CI. A pull request can add a workflow of its own whose job takes a required check's name; requiring the `local-ci` status as well closes that, because only someone with write access can post it, and `make pr-merge`, which runs on the merger's machine, makes the same checks itself. It need not require a head to be up to date with its base: `make pr-merge` refuses one that is behind (GitHub's compare), so the merged tree is the verified one. A repository whose Actions cannot run (billing, or turned off) requires the `local-ci` status itself instead ([below](#when-actions-cannot-run)).

**Staging deploys only what `make ci-local` attested.** Railway's GitHub auto-deploy is off (`repo: ""` in `deploy/platform.yaml`): `Deploy staging` runs on every push to `main`, and its plan job (`cilocal attest <sha>`) lets the rollout start only when either:

- the pushed commit itself has a successful `local-ci` status (`make ci-local COMMIT=<sha> RAN="…"` in a clean worktree of it posts it), or
- the pull request whose squash made it (by GitHub's commit-to-PR index, or its `(#NNN)` squash title) passed local verification on the merged head.

A direct push, or the squash of an unattested head, deploys nothing, and the hourly `Staging catch-up` keeps refusing it until it is attested. Production takes only a release staging already ran ([RELEASES.md](RELEASES.md#what-is-gated)). **The merged tree of two verified PRs is not itself verified**: a head behind its base squashes into a tree nobody ran; a clash surfaces on staging and is fixed forward. An unattested `main` is the top priority: `git worktree add --detach <dir> <sha>`, run what the commits since the last attested one need (`make ci` when there is none, as in a [new project](#local-verification)), then `make ci-local COMMIT=<sha> RAN="…"` there; then dispatch `Deploy staging` (or wait for the catch-up).
A direct push, or the squash of an unattested head, deploys nothing, and the hourly `Staging catch-up` keeps refusing it until it is attested. Production takes only a release staging already ran ([RELEASES.md](RELEASES.md#what-is-gated)). **Only a verified tree merges**: `make pr-merge` refuses a head behind its base, because GitHub would squash it into a tree nobody built (the base's newer commits plus the PR). Two green PRs broke a downstream `main` that way: one removed a function the other still called. Rebase onto the base, run what the change needs and attest again; a burst of PRs therefore lands one after another, each rebased onto the last. An unattested `main` is the top priority: `git worktree add --detach <dir> <sha>`, run what the commits since the last attested one need (`make ci` when there is none, as in a [new project](#local-verification)), then `make ci-local COMMIT=<sha> RAN="…"` there; then dispatch `Deploy staging` (or wait for the catch-up).

## Merging on local verification

Pull requests open ready and stack. Each merges the moment it is attested, conflict-free and green, with `make pr-merge PR="<number>..."` (`cilocal merge`; the skill [github-prs](../.claude/skills/github-prs/SKILL.md)), which squashes exactly the attested head with `--match-head-commit` and never waits. Per PR it decides (`verify.Decide`): merged is done; closed, draft (`gh pr ready <n>`), stacked on another branch (unless `ARGS=--any-base`), conflicting, not attested, a failed check, a hollow green (`Local verification` passed but `Secret scan` skipped) or a pending one (including `Local verification` not reported yet) is skipped with its next step, and the others still merge. Only the newest run of each workflow, and the newest attempt of each job, counts. Before merging it retargets the open PRs stacked on the branch to `main` and prints the `git rebase --onto` for each. `ARGS=--dry-run` says what it would do.
Pull requests open ready and stack. Each merges the moment it is attested, conflict-free and green, with `make pr-merge PR="<number>..."` (`cilocal merge`; the skill [github-prs](../.claude/skills/github-prs/SKILL.md)), which squashes exactly the attested head with `--match-head-commit` and never waits. Per PR it decides (`verify.Decide`): merged is done; closed, draft (`gh pr ready <n>`), stacked on another branch (unless `ARGS=--any-base`), conflicting, behind its base, not attested, a failed check, a hollow green (`Local verification` passed but `Secret scan` skipped) or a pending one (including `Local verification` not reported yet) is skipped with its next step, and the others still merge. Only the newest run of each workflow, and the newest attempt of each job, counts. Before merging it retargets the open PRs stacked on the branch to `main` and prints the `git rebase --onto` for each. `ARGS=--dry-run` says what it would do.

- **Never wait** on another PR, its verification or a staging deploy. Behind `main` is fine; a conflict means rebase, push and attest again.
- **Never wait** on another PR, its verification or a staging deploy. A head behind `main`, or one that conflicts, is refused with "rebase onto origin/main and re-attest": rebase, push, run what it needs, attest. `make pr-merge` reads the base once more right before the merge, so only GitHub's own instant is left for a race.
- **After the merge, check its deploy.** `make pr-merge` prints the squash commit and `make pr-merge ARGS="--check-deploy <sha>"`. Once `Deploy staging` has run for it, run that once: one read of that commit's `Deploy staging` runs and of `<STAGING_WEB_URL>/healthz` (200 with `data.status` `ok`; `STAGING_WEB_URL` from the env, else the repository variable). A failed or refused deploy is the top priority, fixed forward; one cancelled by a newer `main` commit is checked on main's head (`ARGS=--check-staging`); a dry run (`RAILWAY_DEPLOY` is not `true`) says nothing was deployed. It is a follow-up, not a gate: keep merging. `ARGS=--then-check-staging` follows main's deploy (bounded) after a burst. `Post-merge report` comments on the PR when its deploy fails.
- **Ruleset first.** `make pr-merge` calls `gh pr merge`, so the ruleset (required reviews, required checks) still applies on top of it. Never `--delete-branch`: it closes the PRs stacked on the branch.

Expand Down
15 changes: 15 additions & 0 deletions scripts/cilocal/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ func (hub github) api(ctx context.Context, path string, into any) error {
return nil
}

// behind is how many commits of the branch `base` the commit `head` lacks
// (GitHub's compare): 0 when the head already contains the base.
func (hub github) behind(ctx context.Context, base, head string) (int, error) {
var compare struct {
BehindBy *int `json:"behind_by"`
}
if err := hub.api(ctx, "compare/"+base+"..."+head, &compare); err != nil {
return 0, err
}
if compare.BehindBy == nil {
return 0, fmt.Errorf("gh api compare/%s...%s: no behind_by", base, head)
}
return *compare.BehindBy, nil
}

// statuses is every status ever posted on `sha`, newest first.
func (hub github) statuses(ctx context.Context, sha string) ([]verify.Status, error) {
var statuses []verify.Status
Expand Down
21 changes: 19 additions & 2 deletions scripts/cilocal/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
// (.claude/skills/github-prs). It never waits: a PR that is a draft, not
// attested on its head, failing, pending or conflicting is reported with the
// next step and left alone (verify.Decide), so one stuck PR never holds up
// the others; a head behind main merges unless it conflicts. Before merging a
// the others. A head behind its base is refused (rebase and re-attest), so
// what merges is exactly the tree that was verified. Before merging a
// PR it retargets to main every open PR stacked on its branch, so the stack
// survives.
//
Expand Down Expand Up @@ -137,9 +138,15 @@ func mergeOne(ctx context.Context, hub github, number int, opts mergeFlags) (ver
if err != nil {
return verify.Verdict{}, err
}
behind := 0
if pull.State == "OPEN" {
if behind, err = hub.behind(ctx, pull.BaseRefName, pull.HeadRefOid); err != nil {
return verify.Verdict{}, err
}
}
verdict := verify.Decide(verify.Pull{
Number: number, State: pull.State, Draft: pull.IsDraft, Base: pull.BaseRefName, Mergeable: pull.Mergeable,
Checks: pull.Checks, Verification: verification,
Behind: behind, Checks: pull.Checks, Verification: verification,
}, opts.options)
if verdict.Action != verify.ActionMerge {
return verdict, nil
Expand All @@ -151,6 +158,16 @@ func mergeOne(ctx context.Context, hub github, number int, opts mergeFlags) (ver
if opts.dryRun {
return verify.Verdict{Action: verify.ActionMerge, Reason: "would merge " + verify.Short(pull.HeadRefOid) + " (dry run)", Next: "", Note: ""}, nil
}
// The base may have moved since it was read: read it once more right
// before the merge, which leaves only GitHub's own instant for a race.
if behind, err := hub.behind(ctx, pull.BaseRefName, pull.HeadRefOid); err != nil {
return verify.Verdict{}, err
} else if behind > 0 {
return verify.Decide(verify.Pull{
Number: number, State: pull.State, Draft: pull.IsDraft, Base: pull.BaseRefName, Mergeable: pull.Mergeable,
Behind: behind, Checks: pull.Checks, Verification: verification,
}, opts.options), nil
}
// Squash exactly the head that was attested; never --delete-branch (it
// closes the PRs stacked on the branch).
if _, err := output(ctx, "", "gh", "pr", "merge", strconv.Itoa(number), "-R", hub.repo, "--squash", "--match-head-commit", pull.HeadRefOid); err != nil {
Expand Down
Loading
Loading