| 1 |
name: Publish Python distribution to PyPI and TestPyPI |
| 2 |
# Source: |
| 3 |
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 4 |
on: |
| 5 |
push: |
| 6 |
branches: |
| 7 |
- main |
| 8 |
tags: |
| 9 |
- 'v*' |
| 10 |
workflow_dispatch: |
| 11 |
jobs: |
| 12 |
build: |
| 13 |
name: Build distribution package |
| 14 |
runs-on: ubuntu-latest |
| 15 |
steps: |
| 16 |
- uses: actions/checkout@v4 |
| 17 |
- uses: astral-sh/setup-uv@v6 |
| 18 |
with: |
| 19 |
version: '>=0.7' |
| 20 |
- name: Check for version match in git tag and django_cte.__version__ |
| 21 |
if: startsWith(github.ref, 'refs/tags/v') |
| 22 |
run: uvx pyverno check django_cte/__init__.py "${{ github.ref }}" |
| 23 |
- name: Add untagged version suffix |
| 24 |
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }} |
| 25 |
run: uvx pyverno update django_cte/__init__.py |
| 26 |
- name: Build a binary wheel and a source tarball |
| 27 |
run: uv build |
| 28 |
- name: Store the distribution packages |
| 29 |
uses: actions/upload-artifact@v4 |
| 30 |
with: |
| 31 |
name: python-package-distributions |
| 32 |
path: dist/ |
| 33 |
pypi-publish: |
| 34 |
name: Upload release to PyPI |
| 35 |
needs: [build] |
| 36 |
runs-on: ubuntu-latest |
| 37 |
environment: |
| 38 |
name: pypi |
| 39 |
url: https://pypi.org/p/django-cte |
| 40 |
permissions: |
| 41 |
id-token: write |
| 42 |
steps: |
| 43 |
- name: Download all the dists |
| 44 |
uses: actions/download-artifact@v4 |
| 45 |
with: |
| 46 |
name: python-package-distributions |
| 47 |
path: dist/ |
| 48 |
- name: Publish package distributions to PyPI |
| 49 |
uses: pypa/gh-action-pypi-publish@release/v1 |
| 50 |
pypi-test-publish: |
| 51 |
name: Upload release to test PyPI |
| 52 |
needs: [build] |
| 53 |
runs-on: ubuntu-latest |
| 54 |
environment: |
| 55 |
name: testpypi |
| 56 |
url: https://test.pypi.org/p/django-cte |
| 57 |
permissions: |
| 58 |
id-token: write |
| 59 |
steps: |
| 60 |
- name: Download all the dists |
| 61 |
uses: actions/download-artifact@v4 |
| 62 |
with: |
| 63 |
name: python-package-distributions |
| 64 |
path: dist/ |
| 65 |
- name: Publish package distributions to PyPI |
| 66 |
uses: pypa/gh-action-pypi-publish@release/v1 |
| 67 |
with: |
| 68 |
repository-url: https://test.pypi.org/legacy/ |