Publish to PyPI #138
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish to PyPI | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
inputs: | |
pypi: | |
description: 'Target repository (pypi or testpypi)' | |
required: true | |
default: 'pypi' | |
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 path version and get commit message | |
id: get_version | |
run: | | |
git config --local user.email [email protected] | |
git config --local user.name mikel-brostrom | |
commit_message=$(poetry version patch) | |
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: 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() }} |