Skip to content

Merge pull request #8 from unexcellent/publish_on_version_change #70

Merge pull request #8 from unexcellent/publish_on_version_change

Merge pull request #8 from unexcellent/publish_on_version_change #70

Workflow file for this run

name: Publish to PyPI
on:
push:
branches: ["*"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
shell: bash
- name: Configure Poetry to use virtual environment inside the project
run: poetry config virtualenvs.in-project true
- name: Install dependencies
run: poetry install
- name: Run Tests
run: poetry run pytest
- name: Build the package
run: poetry build
- name: Check if version exists on PyPI
id: check-version
run: |
PACKAGE_NAME=$(poetry version | awk '{print $1}')
PACKAGE_VERSION=$(poetry version | awk '{print $2}')
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" https://pypi.org/pypi/$PACKAGE_NAME/$PACKAGE_VERSION/json)
if [ "$RESPONSE" == "200" ]; then
echo "Version $PACKAGE_VERSION already exists on PyPI. Skipping publish step."
echo "exists=true" >> $GITHUB_ENV
else
echo "exists=false" >> $GITHUB_ENV
fi
shell: bash
- name: Publish to PyPI (release only)
if: env.exists == 'false'
run: poetry publish --no-interaction --username __token__ --password ${{ secrets.PYPI_TOKEN }}