Add release.yaml GitHub action #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release to PyPI | |
on: | |
push: | |
tags: | |
- "v*" | |
jobs: | |
release: | |
name: Build and publish to PyPI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4.2.2 | |
- name: Validate version matches tag | |
run: | | |
TAG_VERSION="${GITHUB_REF#refs/tags/v}" | |
echo "Tag version: $TAG_VERSION" | |
FILE_VERSION=$(grep -Po '(?<=^version = ")[^"]+' pyproject.toml) | |
echo "File version: $FILE_VERSION" | |
if [ "$TAG_VERSION" != "$FILE_VERSION" ]; then | |
echo "ERROR: Tag version ($TAG_VERSION) does not match pyproject.toml version ($FILE_VERSION)" | |
exit 1 | |
fi | |
- name: Set up Python | |
uses: actions/setup-python@v5.4.0 | |
with: | |
python-version: "3.12" | |
- name: Install build & twine | |
run: | | |
python -m pip install --upgrade pip | |
pip install build twine | |
- name: Build distribution | |
run: python -m build | |
- name: Publish to PyPI | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: twine upload dist/* |