Skip to content

Publish to PyPI

Publish to PyPI #53

Workflow file for this run

name: Publish to PyPI
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python
run: uv python install 3.12
- name: Get current version
id: get_version
run: |
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Calculate new version
id: version
run: |
CURRENT="${{ steps.get_version.outputs.current_version }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "${{ inputs.bump }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Update version in pyproject.toml and __init__.py
run: |
sed -i 's/^version = .*/version = "${{ steps.version.outputs.new_version }}"/' pyproject.toml
sed -i 's/^__version__ = .*/__version__ = "${{ steps.version.outputs.new_version }}"/' sidemantic/__init__.py
echo "Updated version to ${{ steps.version.outputs.new_version }}"
- name: Update lock file
run: uv lock
- name: Build package
run: uv build
- name: Publish to PyPI
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: uv publish --token $UV_PUBLISH_TOKEN
- name: Commit version bump and create tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml sidemantic/__init__.py uv.lock
git commit -m "Bump version to ${{ steps.version.outputs.new_version }}"
git tag -a "v${{ steps.version.outputs.new_version }}" -m "Release v${{ steps.version.outputs.new_version }}"
git push origin main
git push origin "v${{ steps.version.outputs.new_version }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ steps.version.outputs.new_version }}" \
--title "v${{ steps.version.outputs.new_version }}" \
--generate-notes