Skip to content

ci: Add GitHub Actions workflows for testing and publishing. #1

ci: Add GitHub Actions workflows for testing and publishing.

ci: Add GitHub Actions workflows for testing and publishing. #1

Workflow file for this run

name: Publish to PyPI
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+' # Matches semantic versioning tags
- '[0-9]+.[0-9]+.[0-9]+-test.*' # Test releases
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -e .
- name: Run tests
run: pytest
publish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Verify tag version matches package version
run: |
PACKAGE_VERSION=$(python setup.py --version)
TAG_VERSION=${GITHUB_REF#refs/tags/v}
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "Package version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)"
exit 1
fi
- name: Build package
run: python -m build
- name: Publish to TestPyPI
if: contains(github.ref, 'test')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: twine upload --repository testpypi dist/*
- name: Publish to PyPI
if: "!contains(github.ref, 'test')"
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}