Publish to PyPI #34
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 to PyPI | |
on: | |
push: | |
tags: | |
- 'v*' | |
workflow_dispatch: | |
inputs: | |
task: | |
description: 'PyPI or TestPyPI' | |
required: true | |
default: 'None' | |
type: choice | |
options: | |
- none | |
- testpypi | |
- pypi | |
- all | |
jobs: | |
publish: | |
name: Publish to TestPyPI and PyPI | |
runs-on: [ubuntu-latest] | |
steps: | |
- name: Check tag | |
id: check-tag | |
run: | | |
task="${{ github.event.inputs.task }}" | |
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then | |
task="pypi" | |
fi | |
if [[ "$task" == "pypi" || "$task" == "all" ]]; then | |
echo "run_pypi=true" >> $GITHUB_OUTPUT | |
else | |
echo "run_pypi=false" >> $GITHUB_OUTPUT | |
fi | |
if [[ "$task" == "testpypi" || "$task" == "all" ]]; then | |
echo "run_testpypi=true" >> $GITHUB_OUTPUT | |
else | |
echo "run_testpypi=false" >> $GITHUB_OUTPUT | |
fi | |
if [[ "$task" == "none" ]]; then | |
echo "match=false" >> $GITHUB_OUTPUT | |
else | |
echo "match=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Checkout repo | |
if: steps.check-tag.outputs.match == 'true' | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Download Python wheels | |
if: steps.check-tag.outputs.match == 'true' | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
github_token: ${{secrets.GITHUB_TOKEN}} | |
workflow: wheels.yml | |
workflow_conclusion: success | |
branch: github | |
#name: cp.* | |
#name_is_regexp: true | |
#search_artifacts: true | |
path: dist/ | |
- name: Set up Python | |
if: steps.check-tag.outputs.match == 'true' | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Build a a source tarball | |
if: steps.check-tag.outputs.match == 'true' | |
run: | | |
find ./dist -name '*.whl' -exec mv {} ./dist \; | |
rm -r ./dist/cp* | |
python -m pip install build | |
python -m build --sdist | |
- name: Publish distribution to Test PyPI | |
if: steps.check-tag.outputs.run_testpypi == 'true' | |
uses: pypa/gh-action-pypi-publish@v1.10.3 | |
with: | |
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
repository_url: https://test.pypi.org/legacy/ | |
- name: Publish distribution to PyPI | |
if: steps.check-tag.outputs.run_pypi == 'true' | |
uses: pypa/gh-action-pypi-publish@v1.10.3 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} |