Update publish.yml #4
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 Python Package | ||
| on: | ||
| push: | ||
| branches: | ||
| - master # or 'main', adjust to your default branch | ||
| jobs: | ||
| bump-version-and-publish-testpypi: | ||
| if: github.ref == 'refs/heads/master' # Only on pushes to master | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.x' | ||
| - name: Install bump2version and build tools | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install bump2version==1.0.1 build twine | ||
| - name: Bump patch version, commit, and tag | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| git config user.name "github-actions" | ||
| git config user.email "[email protected]" | ||
| bump2version patch --allow-dirty --commit --tag | ||
| git push origin HEAD:master | ||
| git push --tags | ||
| - name: Build package | ||
| run: python -m build | ||
| - name: Upload to TestPyPI | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }} | ||
| run: twine upload --repository-url https://test.pypi.org/legacy/ dist/* | ||
| publish-to-pypi: | ||
| if: startsWith(github.ref, 'refs/tags/v') # On version tags only | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.x' | ||
| - name: Install build tools | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build twine | ||
| - name: Build package | ||
| run: python -m build | ||
| - name: Upload to PyPI | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | ||
| run: twine upload dist/* | ||