Skip to content

Release

Release #6

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*.*.*'
jobs:
prepare-release:
name: Prepare release version
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Extract version from tag
id: version
run: |
# Remove 'v' prefix from tag
TAG_VERSION=${GITHUB_REF#refs/tags/v}
echo "Release version: $TAG_VERSION"
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
- name: Update version in pyproject.toml
run: |
VERSION="${{ steps.version.outputs.version }}"
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
# Only commit if there are changes
if ! git diff-index --quiet HEAD --; then
git commit -m "chore: release version $VERSION"
git push origin HEAD:main
else
echo "Version already correct in pyproject.toml, skipping commit"
fi
build-and-publish:
name: Build and publish release to PyPI
needs: prepare-release
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: main # Get the version update commit
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload --skip-existing dist/*
create-github-release:
name: Create GitHub Release
needs: [prepare-release, build-and-publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: |
python -m build
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ needs.prepare-release.outputs.version }}
files: dist/*
draft: false
prerelease: false
bump-for-next-dev:
name: Bump version for next dev cycle
needs: [prepare-release, build-and-publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Bump to next patch version
run: |
CURRENT_VERSION="${{ needs.prepare-release.outputs.version }}"
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}"
echo "Bumping from $CURRENT_VERSION to $NEXT_VERSION for next dev cycle"
sed -i "s/^version = \".*\"/version = \"$NEXT_VERSION\"/" pyproject.toml
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: bump version to $NEXT_VERSION for next dev cycle [skip ci]"
git push