ci: split the docs job so only deploy holds contents: write - #3
Merged
Conversation
Build and deploy shared one job, gated at the step level with `if: github.event_name != 'pull_request'`. Step gating decides which steps RUN; it does not change the token the job holds. So the pull request build really did run with `contents: write` -- which is exactly where third-party code runs, a dependency resolved during the build or an action at a floating tag, and it has no use for a token that can push to gh-pages. The job is split in two. `build` keeps `contents: read` and runs on every event, proving `mkdocs build --strict` still passes. `deploy` carries `contents: write` alone and is gated on the same condition that used to sit on the "Configure git" step, so what publishes and when is unchanged. No artifact crosses between the jobs, and none needs to: `mike deploy` runs `mkdocs build` itself and commits its own output to gh-pages, so the site/ the build job produces was already discarded before this split. The build job is the gate, the deploy job publishes -- the same division of labour the single job had, now with a permission boundary between them. The site is built twice on a push, which is the price of publishing byte-for-byte what was published before. The deploy job also takes a concurrency group. `mike deploy --push` pushes gh-pages, and pushing main and a tag together triggers two runs that would race, the loser failing with "! [rejected] gh-pages -> gh-pages (fetch first)". cancel-in-progress stays false: making a publish wait beats killing one part way through. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
tannevaled
force-pushed
the
least-privilege-split-docs-job
branch
from
August 31, 2026 21:59
16d12ce to
9531649
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Last live exposure from the fleet-wide least-privilege Pages sweep. This repo is one of 18 whose
docs.ymlran build and deploy in a single job, gated only at the step level withif: github.event_name != 'pull_request'.Step gating decides which steps run. It does not change the token the job holds. So unlike the other 545 repos in the sweep -- where the concern was latent, because a job boundary already separated build from deploy -- here the pull request build genuinely ran holding
contents: write.The split
build--contents: read, runs on every event, provesmkdocs build --strictstill passes.deploy-- holdscontents: writealone,needs: build, gated ongithub.event_name != 'pull_request': the exact condition that used to sit on the "Configure git" step, lifted to the job. What publishes, and when, is unchanged.The two
mike deploysteps keep their ownif:conditions verbatim, so the branch-vs-tag behaviour is untouched.No artifact crosses between the jobs, and none needs to
mike deployrunsmkdocs builditself and commits its own output togh-pages. Thesite/thatmkdocs build --strictproduced was already thrown away before this split -- it was a validation build, never the published one. So the build job is the gate and the deploy job publishes, exactly the division of labour the single job had, now with a permission boundary between them.The cost is that the site is built twice. That is deliberate: it is what keeps the published output byte-for-byte identical to what was published before.
Concurrency group on the deploy job
mike deploywrites thegh-pagesbranch over the network. This workflow triggers on bothpush: branches: [main]andpush: tags: ["v*"], so publishing a release sends both a branch update and a tag update, starting two runs that race -- the loser failing outright with! [rejected] gh-pages -> gh-pages (fetch first).cancel-in-progressstaysfalsedeliberately: making a publish wait is better than killing one part way through.Verification
Nothing changed but the structure and the two permission keys -- asserted by parsing both files and comparing the step lists element by element, not by reading the diff. The published
gh-pagestree is compared before and after by tree sha, so a split that silently stopped publishing, or published something different, shows up as a changed tree rather than as a green check.