| 1 |
######### |
| 2 |
Release |
| 3 |
######### |
| 4 |
|
| 5 |
Releases follow `semantic versioning <https://semver.org/>`_ and use automated workflows to handle version bumping, |
| 6 |
changelog building, commit creation, and publishing. Maintainers trigger releases through GitHub Actions or run the |
| 7 |
release script locally for testing. |
| 8 |
|
| 9 |
********************* |
| 10 |
Changelog Fragments |
| 11 |
********************* |
| 12 |
|
| 13 |
Contributors add changelog fragments that get collected during releases. Create a file in ``docs/changelog/`` named |
| 14 |
``<pr_number>.<type>.rst`` where type is ``feature`` for new functionality, ``bugfix`` for fixes, ``doc`` for |
| 15 |
documentation changes, ``removal`` for deprecations, or ``misc`` for internal changes. The file should contain a single |
| 16 |
line describing the change, optionally crediting the author with ``:user:`username``` syntax. For example, |
| 17 |
``123.feature.rst`` might contain ``Add support for custom backends - by :user:`contributor```. These fragments are |
| 18 |
collected during releases to build the changelog automatically. |
| 19 |
|
| 20 |
******************* |
| 21 |
Automated Release |
| 22 |
******************* |
| 23 |
|
| 24 |
Navigate to the `pre-release workflow <https://github.com/pypa/build/actions/workflows/pre-release.yml>`_ and click Run |
| 25 |
workflow. Select a version bump type: ``auto`` for patch bumps, ``major`` for X+1.0.0, ``minor`` for X.Y+1.0, or |
| 26 |
``patch`` for X.Y.Z+1. |
| 27 |
|
| 28 |
The workflow updates the version in ``src/build/__init__.py``, runs ``towncrier build`` to collect changelog fragments |
| 29 |
from ``docs/changelog/`` and incorporate them into ``CHANGELOG.rst``, creates a release commit with message ``chore: |
| 30 |
prepare for X.Y.Z``, creates an annotated tag, and pushes both to trigger the CD workflow. |
| 31 |
|
| 32 |
The tag push triggers the continuous deployment pipeline which builds the source distribution and wheel, creates a |
| 33 |
GitHub release with auto-generated notes, generates build attestations for supply chain security, and publishes to PyPI |
| 34 |
via trusted publishing. The process takes approximately five minutes from workflow trigger to published package. |
| 35 |
|
| 36 |
*************** |
| 37 |
Local Release |
| 38 |
*************** |
| 39 |
|
| 40 |
Run the release script locally for testing or manual control. Ensure tox is installed and git identity is configured: |
| 41 |
|
| 42 |
.. code-block:: console |
| 43 |
|
| 44 |
$ pip install tox |
| 45 |
$ git config user.name "Your Name" |
| 46 |
$ git config user.email "[email protected]" |
| 47 |
|
| 48 |
The script creates annotated git tags without GPG signing. Package authenticity is guaranteed by PyPI attestations, not |
| 49 |
git tag signatures. |
| 50 |
|
| 51 |
Dry run without pushing |
| 52 |
======================= |
| 53 |
|
| 54 |
Test the release process locally: |
| 55 |
|
| 56 |
.. code-block:: console |
| 57 |
|
| 58 |
$ tox -e release -- --version auto --no-push |
| 59 |
|
| 60 |
This updates the version file, builds the changelog from fragments, creates the commit and tag locally, but does not |
| 61 |
push to the remote repository. |
| 62 |
|
| 63 |
Full local release |
| 64 |
================== |
| 65 |
|
| 66 |
Specify an explicit version or bump type: |
| 67 |
|
| 68 |
.. code-block:: console |
| 69 |
|
| 70 |
$ tox -e release -- --version 1.5.0 |
| 71 |
$ tox -e release -- --version patch # 1.4.0 → 1.4.1 |
| 72 |
$ tox -e release -- --version minor # 1.4.0 → 1.5.0 |
| 73 |
$ tox -e release -- --version major # 1.4.0 → 2.0.0 |
| 74 |
|
| 75 |
The script updates ``src/build/__init__.py``, runs ``towncrier build`` to collect changelog fragments, runs pre-commit |
| 76 |
hooks, creates a commit with message ``chore: prepare for X.Y.Z``, creates an annotated tag, and pushes both to origin. |
| 77 |
The GitHub Actions CD workflow takes over to build and publish. |
| 78 |
|
| 79 |
********** |
| 80 |
See also |
| 81 |
********** |
| 82 |
|
| 83 |
PyPI removed PGP signature support in May 2023. Package authenticity is guaranteed through PyPI attestations per PEP |
| 84 |
740, which cryptographically link packages to their source repository and build process. |
| 85 |
|
| 86 |
***************** |
| 87 |
Troubleshooting |
| 88 |
***************** |
| 89 |
|
| 90 |
Workflow timeout |
| 91 |
================ |
| 92 |
|
| 93 |
If the pre-release workflow times out, run the release script locally with ``--no-push``, then manually push with ``git |
| 94 |
push && git push --tags``. The CD workflow triggers automatically on tag push. |
| 95 |
|
| 96 |
Publishing conflicts |
| 97 |
==================== |
| 98 |
|
| 99 |
If a version is already published to PyPI, the publish job fails safely. The CD workflow is idempotent except for PyPI |
| 100 |
publishing. For corrections, create a post-release like ``X.Y.Z.post1``. |
| 101 |
|
| 102 |
**************** |
| 103 |
Implementation |
| 104 |
**************** |
| 105 |
|
| 106 |
The automation consists of the pre-release workflow at ``.github/workflows/pre-release.yml`` for manual triggering, the |
| 107 |
CD workflow at ``.github/workflows/cd.yml`` that triggers on tag pushes, the release script at ``tasks/release.py`` for |
| 108 |
version bumping and tag creation, and the ``[env.release]`` environment in ``tox.toml`` providing dependencies. |