|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Release version (e.g. 5.0.0)' |
| 8 | + required: true |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + id-token: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + release: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v7 |
| 20 | + |
| 21 | + - name: Validate version input |
| 22 | + env: |
| 23 | + VERSION: ${{ inputs.version }} |
| 24 | + run: | |
| 25 | + if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 26 | + echo "Invalid version: $VERSION (expected X.Y.Z)" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | + if git rev-parse "$VERSION" >/dev/null 2>&1; then |
| 30 | + echo "Tag $VERSION already exists" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | +
|
| 34 | + - name: Set up Python |
| 35 | + uses: actions/setup-python@v6 |
| 36 | + with: |
| 37 | + python-version: '3.14' |
| 38 | + |
| 39 | + - name: Install Poetry |
| 40 | + run: pipx install poetry |
| 41 | + |
| 42 | + - name: Check version matches pyproject.toml |
| 43 | + env: |
| 44 | + VERSION: ${{ inputs.version }} |
| 45 | + run: | |
| 46 | + PYPROJECT_VERSION="$(poetry version --short)" |
| 47 | + if [ "$PYPROJECT_VERSION" != "$VERSION" ]; then |
| 48 | + echo "Version mismatch: pyproject.toml has $PYPROJECT_VERSION, input is $VERSION" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Install dependencies |
| 53 | + run: poetry install --all-extras |
| 54 | + |
| 55 | + - name: Run tests |
| 56 | + run: poetry run pytest |
| 57 | + |
| 58 | + - name: Build distributions |
| 59 | + run: poetry build |
| 60 | + |
| 61 | + - name: Publish to PyPI |
| 62 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 63 | + |
| 64 | + - name: Extract release notes from changelog |
| 65 | + env: |
| 66 | + VERSION: ${{ inputs.version }} |
| 67 | + run: | |
| 68 | + awk -v version="$VERSION" ' |
| 69 | + $0 ~ "^## \\[" version "\\]" { found = 1; next } |
| 70 | + found && /^## / { exit } |
| 71 | + found { print } |
| 72 | + ' CHANGELOG.md > release-notes.md |
| 73 | + if ! [ -s release-notes.md ]; then |
| 74 | + echo "No changelog section found for $VERSION" > release-notes.md |
| 75 | + fi |
| 76 | +
|
| 77 | + - name: Create GitHub release |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + VERSION: ${{ inputs.version }} |
| 81 | + run: | |
| 82 | + gh release create "$VERSION" \ |
| 83 | + --title "$VERSION" \ |
| 84 | + --notes-file release-notes.md \ |
| 85 | + dist/* |
0 commit comments