Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

Expand Down
11 changes: 7 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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").

Expand Down
4 changes: 4 additions & 0 deletions CompStats/tests/test_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
7 changes: 4 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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<version>`` 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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions scripts/check_package_versions.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading