From eddf76d9ec98c2fcb76ea0338076ca98bbf2be4b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 14:53:18 +0000 Subject: [PATCH] One release pipeline: publishing a GitHub Release does the rest (D6) - .github/workflows/release.yml: on a published release, build the wheel and sdist from the tag, check them, install the wheel in a clean venv, upload to PyPI with Trusted Publishing (OIDC, environment 'pypi', no token), attach them to the release and fill empty release notes from CHANGELOG.md. Dry run on PRs touching packaging, or by hand. - scripts/release/check_release.py: tag = v, dated CHANGELOG section and compare link, docs badge, wheel top level / GUI data files / no CRLF, sdist without desktop build output. Writes the release notes. Tests in tests/test_release_check.py. - RELEASING.md: the release PR, the one button, what to do if a step fails, and the one-time PyPI trusted publisher setup. Linked from CONTRIBUTING.md. - Download page: what each version (web, desktop, pip) can do. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 134 +++++++++++++++++++++++++ CHANGELOG.md | 9 ++ CONTRIBUTING.md | 1 + RELEASING.md | 71 ++++++++++++++ docs/download.md | 20 ++++ scripts/release/check_release.py | 163 +++++++++++++++++++++++++++++++ tests/test_release_check.py | 141 ++++++++++++++++++++++++++ 7 files changed, 539 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 RELEASING.md create mode 100644 scripts/release/check_release.py create mode 100644 tests/test_release_check.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..53b6ec5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,134 @@ +name: Release + +# One release pipeline (roadmap D6). Publishing a GitHub Release is the only manual step: +# +# 1. build: build the wheel and sdist from the tagged commit, run +# scripts/release/check_release.py (tag = v, dated CHANGELOG section, docs +# badge, wheel contents: G-011, G-012, G-032), and install the wheel in a clean venv. +# 2. pypi: upload to PyPI with Trusted Publishing (OIDC, no token anywhere). Needs the +# trusted publisher set up on pypi.org once (see RELEASING.md). +# 3. release-files: attach the wheel and sdist to the GitHub Release, and fill in its +# notes from CHANGELOG.md if they were left empty. +# +# desktop-builds.yml attaches the desktop installers on the same event, and docs.yml has +# already deployed the website when the release PR was merged. +# +# On a pull request that touches packaging, or run by hand (Actions → Release → Run +# workflow), it is a dry run: build and check only. +on: + release: + types: [published] + # Dry run (build and check only) when the packaging or this pipeline changes. + pull_request: + paths: + - "pyproject.toml" + - "scripts/release/**" + - ".github/workflows/release.yml" + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +jobs: + build: + name: Build and check + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-python@v7 + with: + python-version: "3.12" + + - name: Build the wheel and sdist + run: | + python -m pip install --upgrade pip build + python -m build + + - name: Check the release + env: + TAG: ${{ github.event.release.tag_name }} + run: | + python scripts/release/check_release.py --dist dist --notes build/release-notes.md \ + ${TAG:+--tag "$TAG"} + + - name: Install the wheel in a clean environment + run: | + python -m venv /tmp/clean + /tmp/clean/bin/pip install dist/*.whl + cd /tmp + /tmp/clean/bin/eagleplot --version + /tmp/clean/bin/python -I -c " + import eagleplot, pathlib + from eagleplot.io import load_data + root = pathlib.Path(eagleplot.__file__).parent + data = load_data(str(root / 'example-data' / 'Artificial' / 'sine_cosine_waves.csv')) + assert data.shape[0] > 0, data.shape + print('EaglePlot', eagleplot.__version__, 'installed from the wheel and loads data') + " + + - uses: actions/upload-artifact@v7 + with: + name: release-dist + path: | + dist/ + build/release-notes.md + if-no-files-found: error + + pypi: + name: Publish to PyPI + needs: build + if: github.event_name == 'release' + runs-on: ubuntu-24.04 + environment: + name: pypi + url: https://pypi.org/project/eagleplot/ + permissions: + id-token: write # Trusted Publishing: PyPI accepts this job's identity, no token + steps: + - uses: actions/download-artifact@v8 + with: + name: release-dist + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ + # A version already on PyPI (e.g. uploaded by hand) is left alone, not an error. + skip-existing: true + + release-files: + name: Attach files and notes to the release + needs: build + if: github.event_name == 'release' + runs-on: ubuntu-24.04 + permissions: + contents: write + steps: + - uses: actions/download-artifact@v8 + with: + name: release-dist + + - name: Attach the wheel and sdist + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TAG: ${{ github.event.release.tag_name }} + run: gh release upload "$TAG" dist/* --clobber + + - name: Fill in empty release notes from CHANGELOG.md + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TAG: ${{ github.event.release.tag_name }} + run: | + body=$(gh release view "$TAG" --json body --jq .body) + if [ -z "${body//[[:space:]]/}" ]; then + gh release edit "$TAG" --notes-file build/release-notes.md + echo "Release notes filled in from CHANGELOG.md" + else + echo "Release notes already written; left as they are" + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index c747e1f..3eee2cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Added + +- **Releases are published by GitHub Actions** (`.github/workflows/release.yml`). Publishing + a GitHub Release builds the package from the tag, checks it, uploads it to PyPI (Trusted + Publishing, no stored token), attaches the files and installers to the release, and fills + in the release notes from this changelog. How to make a release: `RELEASING.md`. +- **The Download page compares the three versions** (web app, desktop app, Python package): + install, download size, offline use, speed, folders, NIST and the Python API. + ### Changed - The Download page no longer has a code signing policy for the SignPath Foundation (the diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 56066f9..4ae2efc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,6 +52,7 @@ MPLBACKEND=Agg pytest tests/ - **Follow the conventions of the module you are editing**, and give public functions a NumPy-style docstring with Parameters and Returns sections. - **Update `CHANGELOG.md`** under `## [Unreleased]` for anything a user would notice. +- Releases are made by the maintainers: see [RELEASING.md](RELEASING.md). ## Pull requests diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..3978b28 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,71 @@ +# Releasing EaglePlot + +A release is one pull request and one button. Everything else runs in GitHub Actions: + +| Workflow | On a published release it… | +| --- | --- | +| [`release.yml`](.github/workflows/release.yml) | builds the wheel and sdist from the tag, checks them ([`scripts/release/check_release.py`](scripts/release/check_release.py)), uploads them to PyPI (Trusted Publishing: no token), attaches them to the release, and fills in empty release notes from `CHANGELOG.md` | +| [`desktop-builds.yml`](.github/workflows/desktop-builds.yml) | builds the Windows, macOS and Linux installers and attaches them (about 15 minutes) | +| [`docs.yml`](.github/workflows/docs.yml) | already deployed the website and web app when the release PR was merged | + +## 1. The release pull request + +On a branch: + +1. `eagleplot/__init__.py`: set `__version__` to the new version ([semver](https://semver.org/)). +2. `docs/index.html`: the version badge (`nav__badge`) shows the same version. +3. `CHANGELOG.md`: rename `## [Unreleased]` to `## [X.Y.Z] - YYYY-MM-DD` (add a short + summary paragraph), start a new empty `## [Unreleased]` above it, and update the compare + links at the end (`[Unreleased]` → `vX.Y.Z...HEAD`, new `[X.Y.Z]` → `vPREVIOUS...vX.Y.Z`). +4. Check it: + + ```bash + python scripts/release/check_release.py --tag vX.Y.Z + python -m build && python scripts/release/check_release.py --tag vX.Y.Z --dist dist + ``` + + Optionally run **Actions → Release → Run workflow** on the branch: a dry run that builds, + checks and installs the wheel without publishing anything. +5. Open the PR, wait for CI, merge. + +## 2. Publish the GitHub Release + +On GitHub: **Releases → Draft a new release**. + +- **Choose a tag:** type `vX.Y.Z` and pick *Create new tag: vX.Y.Z on publish*. Target: `main` + (check that its latest commit is the release PR's merge). +- **Title:** `EaglePlot X.Y.Z`. +- **Notes:** leave empty to have them filled in from `CHANGELOG.md`, or write your own. +- Click **Publish release**. *Save draft* publishes nothing and starts nothing. + +Then watch **Actions**: *Release* (about 2 minutes) and *Desktop builds* (about 15 minutes). +When both are green, the release page lists the wheel, the sdist and four installers, and +`pip install eagleplot==X.Y.Z` works. + +## If something fails + +- **The release check fails** (for example the tag doesn't match `__version__`): nothing has + been uploaded. Delete the release and its tag on GitHub, fix `main` with a PR, and publish + again. +- **PyPI upload fails:** re-run the failed job. A version already on PyPI is skipped, not + overwritten: PyPI never accepts the same version twice, so a broken upload needs a new + version (`X.Y.Z+1`). +- **A desktop installer fails:** re-run the failed job; it replaces the release's files. + +## One-time setup (done once per project) + +**PyPI Trusted Publishing.** On [pypi.org](https://pypi.org/manage/project/eagleplot/settings/publishing/), +*Publishing → Add a new publisher → GitHub*: + +| Field | Value | +| --- | --- | +| Owner | `The-Schultz-Lab` | +| Repository name | `eagleplot` | +| Workflow name | `release.yml` | +| Environment name | `pypi` | + +PyPI API tokens are then no longer needed for releases; delete any that were only used for +uploading. + +**Optional:** in the repository's *Settings → Environments → pypi*, add yourself as a +required reviewer, so every PyPI upload waits for a click. diff --git a/docs/download.md b/docs/download.md index 01fe150..11c7345 100644 --- a/docs/download.md +++ b/docs/download.md @@ -9,6 +9,26 @@ There are three ways to use it. All three keep your data on your own computer. | **Desktop app** | Using EaglePlot offline, without installing Python | Windows, macOS and Linux installers on the [Releases page](https://github.com/The-Schultz-Lab/eagleplot/releases) (from version 3.2.0) | | **Python package** | Scripts, notebooks, and the full GUI | `pip install eagleplot` ([PyPI](https://pypi.org/project/eagleplot/)), then see [Getting Started](getting-started.html) | +## What each version can do + +All three are the same EaglePlot, with the same pages and plots, from the same release. + +| | Web app | Desktop app | Python package | +| --- | --- | --- | --- | +| Install | Nothing (or **Install** in Chrome/Edge) | Installer, no admin rights | Python 3.9+, `pip install eagleplot` | +| Download | About 45 MB on the first visit | About 190 MB | A few MB, plus its Python packages | +| Works offline | After one visit, once installed | Yes | Yes | +| Start-up | About 8 s | About 12 s | A few seconds | +| Speed of plots and fits | Slower (runs in WebAssembly) | Slower (runs in WebAssembly) | Full speed | +| Load a whole folder (Batch Import) | No | Yes | Yes | +| Fetch spectra from NIST | Links to NIST | Links to NIST | Yes (`pip install "eagleplot[nist]"`) | +| Change the app's theme | No | No | Yes | +| Python API, notebooks, `eagleplot` command | No | No | Yes | +| Settings and presets kept | In the browser | Yes | Yes | +| Data stays on your computer | Yes | Yes | Yes | + +The version number is shown on the Home page of all three. + ## Desktop app Download the file for your system from the [latest release](https://github.com/The-Schultz-Lab/eagleplot/releases/latest): diff --git a/scripts/release/check_release.py b/scripts/release/check_release.py new file mode 100644 index 0000000..b3efd1c --- /dev/null +++ b/scripts/release/check_release.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python3 +"""Check that a release is consistent before it is published (roadmap D6). + + python scripts/release/check_release.py [--tag vX.Y.Z] [--dist DIR] [--notes FILE] + +Checks, against the version in ``eagleplot/__init__.py``: + +- ``--tag``: the release tag is ``v``; +- ``CHANGELOG.md`` has a dated ``## [] - YYYY-MM-DD`` section and a compare link; +- the documentation site's version badge (``docs/index.html``) shows the version; +- ``--dist``: the built wheel and sdist (``python -m build``) are named for the version, + the wheel installs only the ``eagleplot`` package, ships the GUI's data files, and has + no Windows line endings; the sdist has no desktop-build output. + +``--notes FILE`` writes the version's CHANGELOG section to FILE (the GitHub Release +notes). Exits 1 and lists every problem found. ``.github/workflows/release.yml`` runs it +on each published release; run it locally before opening a release PR. +""" + +from __future__ import annotations + +import argparse +import re +import sys +import tarfile +import zipfile +from pathlib import Path +from typing import List, Optional + +ROOT = Path(__file__).resolve().parents[2] + +#: Files a pip-installed GUI needs (G-012: they once went missing from the wheel). +WHEEL_DATA_FILES = ( + "eagleplot/Home.py", + "eagleplot/pages/2_Quick_Plot.py", + "eagleplot/assets/logo.png", + "eagleplot/assets/logo.ico", + "eagleplot/assets/nccu-horiz-logo.png", + "eagleplot/example-data/Artificial/sine_cosine_waves.csv", +) +#: Never in the sdist: the desktop build's staging and output (packaging/desktop). +SDIST_FORBIDDEN = ("node_modules/", "packaging/desktop/build/", "packaging/desktop/dist/") + + +def package_version(root: Path = ROOT) -> str: + """``__version__`` from ``eagleplot/__init__.py``, read without importing it.""" + text = (root / "eagleplot" / "__init__.py").read_text(encoding="utf-8") + match = re.search(r'^__version__\s*=\s*"([^"]+)"', text, re.M) + if not match: + raise SystemExit("eagleplot/__init__.py has no __version__") + return match.group(1) + + +def changelog_section(changelog: str, version: str) -> Optional[str]: + """The body of ``## [version] - date`` in *changelog*, or ``None``.""" + heading = re.search( + rf"^## \[{re.escape(version)}\] - \d{{4}}-\d{{2}}-\d{{2}}[ \t]*$", changelog, re.M + ) + if not heading: + return None + rest = changelog[heading.end() :] + end = re.search(r"^## \[|^\[[^\]]+\]: http", rest, re.M) + body = rest[: end.start()] if end else rest + return body.strip().removesuffix("---").strip() + + +def check_sources(version: str, tag: Optional[str], root: Path = ROOT) -> List[str]: + """Problems with the tag, CHANGELOG and docs badge for *version*.""" + problems = [] + if tag is not None and tag != f"v{version}": + problems.append( + f"release tag {tag!r} doesn't match the package version: expected 'v{version}' " + "(bump eagleplot/__init__.py, or tag the right commit)" + ) + changelog = (root / "CHANGELOG.md").read_text(encoding="utf-8") + if changelog_section(changelog, version) is None: + problems.append( + f"CHANGELOG.md has no dated section '## [{version}] - YYYY-MM-DD' " + "(rename [Unreleased] when preparing the release)" + ) + if not re.search(rf"^\[{re.escape(version)}\]: https://", changelog, re.M): + problems.append(f"CHANGELOG.md has no compare link '[{version}]: https://…' at the end") + index = (root / "docs" / "index.html").read_text(encoding="utf-8") + badge = re.search(r'class="nav__badge">v([^ <&]+)', index) + if not badge or badge.group(1) != version: + found = badge.group(1) if badge else "none" + problems.append(f"docs/index.html version badge shows {found}, expected {version} (G-035)") + return problems + + +def check_dist(dist: Path, version: str) -> List[str]: + """Problems with the wheel and sdist in *dist*.""" + problems: List[str] = [] + wheels = sorted(dist.glob("*.whl")) + sdists = sorted(dist.glob("*.tar.gz")) + want_wheel = f"eagleplot-{version}-py3-none-any.whl" + want_sdist = f"eagleplot-{version}.tar.gz" + if [w.name for w in wheels] != [want_wheel]: + problems.append(f"{dist}: expected exactly {want_wheel}, found {[w.name for w in wheels]}") + if [s.name for s in sdists] != [want_sdist]: + problems.append(f"{dist}: expected exactly {want_sdist}, found {[s.name for s in sdists]}") + + if (dist / want_wheel).is_file(): + with zipfile.ZipFile(dist / want_wheel) as whl: + names = whl.namelist() + top = [n for n in names if n.endswith(".dist-info/top_level.txt")] + top_level = whl.read(top[0]).decode().split() if top else [] + if top_level != ["eagleplot"]: + problems.append( + f"wheel top_level.txt is {top_level}, expected ['eagleplot'] (G-011)" + ) + outside = sorted( + {n.split("/")[0] for n in names} - {"eagleplot", f"eagleplot-{version}.dist-info"} + ) + if outside: + problems.append(f"wheel installs files outside eagleplot/: {outside}") + missing = [f for f in WHEEL_DATA_FILES if f not in names] + if missing: + problems.append(f"wheel is missing GUI data files (G-012): {missing}") + crlf = [n for n in names if n.endswith(".py") and b"\r\n" in whl.read(n)] + if crlf: + problems.append( + f"{len(crlf)} .py files in the wheel have Windows line endings, e.g. " + f"{crlf[0]} (G-032: build from a clean checkout on Linux or CI)" + ) + + if (dist / want_sdist).is_file(): + with tarfile.open(dist / want_sdist) as sdist: + leaked = [n for n in sdist.getnames() if any(f in n for f in SDIST_FORBIDDEN)] + if leaked: + problems.append(f"sdist contains desktop build output, e.g. {leaked[0]}") + return problems + + +def main(argv: Optional[List[str]] = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) + parser.add_argument("--tag", help="the release tag, e.g. v3.2.0") + parser.add_argument("--dist", type=Path, help="folder with the built wheel and sdist") + parser.add_argument("--notes", type=Path, help="write the version's CHANGELOG section here") + args = parser.parse_args(argv) + + version = package_version() + problems = check_sources(version, args.tag) + if args.dist is not None: + problems += check_dist(args.dist, version) + if args.notes is not None: + changelog = (ROOT / "CHANGELOG.md").read_text(encoding="utf-8") + args.notes.parent.mkdir(parents=True, exist_ok=True) + args.notes.write_text( + (changelog_section(changelog, version) or "") + "\n", encoding="utf-8" + ) + + if problems: + print(f"EaglePlot {version}: {len(problems)} problem(s):") + for problem in problems: + print(f" - {problem}") + return 1 + print(f"EaglePlot {version}: release checks passed") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_release_check.py b/tests/test_release_check.py new file mode 100644 index 0000000..8abc4ea --- /dev/null +++ b/tests/test_release_check.py @@ -0,0 +1,141 @@ +"""scripts/release/check_release.py: the checks the release workflow runs (roadmap D6).""" + +import importlib.util +import io +import sys +import tarfile +import zipfile +from pathlib import Path + +import pytest + +REPO = Path(__file__).resolve().parent.parent + + +def _load(): + path = REPO / "scripts" / "release" / "check_release.py" + spec = importlib.util.spec_from_file_location("_check_release", path) + module = importlib.util.module_from_spec(spec) + sys.modules[spec.name] = module + spec.loader.exec_module(module) + return module + + +check = _load() +VERSION = check.package_version() + + +def test_the_repository_is_consistent_for_its_own_version(): + """__version__, the CHANGELOG section and the docs badge agree (G-035).""" + assert check.check_sources(VERSION, f"v{VERSION}") == [] + + +def test_a_wrong_tag_is_reported(): + problems = check.check_sources(VERSION, "v0.0.1") + assert len(problems) == 1 and "doesn't match the package version" in problems[0] + + +class TestChangelogSection: + CHANGELOG = ( + "# Changelog\n\n## [Unreleased]\n\n---\n\n" + "## [2.0.0] - 2026-01-02\n\nBig release.\n\n### Added\n\n- A thing.\n\n---\n\n" + "## [1.0.0] - 2025-05-06\n\n- Old.\n\n---\n\n" + "[Unreleased]: https://x/compare/v2.0.0...HEAD\n[2.0.0]: https://x/compare/v1.0.0...v2.0.0\n" + ) + + def test_section_body(self): + body = check.changelog_section(self.CHANGELOG, "2.0.0") + assert body == "Big release.\n\n### Added\n\n- A thing." + + def test_last_section_stops_at_the_links(self): + assert check.changelog_section(self.CHANGELOG, "1.0.0") == "- Old." + + @pytest.mark.parametrize("version", ["3.0.0", "Unreleased", "2.0"]) + def test_missing_or_undated(self, version): + assert check.changelog_section(self.CHANGELOG, version) is None + + +def _wheel(dist: Path, version: str, files: dict, top_level: str = "eagleplot\n") -> Path: + path = dist / f"eagleplot-{version}-py3-none-any.whl" + with zipfile.ZipFile(path, "w") as whl: + for name, data in files.items(): + whl.writestr(name, data) + whl.writestr(f"eagleplot-{version}.dist-info/top_level.txt", top_level) + return path + + +def _sdist(dist: Path, version: str, names=("PKG-INFO",)) -> Path: + path = dist / f"eagleplot-{version}.tar.gz" + with tarfile.open(path, "w:gz") as tar: + for name in names: + info = tarfile.TarInfo(f"eagleplot-{version}/{name}") + info.size = 1 + tar.addfile(info, io.BytesIO(b"x")) + return path + + +GOOD_FILES = {name: b"ok\n" for name in check.WHEEL_DATA_FILES} + + +class TestDist: + def test_a_good_build_passes(self, tmp_path): + _wheel(tmp_path, "9.9.9", GOOD_FILES) + _sdist(tmp_path, "9.9.9") + assert check.check_dist(tmp_path, "9.9.9") == [] + + def test_wrong_version_in_the_file_names(self, tmp_path): + _wheel(tmp_path, "9.9.8", GOOD_FILES) + _sdist(tmp_path, "9.9.8") + problems = check.check_dist(tmp_path, "9.9.9") + assert len(problems) == 2 and all("expected exactly" in p for p in problems) + + def test_another_top_level_package(self, tmp_path): + _wheel(tmp_path, "9.9.9", {**GOOD_FILES, "modules/io.py": b""}, "eagleplot\nmodules\n") + _sdist(tmp_path, "9.9.9") + problems = "\n".join(check.check_dist(tmp_path, "9.9.9")) + assert "top_level.txt" in problems and "outside eagleplot/" in problems + + def test_missing_gui_data_files(self, tmp_path): + files = dict(GOOD_FILES) + del files["eagleplot/assets/logo.png"] + _wheel(tmp_path, "9.9.9", files) + _sdist(tmp_path, "9.9.9") + (problem,) = check.check_dist(tmp_path, "9.9.9") + assert "G-012" in problem and "logo.png" in problem + + def test_windows_line_endings(self, tmp_path): + _wheel(tmp_path, "9.9.9", {**GOOD_FILES, "eagleplot/io.py": b"import os\r\n"}) + _sdist(tmp_path, "9.9.9") + (problem,) = check.check_dist(tmp_path, "9.9.9") + assert "G-032" in problem and "eagleplot/io.py" in problem + + def test_desktop_build_output_in_the_sdist(self, tmp_path): + _wheel(tmp_path, "9.9.9", GOOD_FILES) + _sdist(tmp_path, "9.9.9", ["PKG-INFO", "packaging/desktop/node_modules/x/index.js"]) + (problem,) = check.check_dist(tmp_path, "9.9.9") + assert "desktop build output" in problem + + +def test_notes_are_written_for_the_release(tmp_path): + notes = tmp_path / "notes.md" + assert check.main(["--tag", f"v{VERSION}", "--notes", str(notes)]) == 0 + text = notes.read_text(encoding="utf-8") + assert text.strip() and "## [" not in text and "[Unreleased]" not in text + + +def test_the_release_workflow_publishes_without_a_token(): + """PyPI upload by Trusted Publishing only: OIDC permission, no password or token.""" + import yaml + + text = (REPO / ".github" / "workflows" / "release.yml").read_text(encoding="utf-8") + workflow = yaml.safe_load(text) + jobs = workflow["jobs"] + assert jobs["pypi"]["permissions"] == {"id-token": "write"} + assert jobs["pypi"]["environment"]["name"] == "pypi" + assert jobs["pypi"]["needs"] == "build" + publish = [s for s in jobs["pypi"]["steps"] if "gh-action-pypi-publish" in s.get("uses", "")] + assert publish and "password" not in publish[0].get("with", {}) + assert "secrets." not in text + build_steps = " ".join(s.get("run", "") for s in jobs["build"]["steps"]) + assert "check_release.py" in build_steps + assert workflow.get("permissions") == {"contents": "read"} # write only where needed