Skip to content

Commit

Permalink
Created separate test release action
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tim-schilling committed Jan 18, 2025
1 parent aaa5544 commit bed66ed
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 31 deletions.
39 changes: 10 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

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

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

jobs:

Expand Down Expand Up @@ -33,7 +41,6 @@ jobs:
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -93,29 +100,3 @@ jobs:
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to TestPyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: ${{ env.PYPI_TEST_URL }}

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1.10
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
82 changes: 82 additions & 0 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test Python 🐍 distribution 📦 to TestPyPI

on:
workflow_dispatch:
inputs:
iteration:
description: 'A unique iteration for the run. The tag will be prefixed with test.yyyymmdd.'
type: string
required: true
default: "0"

env:
# Change these for your project's URLs
PYPI_TEST_URL: https://test.pypi.org/p/django-commons-best-practices
# The environment key that overrides the version number
DEV_VERSION_ENV_KEY: BEST_PRACTICES_VERSION

jobs:

create-dev-version:
# Generate the dev version suffix based on the current date.
# Tag name:
# <version>.dev<yyyymmdd><iteration>
name: Create dev version string
runs-on: ubuntu-latest
outputs:
dev_version: ${{ steps.output-dev-version.outputs.dev_version }}
steps:
- name: Set date suffix
id: set-date
run: echo "suffix=dev$(date +%Y%m%d)${{ github.event.inputs.iteration }}" >> $GITHUB_ENV
- name: Output dev version
id: output-dev-version
run: echo "dev_version=${{ env.suffix }}" >> "$GITHUB_OUTPUT"

build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run:
python3 -m pip install build --user
- name: Build a binary wheel and a source tarball
env:
DEV_VERSION: ${{needs.create-dev-version.outputs.dev_version}}
run: ${{ env.DEV_VERSION_ENV_KEY }}="${{ env.DEV_VERSION }}" python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: ${{ env.PYPI_TEST_URL }}

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1.10
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ build-backend = "setuptools.build_meta"

[project]
name = "django-commons-best-practices"
version = "1.1.0"
dynamic = ["version", "readme"]
authors = [
{ name="Tim Schilling", email="[email protected]" },
]
description = "A place to test things out"
readme = "README.md"
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3",
Expand All @@ -21,6 +20,10 @@ keywords = [
"django commons",
]

[tool.setuptools.dynamic]
version = {attr = "django_commons_best_practices.__version__"}
readme = {file = ["README.md"]}

[project.urls]
Homepage = "https://github.com/django-commons/best-practices"
Issues = "https://github.com/django-commons/best-practices/issues"
8 changes: 8 additions & 0 deletions src/django_commons_best_practices/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__all__ = ["VERSION"]
import os

# Support suffixing the version with a dev segment.
# This allows for building dev distributions to test
# the release process.
# See .github/workflows/test_release.yml
__version__ = VERSION = "1.1.0" + os.environ.get("BEST_PRACTICES_VERSION_DEV", "")

0 comments on commit bed66ed

Please sign in to comment.