Publish to PyPI #23
This file contains hidden or 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: | |
| workflow_dispatch: | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install build tools | |
| run: pip install build twine | |
| - name: Bump build version | |
| run: | | |
| current=$(grep '^version' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | |
| major=$(echo "$current" | cut -d. -f1) | |
| minor=$(echo "$current" | cut -d. -f2) | |
| build=$(echo "$current" | cut -d. -f3) | |
| new="${major}.${minor}.$((build + 1))" | |
| sed -i "s/^version = \"${current}\"/version = \"${new}\"/" pyproject.toml | |
| echo "VERSION=${new}" >> "$GITHUB_ENV" | |
| echo "Bumped ${current} -> ${new}" | |
| - name: Build package | |
| run: python -m build | |
| - name: Upload to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | |
| run: python -m twine upload dist/* | |
| - name: Commit version bump | |
| run: | | |
| git config user.name "briankelley" | |
| git config user.email "briankelley@users.noreply.github.com" | |
| git add pyproject.toml | |
| git commit -m "build: bump version to ${VERSION} [skip ci]" | |
| git push |