Skip to content

Publish to PyPI

Publish to PyPI #165

Workflow file for this run

name: Publish to PyPI
on:
push:
branches: [main]
workflow_dispatch:
inputs:
pypi:
description: 'Target repository'
required: true
type: choice
default: 'pypi'
options:
- pypi
- testpypi
bump_type:
description: 'Version bump type'
required: true
type: choice
default: 'patch'
options:
- patch
- minor
- major
jobs:
pypi-upload:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel poetry
poetry config virtualenvs.create false
poetry install
- name: Increase poetry path version and add
id: get_version
run: |
git config --local user.email [email protected]
git config --local user.name mikel-brostrom
bump_type=${{ github.event.inputs.bump_type }}
commit_message=$(poetry version $bump_type)
new_version=$(echo $commit_message | grep -oE '[0-9]+\.[0-9]+\.[0-9]+$')
git add pyproject.toml
poetry build
echo "commit_message=$commit_message" >> $GITHUB_OUTPUT
echo "new_version=$new_version" >> $GITHUB_OUTPUT
if: ${{ success() }}
- name: Update __init__.py version and add
run: |
sed -i "s/__version__ = '.*'/__version__ = '${{ steps.get_version.outputs.new_version }}'/" boxmot/__init__.py
git add boxmot/__init__.py
if: ${{ success() }}
- name: Update citation pkg version and add
run: |
sed -i "s/version: .*/version: ${{ steps.get_version.outputs.new_version }}/" CITATION.cff
git add CITATION.cff
if: ${{ success() }}
- name: Commit and push updated version
run: |
git commit -m "${{ steps.get_version.outputs.commit_message }}"
git push
if: ${{ success() }}
- name: Publish to PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: |
if [ "${{ github.event.inputs.pypi }}" == "pypi" ]; then
poetry publish
else
poetry config repositories.testpypi https://test.pypi.org/legacy/
# poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_TOKEN }}
poetry config http-basic.testpypi "__token__" ${{ secrets.TEST_PYPI_TOKEN }}
poetry publish --repository testpypi
fi
if: ${{ success() }}
- name: Create code release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.new_version }}
release_name: Release v${{ steps.get_version.outputs.new_version }}
draft: false
prerelease: false
if: ${{ success() }}