Skip to content

Update publish-to-pypi.yaml #6

Update publish-to-pypi.yaml

Update publish-to-pypi.yaml #6

name: Publish To PyPi
on:
push:
branches:
- master
tags:
- '*.*.*'
jobs:
check-version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11.4
uses: actions/setup-python@v4
with:
python-version: "3.11.4"
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
- name: Check Version
id: check-version
run: |
version=$(poetry version --short)
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "version=$version" >> $GITHUB_OUTPUT
else
echo "Not a valid version bump. Skipping tag creation."
exit 0
fi
- name: Create Tag
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.check-version.outputs.version != '' }}
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git tag ${{ steps.check-version.outputs.version }}
git push origin ${{ steps.check-version.outputs.version }}
release:
runs-on: ubuntu-latest
needs: check-version
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11.4
uses: actions/setup-python@v4
with:
python-version: "3.11.4"
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Build project for distribution
run: poetry build
- name: Publish to PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: poetry publish