Skip to content

Publish to PyPI

Publish to PyPI #10

Workflow file for this run

name: Publish to PyPI
on:
workflow_dispatch:
inputs:
environment:
description: 'Choose environment'
required: true
type: choice
options:
- test
- production
default: test
permissions:
contents: read
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install build tools
run: python -m pip install --upgrade build twine
- name: Modify version for test environment
if: ${{ github.event.inputs.environment == 'test' }}
run: |
TIMESTAMP=$(date +%Y%m%d%H%M)
VERSION=$(grep -oP 'version = "\K[^"]+' pyproject.toml)
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1)).dev${TIMESTAMP}"
sed -i "s/version = \".*\"/version = \"${NEW_VERSION}\"/" pyproject.toml
- name: Build package
run: python -m build
- name: Publish to Test PyPI
if: ${{ github.event.inputs.environment == 'test' }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: twine upload --repository testpypi dist/*
- name: Publish to PyPI
if: ${{ github.event.inputs.environment == 'production' }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*