name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Verify version matches
run: |
grep -q "version = \"$VERSION\"" pyproject.toml ||
(echo "Version in pyproject.toml doesn't match tag" && exit 1)
- name: Build package
run: python -m build
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
draft: false
prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }}
generate_release_notes: true
- name: Publish to PyPI
if: ${{ !contains(github.ref, '-alpha') && !contains(github.ref, '-beta') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}