Update publish-to-test-pypi.yml #31
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 Python 🐍 distributions 📦 to PyPI and TestPyPI | |
on: | |
push: | |
branches: | |
- main # Change 'main' to your branch name if necessary | |
jobs: | |
build-n-publish: | |
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" # Use a specific version of Python | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build twine | |
- name: Bump version | |
id: bump_version # Set an id to refer to this step's output | |
run: | | |
current_version=$(grep -oP '(?<=version=").*(?=")' setup.py) | |
new_version=$(echo $current_version | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') | |
sed -i "s/version=\"$current_version\"/version=\"$new_version\"/" setup.py | |
echo "::set-output name=new_version::$new_version" # Set new_version as an output | |
- name: Build a binary wheel and a source tarball | |
run: python -m build | |
- name: Publish distribution 📦 to Test PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
continue-on-error: false # Catch errors if any | |
- name: Publish distribution 📦 to PyPI | |
if: github.ref == 'refs/heads/main' && always() | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
- name: Create GitHub Release | |
if: github.ref == 'refs/heads/main' && always() | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.bump_version.outputs.new_version }} # Reference the bumped version | |
release_name: Release ${{ steps.bump_version.outputs.new_version }} | |
draft: false | |
prerelease: false |