Publish PyPi package #1
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 PyPi package | |
on: | |
workflow_run: | |
workflows: ["Release Workflow"] | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
build-and-publish: | |
name: Build and publish PyPi package | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- name: Fetch tags | |
run: git fetch --depth=1 --tags | |
- name: Get latest tag or set default | |
id: latest_tag | |
run: | | |
TAG=$(git tag -l --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
if [ -z "$TAG" ]; then | |
TAG="latest" | |
fi | |
echo "::set-output name=tag::$TAG" | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install setuptools wheel twine toml build | |
- name: Update pyproject.toml | |
run: | | |
python -c "\ | |
import toml; \ | |
pyproject = toml.load('pyproject.toml'); \ | |
pyproject['project']['version'] = '${{ steps.latest_tag.outputs.tag }}'; \ | |
toml.dump(pyproject, open('pyproject.toml', 'w'))" | |
- name: Build and publish | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
python -m build | |
twine upload dist/* |