Skip to content

Release to PyPI

Release to PyPI #1

Workflow file for this run

name: Publish to PyPI
on:
workflow_dispatch:
inputs:
version_type:
description: "Version bump type"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major
push:
tags:
- "v*"
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Bump version (manual trigger)
if: github.event_name == 'workflow_dispatch'
id: bump_version
run: |
python scripts/bump_version.py ${{ github.event.inputs.version_type }}
echo "version=$(python -c "import re; content=open('setup.py').read(); print(re.search(r'version\s*=\s*[\"\\']([^\"\\']+)[\"\\']', content).group(1))")" >> $GITHUB_OUTPUT
- name: Extract version from tag
if: github.event_name == 'push'
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Update version in setup.py (tag trigger)
if: github.event_name == 'push'
run: |
VERSION=${{ steps.get_version.outputs.version }}
sed -i "s/version=\".*\"/version=\"$VERSION\"/" setup.py
echo "Updated setup.py with version: $VERSION"
- name: Build package
run: |
python -m build
- name: Check package
run: |
twine check dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
- name: Create GitHub Release (tag trigger)
if: github.event_name == 'push'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ steps.get_version.outputs.version }}
body: |
## Changes in version ${{ steps.get_version.outputs.version }}
See the [changelog](https://github.com/NIKX-Tech/sentor-ml-python-sdk/blob/main/CHANGELOG.md) for details.
draft: false
prerelease: false
- name: Commit version bump (manual trigger)
if: github.event_name == 'workflow_dispatch'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add setup.py
git commit -m "Bump version to ${{ steps.bump_version.outputs.version }}"
git push