Skip to content

Commit 4d99a48

Browse files
committed
Limit the test release workflow from running on non-main branches.
1 parent caab641 commit 4d99a48

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

.github/workflows/test_release.yml

+15
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,27 @@ env:
1919
DEV_VERSION_ENV_KEY: BEST_PRACTICES_VERSION_DEV
2020

2121
jobs:
22+
check-branch:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Check if the branch is main
26+
run: |
27+
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
28+
echo "This workflow can only run on the main branch. Exiting."
29+
exit 0
30+
fi
31+
echo "Branch is main, proceeding with the job."
32+
33+
- name: Continue with the action
34+
run: echo "Performing the main branch actions."
2235

2336
create-dev-version:
2437
# Generate the dev version suffix based on the current date.
2538
# Tag name:
2639
# <version>.dev<yyyymmdd><iteration>
2740
name: Create dev version string
41+
needs:
42+
- check-branch
2843
runs-on: ubuntu-latest
2944
outputs:
3045
dev_version: ${{ steps.output-dev-version.outputs.dev_version }}

docs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and organized docs are the best docs.
88
## Table of Contents
99

1010
- [Installation](installation.md)
11+
- [Releasing packages](releases.md)
1112
- [Getting Started](getting_started.md)
1213
- [Contributing](contributing.md)
1314
- [Code of Conduct](../CODE_OF_CONDUCT.md)

docs/releases.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)