diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..8d3ea9a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,38 @@ +name: Publish to PyPI + +on: + release: + types: [published] + +jobs: + build-and-publish: + runs-on: ubuntu-latest + environment: pypi + permissions: + contents: read # required for actions/checkout + id-token: write # required for PyPI trusted publishing (OIDC) + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install build tooling + run: python -m pip install --upgrade build + + - name: Build sdist and wheel + run: python -m build + + - name: Verify version matches release tag + run: | + TAG="${GITHUB_REF_NAME#v}" + PKG_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])") + if [ "$TAG" != "$PKG_VERSION" ]; then + echo "Release tag ($TAG) does not match pyproject.toml version ($PKG_VERSION)" >&2 + exit 1 + fi + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1