Build and publish package to PyPI #23
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: Build and publish package to PyPI | |
on: | |
workflow_dispatch: | |
inputs: | |
target: | |
description: 'Deployment target. Can be "pypi" or "testpypi"' | |
default: 'pypi' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.12"] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: python -m pip install wheel build | |
- name: Build package | |
run: python -m build | |
- name: Upload package | |
uses: actions/upload-artifact@v4.4.3 | |
with: | |
name: files | |
path: ./dist/ | |
if-no-files-found: error | |
publish: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download package | |
uses: actions/download-artifact@v4 | |
with: | |
name: files | |
path: dist | |
- name: Publish on PyPI | |
if: github.event.inputs.target == 'pypi' && github.ref == 'refs/heads/develop' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_TOKEN }} | |
packages_dir: dist/ | |
- name: Publish on TestPyPI | |
if: github.event.inputs.target == 'testpypi' && github.ref == 'refs/heads/develop' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.TESTPYPI_TOKEN }} | |
packages_dir: dist/ | |
repository_url: https://test.pypi.org/legacy/ |