Skip to content

Commit bed66ed

Browse files
committed
Created separate test release action
This required dynamic versioning so that we could read in an environment variable to suffix the version with a dev tag. This allows us to create dev distributions of the package to test the release process more thoroughly.
1 parent aaa5544 commit bed66ed

File tree

4 files changed

+105
-31
lines changed

4 files changed

+105
-31
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
22

3-
on: push
3+
on:
4+
push:
5+
tags:
6+
# Order matters, the last rule that applies to a tag
7+
# is the one that takes effect:
8+
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches-and-tags
9+
- '*'
10+
# There should be no dev tags created, but to be safe,
11+
# let's not publish them.
12+
- '!*.dev*'
413

514
env:
615
# Change these for your project's URLs
716
PYPI_URL: https://pypi.org/p/django-commons-best-practices
8-
PYPI_TEST_URL: https://test.pypi.org/p/django-commons-best-practices
917

1018
jobs:
1119

@@ -33,7 +41,6 @@ jobs:
3341
publish-to-pypi:
3442
name: >-
3543
Publish Python 🐍 distribution 📦 to PyPI
36-
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
3744
needs:
3845
- build
3946
runs-on: ubuntu-latest
@@ -93,29 +100,3 @@ jobs:
93100
gh release upload
94101
'${{ github.ref_name }}' dist/**
95102
--repo '${{ github.repository }}'
96-
97-
publish-to-testpypi:
98-
name: Publish Python 🐍 distribution 📦 to TestPyPI
99-
if: startsWith(github.ref, 'refs/tags/') # only publish to TestPyPI on tag pushes
100-
needs:
101-
- build
102-
runs-on: ubuntu-latest
103-
104-
environment:
105-
name: testpypi
106-
url: ${{ env.PYPI_TEST_URL }}
107-
108-
permissions:
109-
id-token: write # IMPORTANT: mandatory for trusted publishing
110-
111-
steps:
112-
- name: Download all the dists
113-
uses: actions/download-artifact@v4
114-
with:
115-
name: python-package-distributions
116-
path: dist/
117-
- name: Publish distribution 📦 to TestPyPI
118-
uses: pypa/gh-action-pypi-publish@release/v1.10
119-
with:
120-
repository-url: https://test.pypi.org/legacy/
121-
skip-existing: true

.github/workflows/test_release.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Test Python 🐍 distribution 📦 to TestPyPI
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
iteration:
7+
description: 'A unique iteration for the run. The tag will be prefixed with test.yyyymmdd.'
8+
type: string
9+
required: true
10+
default: "0"
11+
12+
env:
13+
# Change these for your project's URLs
14+
PYPI_TEST_URL: https://test.pypi.org/p/django-commons-best-practices
15+
# The environment key that overrides the version number
16+
DEV_VERSION_ENV_KEY: BEST_PRACTICES_VERSION
17+
18+
jobs:
19+
20+
create-dev-version:
21+
# Generate the dev version suffix based on the current date.
22+
# Tag name:
23+
# <version>.dev<yyyymmdd><iteration>
24+
name: Create dev version string
25+
runs-on: ubuntu-latest
26+
outputs:
27+
dev_version: ${{ steps.output-dev-version.outputs.dev_version }}
28+
steps:
29+
- name: Set date suffix
30+
id: set-date
31+
run: echo "suffix=dev$(date +%Y%m%d)${{ github.event.inputs.iteration }}" >> $GITHUB_ENV
32+
- name: Output dev version
33+
id: output-dev-version
34+
run: echo "dev_version=${{ env.suffix }}" >> "$GITHUB_OUTPUT"
35+
36+
build:
37+
name: Build distribution 📦
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Set up Python
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: "3.x"
46+
- name: Install pypa/build
47+
run:
48+
python3 -m pip install build --user
49+
- name: Build a binary wheel and a source tarball
50+
env:
51+
DEV_VERSION: ${{needs.create-dev-version.outputs.dev_version}}
52+
run: ${{ env.DEV_VERSION_ENV_KEY }}="${{ env.DEV_VERSION }}" python3 -m build
53+
- name: Store the distribution packages
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: python-package-distributions
57+
path: dist/
58+
59+
publish-to-testpypi:
60+
name: Publish Python 🐍 distribution 📦 to TestPyPI
61+
needs:
62+
- build
63+
runs-on: ubuntu-latest
64+
65+
environment:
66+
name: testpypi
67+
url: ${{ env.PYPI_TEST_URL }}
68+
69+
permissions:
70+
id-token: write # IMPORTANT: mandatory for trusted publishing
71+
72+
steps:
73+
- name: Download all the dists
74+
uses: actions/download-artifact@v4
75+
with:
76+
name: python-package-distributions
77+
path: dist/
78+
- name: Publish distribution 📦 to TestPyPI
79+
uses: pypa/gh-action-pypi-publish@release/v1.10
80+
with:
81+
repository-url: https://test.pypi.org/legacy/
82+
skip-existing: true

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "django-commons-best-practices"
7-
version = "1.1.0"
7+
dynamic = ["version", "readme"]
88
authors = [
99
{ name="Tim Schilling", email="[email protected]" },
1010
]
1111
description = "A place to test things out"
12-
readme = "README.md"
1312
requires-python = ">=3.11"
1413
classifiers = [
1514
"Programming Language :: Python :: 3",
@@ -21,6 +20,10 @@ keywords = [
2120
"django commons",
2221
]
2322

23+
[tool.setuptools.dynamic]
24+
version = {attr = "django_commons_best_practices.__version__"}
25+
readme = {file = ["README.md"]}
26+
2427
[project.urls]
2528
Homepage = "https://github.com/django-commons/best-practices"
2629
Issues = "https://github.com/django-commons/best-practices/issues"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
__all__ = ["VERSION"]
2+
import os
3+
4+
# Support suffixing the version with a dev segment.
5+
# This allows for building dev distributions to test
6+
# the release process.
7+
# See .github/workflows/test_release.yml
8+
__version__ = VERSION = "1.1.0" + os.environ.get("BEST_PRACTICES_VERSION_DEV", "")

0 commit comments

Comments
 (0)