diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 45154c5..ca53a0f 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -109,7 +109,8 @@ jobs: # not ask must not overwrite that release's results with another tier. if: needs.benchmark.outputs.measured == 'true' && (github.event_name == 'push' || inputs.publish) runs-on: ubuntu-latest - timeout-minutes: 15 + # 15 for the commit, and the 30 the notes step may wait for the release. + timeout-minutes: 45 continue-on-error: true permissions: contents: write # push to main, and edit the release notes @@ -147,8 +148,12 @@ jobs: done echo "could not push benchmark results"; exit 1 - # Best effort, and last: releases here are cut by hand, so this job may - # well run before one exists. The docs page is authoritative either way. + # Best effort, and last. publish.yml creates the release once PyPI has + # the version, normally before this job gets here, but only by 7 to 13 + # minutes (0.17.4 to 0.17.6): slow tests or a re-run in Publish would + # leave no release yet. So it waits up to 30 minutes for one; a failed + # publish leaves none. The docs page is authoritative either way, and + # re-running this job appends the summary later. - name: Append to the release notes if: github.ref_type == 'tag' continue-on-error: true @@ -156,8 +161,12 @@ jobs: GH_TOKEN: ${{ github.token }} TAG: ${{ github.ref_name }} run: | + for _ in $(seq 30); do + gh release view "$TAG" >/dev/null 2>&1 && break + sleep 60 + done gh release view "$TAG" >/dev/null 2>&1 || { - echo "no release for $TAG yet; skipping"; exit 0 + echo "no release for $TAG after 30 minutes; skipping"; exit 0 } gh release view "$TAG" --json body -q .body > "$RUNNER_TEMP/body.md" # Idempotent: replace any block this job wrote before. diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 91ac888..37dd103 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,14 +4,16 @@ name: Publish # # What a run publishes, by how it started: # -# a pushed tag PyPI, then the image +# a pushed tag PyPI, then the image and the +# GitHub release # workflow_dispatch, target testpypi TestPyPI only, from any ref -# workflow_dispatch, target pypi PyPI, then the image; from a tag -# only, as check-version refuses a -# branch +# workflow_dispatch, target pypi PyPI, then the image and the +# release; from a tag only, as +# check-version refuses a branch # -# Nothing publishes unless the suite passed, and nothing reaches PyPI or -# quay.io unless the tag matches pyproject.toml. +# Nothing publishes unless the suite passed, and nothing reaches PyPI, +# quay.io or the releases page unless the tag matches pyproject.toml and +# docs/changelog.md has a section for it. on: push: tags: ["*"] @@ -59,6 +61,22 @@ jobs: exit 1 fi echo "version=$declared" >> "$GITHUB_OUTPUT" + # The GitHub release's notes are this section, so check it before + # anything is published rather than after: once PyPI has the version + # the tag cannot change, and no re-run could mend the notes. The + # extraction is the one github-release uses. + - name: The changelog must have a section for the tag + id: changelog + env: + TAG: ${{ github.ref_name }} + run: | + awk -v tag="$TAG" \ + '$0 == "## " tag { on = 1; next } on && /^## / { exit } on' \ + docs/changelog.md > notes.md + if ! grep -q '[^[:space:]]' notes.md; then + echo "::error::docs/changelog.md has no '## $TAG' section with text" + exit 1 + fi test: uses: ./.github/workflows/tests.yml # zizmor: ignore[self-repository] actionlint 1.7 predates $/ @@ -135,3 +153,37 @@ jobs: secrets: QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} + + # Releases were cut by hand with `gh release create` until 0.11.1. The + # checklist never named that step, so later tags were published with no + # release page and backfilled by hand. Running after PyPI means a release + # never announces a version pip cannot install. A release already cut by + # hand is left alone. + github-release: + needs: [check-version, publish-pypi] + runs-on: ubuntu-latest + permissions: + contents: write # create the release + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - name: Notes from the changelog + id: notes + env: + TAG: ${{ needs.check-version.outputs.version }} + run: | + awk -v tag="$TAG" \ + '$0 == "## " tag { on = 1; next } on && /^## / { exit } on' \ + docs/changelog.md > notes.md + grep -q '[^[:space:]]' notes.md + - name: Create the release + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TAG: ${{ needs.check-version.outputs.version }} + run: | + if gh release view "$TAG" >/dev/null 2>&1; then + echo "release $TAG already exists"; exit 0 + fi + gh release create "$TAG" --verify-tag --title "$TAG" --notes-file notes.md diff --git a/AGENTS.md b/AGENTS.md index 177b73a..482c268 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -309,20 +309,23 @@ an item to Released when its tag is out. - entries that start with a bold one-line lead and an issue link. - Merge the release branch, then push a tag with no `v` prefix. The tag triggers: - - `publish.yml`, which checks that the tag matches pyproject, tests - (`tests.yml`, including a build and smoke test of the Docker image), - builds and publishes to PyPI, then calls `quay-on-tag.yml` to build the - image, check that it runs, and push that image to - `quay.io/cellgeni/adata-cli`. If the tests fail or the tag does not - match, nothing is published. `:latest` moves only to the highest - `X.Y.Z` tag; + - `publish.yml`, which checks that the tag matches pyproject and has a + changelog section, tests (`tests.yml`, including a build and smoke test + of the Docker image), builds and publishes to PyPI. Then, side by side, + it calls `quay-on-tag.yml` to build the image, check that it runs, and + push that image to `quay.io/cellgeni/adata-cli`, and creates the GitHub + release with the changelog section as its notes (a failed image does + not hold it back). If the tests fail or a check does not pass, nothing + is published. `:latest` moves only to the + highest `X.Y.Z` tag. Don't create the release by hand: that step was + missed from 0.12.0 on, and releases had to be backfilled; - `benchmark.yml`, which reruns `benchmarks/` and commits the results to - `docs/reference/benchmarks.md` and `docs/benchmarks/.json`. The job - that measures has a read-only token; the one that commits installs - nothing. + `docs/reference/benchmarks.md` and `docs/benchmarks/.json`, and + appends a summary to the release notes. The job that measures has a + read-only token; the one that commits installs nothing. - A manual `Publish` dispatch to `testpypi` publishes there alone, from any - ref. One to `pypi` publishes, and pushes the image, only when run from a - tag; from a branch it fails. + ref. One to `pypi` publishes, pushes the image and creates the release, + only when run from a tag; from a branch it fails. - Workflows pin third-party actions by commit SHA, with the version in a comment, and pass tags and inputs to scripts through `env:`. `tests/test_release_pipeline.py` and the `workflow lint` job check both. diff --git a/STATUS.md b/STATUS.md index 127a475..d4296b5 100644 --- a/STATUS.md +++ b/STATUS.md @@ -33,6 +33,14 @@ theirs. ## Follow-ups noticed +- GitHub releases stopped at 0.11.1: they were cut by hand, and the release + checklist never said so. PyPI, quay and the benchmark page were unaffected. + `publish.yml` now creates the release from the changelog section (#114). + 0.12.0 to 0.17.6 were backfilled by hand from the changelog plus each + tag's benchmark artifact; the next tag is the first end-to-end check. + GitHub renders each newline in a release body as a line break, so the + changelog's wrapped lines show ragged there; unwrapping paragraphs when + the notes are extracted would fix it (review of #114). - From waves 3 and 4 of the audit fixes: - The streaming transpose and other users of `csr_build.BucketSorter` append every input block to every bucket, (nnz/chunk)² appends, and diff --git a/docs/developers.md b/docs/developers.md index bfb6448..17d5847 100644 --- a/docs/developers.md +++ b/docs/developers.md @@ -261,17 +261,20 @@ It reports and never gates; the complexity guards gate. paragraph, then whichever of `### Added`, `### Changed` and `### Fixed` apply, each entry led by a bold line and an issue link. 4. Merge, then push a tag with no `v` prefix. The tag runs `publish.yml`, - which checks the tag against `pyproject.toml`, tests (`tests.yml`, - including a build and smoke test of the image), publishes to PyPI, then - calls `quay-on-tag.yml` to build the image, check that it runs, and push - that image. If the tests fail or the tag does not match, nothing is - published. `:latest` moves only to the highest `X.Y.Z` tag. The tag also - runs `benchmark.yml` (the benchmark page), whose measuring job has a - read-only token; the job that commits the results installs nothing. + which checks the tag against `pyproject.toml` and `docs/changelog.md`, + tests (`tests.yml`, including a build and smoke test of the image), + publishes to PyPI. Then, side by side, it calls `quay-on-tag.yml` to + build the image, check that it runs, and push that image, and creates + the GitHub release from the changelog section. If the tests fail or a check does not pass, + nothing is published. `:latest` moves only to the highest `X.Y.Z` tag. + Don't create the release by hand. The tag also runs `benchmark.yml` (the + benchmark page, which it also appends to the release notes), whose + measuring job has a read-only token; the job that commits the results + installs nothing. A manual `Publish` dispatch to TestPyPI publishes there alone, from any ref; -one to PyPI publishes, and pushes the image, only when run from a tag, and -fails from a branch. +one to PyPI publishes, pushes the image and creates the release, only when +run from a tag, and fails from a branch. Workflows pin third-party actions by commit SHA, with the version in a comment, and pass tags and inputs to scripts through `env:`. `tests/test_release_pipeline.py` and the `workflow lint` job check both. diff --git a/tests/test_release_pipeline.py b/tests/test_release_pipeline.py index 597a345..3cc8182 100644 --- a/tests/test_release_pipeline.py +++ b/tests/test_release_pipeline.py @@ -100,16 +100,16 @@ def result(name): return results -PUBLISHERS = {"publish-testpypi", "publish-pypi", "image"} +PUBLISHERS = {"publish-testpypi", "publish-pypi", "image", "github-release"} TAG = "refs/tags/0.17.5" @pytest.mark.parametrize( "event, ref, target, failing, published", [ - ("push", TAG, None, (), {"publish-pypi", "image"}), + ("push", TAG, None, (), {"publish-pypi", "image", "github-release"}), ("workflow_dispatch", TAG, "testpypi", (), {"publish-testpypi"}), - ("workflow_dispatch", TAG, "pypi", (), {"publish-pypi", "image"}), + ("workflow_dispatch", TAG, "pypi", (), {"publish-pypi", "image", "github-release"}), ("workflow_dispatch", "refs/heads/main", "testpypi", (), {"publish-testpypi"}), # check-version refuses a branch, so the run fails rather than pass. ("workflow_dispatch", "refs/heads/main", "pypi", ("check-version",), set()), @@ -117,11 +117,14 @@ def result(name): ("push", TAG, None, ("check-version",), set()), ("push", TAG, None, ("build",), set()), ("push", TAG, None, ("publish-pypi",), set()), + # PyPI has the version by then, so the release still announces it. + ("push", TAG, None, ("image",), {"publish-pypi", "github-release"}), ], ids=[ "tag", "testpypi-dispatch-from-tag", "pypi-dispatch-from-tag", "testpypi-dispatch-from-branch", "pypi-dispatch-from-branch", "tests-fail", "tag-is-not-the-version", "build-fails", "pypi-upload-fails", + "image-fails", ], ) def test_each_run_publishes_exactly_what_passed(event, ref, target, failing, published): @@ -182,6 +185,59 @@ def test_check_version_passes_only_a_tag_that_names_the_version( assert output.read_text() == f"version={declared}\n" +@pytest.mark.parametrize( + "heading, ok", + [ + ("## 0.17.5\n\nText.\n", True), + ("## 0.17.4\n\nText.\n", False), + ("## 0.17.5 (soon)\n\nText.\n", False), + ("## 0.17.5\n\n## 0.17.4\n\nText.\n", False), + ("## 0.17.5\n", False), + ], + ids=["has-the-section", "no-section", "heading-is-not-the-tag", "section-is-empty", "heading-ends-the-file"], +) +def test_check_version_refuses_a_tag_the_changelog_does_not_cover(tmp_path, heading, ok): + """The release's notes are the tag's changelog section, so a tag with + none, or with no text in it, is refused before anything is published: + once PyPI has the version the tag cannot change to mend the notes.""" + (tmp_path / "docs").mkdir() + (tmp_path / "docs" / "changelog.md").write_text(f"# Changelog\n\n{heading}") + done = _bash( + _script("publish.yml", "check-version", "changelog"), tmp_path, TAG="0.17.5", + ) + assert (done.returncode == 0) == ok, done.stdout + done.stderr + + +def test_the_release_notes_are_the_tags_changelog_section(tmp_path): + """GitHub releases stopped at 0.11.1: they were cut by hand and the + checklist never said so. publish.yml now writes the notes from the + changelog, the tag's section alone.""" + (tmp_path / "docs").mkdir() + (tmp_path / "docs" / "changelog.md").write_text( + "# Changelog\n\n## 0.17.6\n\nNewer.\n\n## 0.17.5\n\nThis one.\n\n" + "### Fixed\n\n- **A fix**.\n\n## 0.17.4\n\nOlder.\n" + ) + script = _script("publish.yml", "github-release", "notes") + + done = _bash(script, tmp_path, TAG="0.17.5") + assert done.returncode == 0, done.stdout + done.stderr + assert (tmp_path / "notes.md").read_text() == "\nThis one.\n\n### Fixed\n\n- **A fix**.\n\n" + + # A tag the changelog lacks gives empty notes, and the job fails. + assert _bash(script, tmp_path, TAG="0.17.9").returncode != 0 + + +def test_the_real_changelog_gives_notes_for_its_newest_release(tmp_path): + (tmp_path / "docs").mkdir() + changelog = (ROOT / "docs" / "changelog.md").read_text() + (tmp_path / "docs" / "changelog.md").write_text(changelog) + newest = re.search(r"^## (\S+)$", changelog, re.M)[1] + done = _bash(_script("publish.yml", "github-release", "notes"), tmp_path, TAG=newest) + assert done.returncode == 0, done.stdout + done.stderr + notes = (tmp_path / "notes.md").read_text() + assert notes.strip() and "\n## " not in notes + + def test_the_image_is_pushed_only_from_publish(): """F143: quay-on-tag.yml ran on every tag by itself until 0.17.4.""" assert set(_load("quay-on-tag.yml")["on"]) == {"workflow_call"}