Skip to content

Release and Publish #25

Release and Publish

Release and Publish #25

Workflow file for this run

name: Release and Publish
on:
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
release:
name: Create GitHub release and publish to PyPI
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure workflow runs from main
run: |
if [ "${{ github.ref_name }}" != "main" ]; then
echo "This workflow must be run from the main branch."
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up uv
uses: astral-sh/setup-uv@v6
- name: Read version from pyproject
run: |
VERSION="$(python - <<'PY'
import tomllib
from pathlib import Path
data = tomllib.loads(Path("pyproject.toml").read_text())
print(data["project"]["version"])
PY
)"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "TAG=v$VERSION" >> "$GITHUB_ENV"
- name: Ensure release tag does not already exist
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release $TAG already exists."
exit 1
fi
- name: Build package
run: uv build
- name: Validate distributions
run: uvx twine check --strict dist/*
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "$TAG" \
--title "$TAG" \
--generate-notes \
--target "${{ github.sha }}" \
dist/*
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1