Skip to content

Publish to PyPI

Publish to PyPI #3

Workflow file for this run

name: Publish to PyPI
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 0.2.0)'
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
pip install build twine
- name: Update version
if: github.event_name == 'workflow_dispatch'
run: |
sed -i "s/VERSION = '.*'/VERSION = '${{ inputs.version }}'/" checkend/version.py
sed -i "s/version = \".*\"/version = \"${{ inputs.version }}\"/" pyproject.toml
- name: Run tests
run: pytest -v
- name: Run linter
run: ruff check .
- name: Build package
run: python -m build
- name: Configure git
if: github.event_name == 'workflow_dispatch'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install git-cliff
if: github.event_name == 'workflow_dispatch'
uses: kenji-miyake/setup-git-cliff@v2
- name: Generate changelog
if: github.event_name == 'workflow_dispatch'
run: |
git-cliff --tag "v${{ inputs.version }}" -o CHANGELOG.md
- name: Commit version and changelog
if: github.event_name == 'workflow_dispatch'
run: |
git pull --rebase origin main
git add checkend/version.py pyproject.toml CHANGELOG.md
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Release v${{ inputs.version }}"
git push
fi
- name: Create tag and release
if: github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "Tag v${{ inputs.version }} already exists"
else
git tag "v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
fi
if gh release view "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "Release v${{ inputs.version }} already exists"
else
gh release create "v${{ inputs.version }}" \
--title "v${{ inputs.version }}" \
--generate-notes
fi
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*