CI: Add tag check for release workflow #2
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] | |
jobs: | |
build-n-publish: | |
name: Build and publish Python distributions to PyPI | |
runs-on: ubuntu-latest | |
# Specifying a GitHub environment is optional, but strongly encouraged | |
environment: release | |
permissions: | |
# IMPORTANT: this permission is mandatory for trusted publishing | |
id-token: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.12 | |
- name: Update package cache | |
run: sudo apt-get -yq update | |
- name: Install Deps for installing project | |
run: pip install wheel | |
- name: Install Deps with pip | |
run: pip install . | |
- name: Install pypa/build | |
run: python -m pip install build --user | |
- name: Build a binary wheel and a source tarball | |
run: python setup.py sdist bdist_wheel | |
- name: Check Tag | |
id: check-tag | |
# https://packaging.python.org/en/latest/specifications/version-specifiers/#pre-releases | |
run: | | |
if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+a[0-9]+$ ]]; then | |
echo "match=prerelease" >> $GITHUB_OUTPUT | |
elif [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+b[0-9]+$ ]]; then | |
echo "match=prerelease" >> $GITHUB_OUTPUT | |
elif [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+rc[0-9]+$ ]]; then | |
echo "match=release" >> $GITHUB_OUTPUT | |
elif [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "match=release" >> $GITHUB_OUTPUT | |
else | |
echo "match=dirty" >> $GITHUB_OUTPUT | |
fi | |
- name: Publish distribution to Test PyPI | |
if: github.ref == 'refs/heads/main' && steps.check-tag.outputs.match == 'prerelease' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
- name: Publish distribution to PyPI | |
if: startsWith(github.ref, 'refs/tags/v') && steps.check-tag.outputs.match == 'release' | |
uses: pypa/gh-action-pypi-publish@release/v1 |