diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29f3927..9da6e44 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -147,12 +147,12 @@ jobs: # would have dropped the older release from the file for good. # # Pushing it directly fixes that, but ordering matters. Tag first - # and main ends one commit ahead of the tag, which quietly breaks - # the docs: sphinx-docs.yml only deploys after a release when - # `git describe --exact-match` succeeds, and it no longer would. - # Committing first keeps main and the tag on the same commit, and - # has the tagged tree contain its own changelog, which is what a - # reader of the tag expects anyway. + # and main ends one commit ahead of the tag. Committing first + # keeps main and the tag on the same commit, and has the tagged + # tree contain its own changelog, which is what a reader of the + # tag expects anyway. (The API reference used to depend on this + # too, deploying only when main's tip was exactly a tag; it now + # builds from the tag by name, in the docs job below.) git add CHANGELOG.md git commit -m "chore(release): ${VERSION#v}" git tag -a "$VERSION" -m "$VERSION" @@ -246,6 +246,29 @@ jobs: - uses: pypa/gh-action-pypi-publish@release/v1 + # Publish the API reference at the released version, and only once the + # wheel is on PyPI. The Sphinx workflow used to deploy on its own, from the + # push of the release commit, which runs in parallel with the build and + # publish jobs above: a failed publish left the reference one version ahead + # of what `pip install tetrak` gave. Needing `publish` makes that order + # explicit. The called workflow runs under this push's ref, so the + # github-pages environment's main-only branch policy admits the deploy + # while the build itself checks out the tag. + # + # The permissions are the called workflow's: a reusable workflow cannot + # hold more than its caller grants. + docs: + name: Publish the API reference + needs: [release, publish] + if: needs.release.outputs.released == 'true' + permissions: + contents: read + pages: write + id-token: write + uses: ./.github/workflows/sphinx-docs.yml + with: + tag: ${{ needs.release.outputs.version }} + # Which install targets need an SBOM, read from pyproject.toml rather than # written down here. Adding an extra publishes its SBOM with no workflow # edit, which is the point: a hand-maintained list is one release away from diff --git a/.github/workflows/sphinx-docs.yml b/.github/workflows/sphinx-docs.yml index 3a20a43..209e905 100644 --- a/.github/workflows/sphinx-docs.yml +++ b/.github/workflows/sphinx-docs.yml @@ -1,5 +1,25 @@ name: Sphinx docs +# Two jobs in one file: a build check, and a deploy that only Release (or a +# hand-run dispatch) can start. +# +# The push and pull_request paths build the reference and stop. They used to +# deploy as well, and that published whatever version hatch-vcs derived from +# the commit under test. A merge that cuts no release (chore, ci, docs, test) +# lands an untagged commit, which hatch-vcs honestly versions as X.Y.Z.devN +# -- so after the first post-split chore merge the page read "tetrak +# 5.14.2.dev2 documentation" with nothing due to overwrite it until the next +# release. +# +# Deploying from a tagged commit was the first fix, and not enough: Release +# pushes its tag before it builds and publishes the wheel, so a deploy +# triggered by that push could run while publication was still pending, and +# would leave the reference ahead of PyPI if publication failed. The deploy +# is therefore a job in release.yml, run after the publish job succeeds, +# which calls this workflow with the tag it just released. The published +# reference then matches the version that is on PyPI, because it cannot +# deploy before that is true. + on: push: branches: [main] @@ -11,28 +31,41 @@ on: # workflow filtered out by path never starts, so never reports, and leaves # the pull request blocked. pull_request: - # There was a `workflow_run: [Release]` trigger here, because Release used - # to push with GITHUB_TOKEN, which by design never retriggers `push` - # workflows -- so the push above always built one commit before the tag - # existed and the published version trailed permanently. + # Release calls this after the wheel is on PyPI. The caller's event is its + # push to main, so the run deploys under refs/heads/main -- the only ref + # the github-pages environment's branch policy admits -- while building + # from the tag. + workflow_call: + inputs: + tag: + description: The release tag to build and deploy + required: true + type: string + # A redeploy by hand, for a release whose docs job was skipped or failed: + # + # gh workflow run sphinx-docs.yml --ref main -f tag=5.14.1 # - # Release now pushes as the `scattercode-release` App, whose token is a - # real identity and does trigger `push`. Its commit is the tagged commit, - # so the push path above builds at the tag and publishes a clean version. - # Keeping workflow_run as well would deploy the same commit twice per - # release, serialised through the `pages` concurrency group for no gain. + # The tag is an input rather than the ref for the same reason: a dispatch + # against the tag itself builds the right thing and is then refused by the + # environment, which was verified the hard way. workflow_dispatch: + inputs: + tag: + description: The release tag to build and deploy (for example 5.14.1) + required: true + type: string permissions: contents: read pages: write id-token: write -# Two regimes in one expression. Deploying runs (push, dispatch) keep -# the original serialised `pages` group with no -# cancellation, so a deploy is never killed mid-flight. Pull-request -# builds deploy nothing and get a per-ref group with cancellation, so a -# review-fix push stops the superseded build instead of paying for it. +# Two regimes in one expression. Deploying runs keep the original +# serialised `pages` group with no cancellation, so a deploy is never killed +# mid-flight. Pull-request builds deploy nothing and get a per-ref group with +# cancellation, so a review-fix push stops the superseded build instead of +# paying for it. (A run called from Release also sits in Release's own +# `release` group, which already serialises releases.) concurrency: group: ${{ github.event_name == 'pull_request' && format('sphinx-pr-{0}', github.ref) || 'pages' }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} @@ -48,6 +81,9 @@ jobs: steps: - uses: actions/checkout@v7 with: + # The tag when deploying; empty on push and pull_request, which + # actions/checkout reads as "the commit that triggered the run". + ref: ${{ inputs.tag }} # hatch-vcs derives the version from `git describe --tags`. The # default shallow clone has no tags reachable, so conf.py's # `tetrak_ocr._version` falls back to setuptools_scm's "no tag @@ -62,18 +98,26 @@ jobs: - name: Install the package and Sphinx toolchain run: pip install -e '.[apidocs]' + # The input could be a branch name or a typo, and actions/checkout + # would check either out without complaint. The build has to report + # exactly the version asked for, or the deploy is refused. + - name: Check the build reports the tag it was asked for + if: inputs.tag != '' + env: + TAG: ${{ inputs.tag }} + run: | + set -euo pipefail + git describe --exact-match --tags HEAD + python -c "import os, tetrak_ocr as t; v = os.environ['TAG'].removeprefix('v'); assert t.__version__ == v, (t.__version__, v); print('building', t.__version__)" + - name: Build run: sphinx-build -W -b html docs docs/_build/html - uses: actions/configure-pages@v6 - if: >- - (github.event_name == 'push' && github.ref == 'refs/heads/main') || - github.event_name == 'workflow_dispatch' + if: inputs.tag != '' - uses: actions/upload-pages-artifact@v5 - if: >- - (github.event_name == 'push' && github.ref == 'refs/heads/main') || - github.event_name == 'workflow_dispatch' + if: inputs.tag != '' with: path: docs/_build/html @@ -85,13 +129,7 @@ jobs: # 'true', and silently disabled every post-release deploy -- the exact # path that exists to publish the docs at a tag rather than one commit # past it. Nothing failed; the docs just stopped updating after releases. - # - # workflow_dispatch deploys too. Recovering from a skipped release deploy - # otherwise means waiting for the next release, which is a long way round - # for a page that is already wrong. - if: >- - (github.event_name == 'push' && github.ref == 'refs/heads/main') || - github.event_name == 'workflow_dispatch' + if: inputs.tag != '' runs-on: ubuntu-latest environment: name: github-pages diff --git a/CLAUDE.md b/CLAUDE.md index f9505fc..d52b905 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -334,7 +334,8 @@ here, and the brief's status in `tetrak-product`. Cloudflare Pages builds the site itself on every push to `main`, so nothing here deploys. - `sphinx-docs.yml` — builds the `docs/` Sphinx site on every push and PR as a - check; deploys to GitHub Pages only on push to `main`. See Deployment below. + check. It deploys to GitHub Pages only when called by `release.yml` with a + tag, after the wheel is on PyPI. See Deployment below. - `pr-title.yml` — the pull request title must be a Conventional Commit, since squash-merging makes it the commit on `main` that the release reads. - `release.yml` — see below. @@ -352,7 +353,18 @@ every push to `main`. No manual step is required. The Sphinx CLI/API reference in `docs/` publishes separately, to GitHub Pages at `https://scattercode.github.io/tetrak/`, via -`.github/workflows/sphinx-docs.yml` on every push to `main`. It is scoped +`.github/workflows/sphinx-docs.yml`. Every push to `main` builds it as a +check, but nothing deploys from that path: `release.yml` calls the workflow +with the new tag as the last step of a release, after the publish job, so the +published reference matches the version that is on PyPI. Deploying from the +push itself used to publish an honest but unreleased `X.Y.Z.devN` title after +any merge that cut no release (`chore`, `ci`, `docs`, `test`), which is what +the page showed after the first post-split chore merge. So a change under +`docs/` reaches the published reference with the next release, not before. +To redeploy by hand, dispatch from `main` with the tag as an input +(`gh workflow run sphinx-docs.yml --ref main -f tag=5.14.1`): the +`github-pages` environment admits deployments from `main` only, so a dispatch +against the tag ref builds correctly and is then refused. It is scoped strictly to the CLI and Python API reference; narrative content stays on the Hugo site. @@ -456,6 +468,9 @@ Releases are automated — do not perform them by hand. `tetrak`, the import package `tetrak_ocr` and the command `tetrak-ocr` — install instructions and error messages say `pip install tetrak`, never `tetrak-ocr`, which is a name we do not own. +- Once the wheel is published, `release.yml` calls `sphinx-docs.yml` with the + tag to deploy the API reference at that version. The reference never + deploys from a plain push to `main`. - Never edit `CHANGELOG.md` by hand — change the commit messages or the `commit_parsers` in `cliff.toml` instead. - Never create tags or Releases manually.