|
| 1 | +# Releasing packages |
| 2 | + |
| 3 | +This section describes how to release Python packages using the Best Practices |
| 4 | +methodology |
| 5 | + |
| 6 | +Note: the Best Practices repo uses setuptools as it's build tool. Any tool will work, |
| 7 | +but you will need to change your ``pyproject.toml`` and ``<package>/version.py`` file. |
| 8 | + |
| 9 | +## Releases |
| 10 | + |
| 11 | +Software releases are automated through the GitHub Action at |
| 12 | +``.github/workflows/release.yml``. It uses PyPI's [Trusted Publisher](https://docs.pypi.org/trusted-publishers/) |
| 13 | +integration with GitHub. |
| 14 | + |
| 15 | +PyPI packages are published when a new tag is pushed to origin that |
| 16 | +doesn't have `.dev` contained within it. |
| 17 | + |
| 18 | +It's strongly recommended that you limit who can trigger a PyPI release |
| 19 | +of your package. The ``release.yml`` supports this via the ``pypi`` environment. |
| 20 | +You can limit who can approve the workflow by configuring the environment |
| 21 | +(``pypi`` in this case) to have [required reviewers](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments/managing-environments-for-deployment#required-reviewers). |
| 22 | + |
| 23 | +## Testing Releases |
| 24 | + |
| 25 | +The packaging and release process can be tested by utilizing the ``test_release.yml`` |
| 26 | +GitHub action workflow. |
| 27 | + |
| 28 | +This requires you to allow your package's version to be configured by an environment |
| 29 | +variable. An example of this can be seen in ``src/django_commons_best_practices/__init__.py``. |
| 30 | +You will also need to change your ``pyproject.toml`` to allow |
| 31 | +[dynamic versioning](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#static-vs-dynamic-metadata). |
| 32 | + |
| 33 | +To test the release process fully, the package must be built with a unique version. |
| 34 | +The default versioning schema only supports a `.dev` suffix that is an obviously test |
| 35 | +tag. You need to allow a suffix to be specified from an environment variable, then use |
| 36 | +that environment variable in ``test_release.yml`` for the ``DEV_VERSION_ENV_KEY`` env |
| 37 | +variable. |
| 38 | + |
| 39 | +### Running tests |
| 40 | + |
| 41 | +The default version of ``test_release.yml`` will run the tests once per month, on the second |
| 42 | +day of the month. |
| 43 | + |
| 44 | +It also supports running the tests on an adhoc basis via the ``workflow_dispatch`` GitHub |
| 45 | +action event type. It will require you to specify an ``iteration`` value. This value must |
| 46 | +be unique for each test run on a given day. |
0 commit comments