name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
id-token: write # For trusted publishing to PyPI
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run tests
run: |
pytest tests/ -v
build:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: |
python -m build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
github-release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Extract release notes
id: extract-release-notes
run: |
# Extract version from tag
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Extract release notes from CHANGELOG.md
if [ -f CHANGELOG.md ]; then
# Try to extract release notes for this version
awk "/^## \[$VERSION\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md > release_notes.md
if [ ! -s release_notes.md ]; then
echo "Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "See [CHANGELOG.md](CHANGELOG.md) for details." >> release_notes.md
fi
else
echo "Release $VERSION" > release_notes.md
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Release v${{ steps.extract-release-notes.outputs.version }}
body_path: release_notes.md
files: |
dist/*.tar.gz
dist/*.whl
draft: false
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
pypi-publish:
runs-on: ubuntu-latest
needs: build
environment: release
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# Use trusted publishing - no API token needed
# Configure at https://pypi.org/manage/account/publishing/
verbose: true