diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 460a043..4d0ed2e 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -1,9 +1,9 @@ name: Publish to PyPI +# Publishing is a manual step: run this workflow from the Actions tab (or with +# `gh workflow run publish-pypi.yml --ref main`). Creating a tag or a GitHub +# release does not publish anything. on: - push: - tags: - - "v*" workflow_dispatch: concurrency: @@ -20,24 +20,6 @@ jobs: with: python-version: "3.12" - - name: Install version-check dependencies - if: github.event_name != 'workflow_dispatch' - run: pip install packaging - - # Tags are the release trigger, so a stale tag (forgot to bump - # __version__) must fail loudly instead of publishing the wrong - # version. `version` is declared `dynamic` in pyproject.toml, so it is - # read the same way scripts/check_package_versions.py reads it. - - name: Verify tag matches the package version - if: github.event_name != 'workflow_dispatch' - run: | - tag_version="${GITHUB_REF_NAME#v}" - pkg_version=$(python -c "import sys; sys.path.insert(0, 'scripts'); from check_package_versions import local_version; print(local_version())") - if [ "$tag_version" != "$pkg_version" ]; then - echo "Tag version $tag_version does not match CompStats.__version__ $pkg_version" >&2 - exit 1 - fi - - name: Install build tooling run: pip install build twine diff --git a/CLAUDE.md b/CLAUDE.md index 553d13c..ead6efe 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -79,10 +79,13 @@ Coveralls, and runs `scripts/check_package_versions.py` (the version gate descri - The version lives in one place: `__version__` in `CompStats/__init__.py`. - `scripts/check_package_versions.py` (run by CI on every push and pull request) fails unless `__version__` is exactly one patch or one minor release ahead of the latest version on PyPI. -- To release: make sure `__version__` is the version to publish, merge to `main`, then create and - push the tag `v<__version__>` (for example `git tag v0.2.0 && git push origin v0.2.0`). - `.github/workflows/publish-pypi.yml` verifies that the tag equals `__version__`, builds the - sdist and the wheel, runs `twine check` and uploads with the `TWINE` repository secret. +- To release: make sure `__version__` is the version to publish, merge to `main`, then run + `.github/workflows/publish-pypi.yml` by hand (the "Run workflow" button of the Actions tab, or + `gh workflow run publish-pypi.yml --ref main`). It builds the sdist and the wheel, runs + `twine check` and uploads with the `TWINE` repository secret. +- Publishing is manual only. Creating a tag or a GitHub release (for example + `gh release create v0.2.0 --target main`) does not upload anything to PyPI, so the release is + created after the package is published. - After a release, bump `__version__` before the next change is merged, otherwise the version gate fails ("local is not ahead of PyPI"). diff --git a/CompStats/tests/test_packaging.py b/CompStats/tests/test_packaging.py index a6c987a..dea74ca 100644 --- a/CompStats/tests/test_packaging.py +++ b/CompStats/tests/test_packaging.py @@ -95,6 +95,10 @@ def test_workflows(): publish = (WORKFLOWS / "publish-pypi.yml").read_text(encoding="utf-8") assert "secrets.TWINE" in publish assert "twine check" in publish + # Publishing is manual only: neither a tag nor a release triggers it. + assert "workflow_dispatch" in publish + for trigger in ("push:", "tags:", "release:"): + assert trigger not in publish def test_pyproject_build_system_and_test_extra(): diff --git a/docs/source/index.rst b/docs/source/index.rst index e844d6e..863858e 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -304,9 +304,10 @@ Build the developer reference; the HTML is written to ``docs/build/html/index.ht The same strict build runs in continuous integration, and any warning (for example, a cross-reference that does not resolve) makes it fail. -Releases are published by pushing a ``v`` tag, which triggers the workflow -``.github/workflows/publish-pypi.yml``; the version gate ``scripts/check_package_versions.py`` -verifies that the version is a single step ahead of the one published on PyPI. +Releases are published by running the workflow ``.github/workflows/publish-pypi.yml`` manually +on ``main``. Creating a tag or a GitHub release does not publish the package. The version gate +``scripts/check_package_versions.py`` verifies that the version is a single step ahead of the one +published on PyPI. User site ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/scripts/check_package_versions.py b/scripts/check_package_versions.py index 4d9d71f..43ffaca 100644 --- a/scripts/check_package_versions.py +++ b/scripts/check_package_versions.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 """Check the package's local version against PyPI. -``publish-pypi.yml`` only checks, at the moment a tag is pushed, that the tag -matches ``CompStats.__version__``. Nothing checks *before* that whether the -local version is actually ahead of what PyPI has, or whether it jumped more -than one release past it. This script reports PyPI's latest version, the +``publish-pypi.yml`` is run by hand and uploads whatever version the checked +out code declares. Nothing in it checks whether the local version is actually +ahead of what PyPI has, or whether it jumped more than one release past it. +This script reports PyPI's latest version, the local version (read from the attribute ``pyproject.toml`` declares as the dynamic version, without importing the package, so none of its dependencies need to be installed), and whether the local version is a valid single-step