Workflow file for this run
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 to PyPI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "flowquery-py/src/**" | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - "flowquery-py/src/**" | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| target: | |
| description: "Publish target" | |
| required: true | |
| default: "testpypi" | |
| type: choice | |
| options: | |
| - testpypi | |
| - pypi | |
| permissions: | |
| contents: write | |
| jobs: | |
| bump-version: | |
| name: Bump version | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_version: ${{ steps.bump.outputs.new_version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - name: Bump Python package version | |
| id: bump | |
| working-directory: flowquery-py | |
| run: | | |
| # Get current version from pyproject.toml | |
| CURRENT=$(grep -Po '(?<=^version = ")[^"]+' pyproject.toml) | |
| echo "Current version: $CURRENT" | |
| # Parse and bump patch version | |
| IFS='.' read -r major minor patch <<< "$CURRENT" | |
| NEW_VERSION="$major.$minor.$((patch + 1))" | |
| echo "New version: $NEW_VERSION" | |
| # Update pyproject.toml | |
| sed -i "s/^version = \"$CURRENT\"/version = \"$NEW_VERSION\"/" pyproject.toml | |
| # Commit and push | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add pyproject.toml | |
| git commit -m "chore(py): bump version to $NEW_VERSION [skip ci]" | |
| git push | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| build: | |
| name: Build distribution | |
| needs: [bump-version] | |
| if: always() && (needs.bump-version.result == 'success' || needs.bump-version.result == 'skipped') | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: flowquery-py | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| fetch-depth: 0 | |
| - name: Pull latest changes | |
| if: needs.bump-version.result == 'success' | |
| run: git pull origin main | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install build dependencies | |
| run: pip install build | |
| - name: Build package | |
| run: python -m build | |
| - name: Upload distribution artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: flowquery-py/dist/ | |
| publish-testpypi: | |
| name: Publish to TestPyPI | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi' | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: testpypi | |
| url: https://test.pypi.org/p/flowquery | |
| steps: | |
| - name: Download distribution artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Publish to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| trusted-publisher: false | |
| publish-pypi: | |
| name: Publish to PyPI | |
| if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'pypi') | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/flowquery | |
| steps: | |
| - name: Download distribution artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| trusted-publisher: false |