GitHub Action to Build a Python Package Using setuptools-scm
This GHA package validates your project's pyproject.toml
for correct setuptools-scm
configuration, then builds the Python package.
It is designed to be used in automated release workflows, typically preceding GitHub release and/or PyPI publishing.
- Ensures your
pyproject.toml
:- Lists
setuptools-scm
as a build requirement - Does not statically define
project.version
- Includes the
[tool.setuptools_scm]
section
- Lists
- Builds the package via
python -m build
- Both
sdist
andwheel
artifacts are created - The resulting
.tar.gz
and.whl
files are written to thedist/
directory
- Both
- You must have the minimum supported Python version declared in
pyproject.toml
installed in the environment.- For example, if your project requires
>=3.10
, you must useactions/setup-python
with Python 3.10 before this step.
- For example, if your project requires
None
None
The following is based on WIPACrepo/wipac-dev-actions-testbed
's cicd.yml
:
jobs:
...
tag-and-release:
# only run on main/master/default
if: format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
needs: [
py-versions,
...
]
runs-on: ubuntu-latest
concurrency: tag-and-release # prevent any possible race conditions
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # required to see tags and commits
ref: ${{ github.sha }} # lock to triggered commit ('github.ref' is dynamic)
- uses: actions/setup-python@v5 # needed for building project
with:
python-version: "${{ fromJSON(needs.py-versions.outputs.matrix)[0] }}"
- uses: WIPACrepo/wipac-dev-next-version-action@...
id: next-version
...
- if: steps.next-version.outputs.version != ''
name: Tag New Version
...
- if: steps.next-version.outputs.version != ''
uses: WIPACrepo/wipac-dev-py-build-action@...
# -> uses the most recent git tag for versioning
# -> creates 'dist/' files
- if: steps.next-version.outputs.version != ''
uses: softprops/action-gh-release@v2
with:
files: dist/*
tag_name: v${{ steps.next-version.outputs.version }} # must match git tag above
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- if: steps.next-version.outputs.version != ''
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}