Skip to content

fix: read version from pyproject.toml in build job, avoid importing p… #3

fix: read version from pyproject.toml in build job, avoid importing p…

fix: read version from pyproject.toml in build job, avoid importing p… #3

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
permissions:
contents: read
jobs:
# ── 1. Run tests before publishing ────────────────────────────────────────
test:
name: Test before release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install dependencies
run: pip install -e ".[dev,async]"
- name: Run tests
run: pytest tests/ -v --tb=short
# ── 2. Build source distribution and wheel ────────────────────────────────
build:
name: Build distribution
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install build
run: pip install build
- name: Build sdist and wheel
run: python -m build
- name: Verify tag matches package version
run: |
TAG="${GITHUB_REF_NAME#v}"
VERSION=$(python -c "
import re, pathlib
content = pathlib.Path('pyproject.toml').read_text()
print(re.search(r'^version\s*=\s*\"(.+?)\"', content, re.MULTILINE).group(1))
")
echo "Tag: $TAG | Package version: $VERSION"
if [ "$TAG" != "$VERSION" ]; then
echo "ERROR: tag '$TAG' does not match package version '$VERSION'"
exit 1
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# ── 3. Publish to PyPI via OIDC Trusted Publisher ─────────────────────────
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: build
environment: pypi
permissions:
id-token: write # required for OIDC trusted publisher
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