Release: Publish to PyPi #9
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
| # Step 6: Builds and publishes the package to PyPI from a release/v{version} branch. | |
| # Creates a merge-back PR (step 7) to sync release changes to main. | |
| name: "Release: Publish to PyPi" | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Validate branch | |
| run: | | |
| if [[ ! "${GITHUB_REF_NAME}" =~ ^release/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: Must run from a release/v* branch (e.g., release/v0.3.0)" | |
| exit 1 | |
| fi | |
| - name: Extract version | |
| id: version | |
| run: | | |
| VERSION="${GITHUB_REF_NAME}" | |
| VERSION="${VERSION#release/v}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Publishing version: $VERSION" | |
| - uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to PyPI | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
| run: uv publish | |
| - name: Create merge-back PR | |
| env: | |
| GH_TOKEN: ${{ secrets.RELEASE_PAT }} | |
| STEPS_VERSION_OUTPUTS_VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| gh pr create \ | |
| --base main \ | |
| --head "${GITHUB_REF_NAME}" \ | |
| --title "chore: merge release v${STEPS_VERSION_OUTPUTS_VERSION} to main" \ | |
| --body "Syncs version bump and CHANGELOG from release v${STEPS_VERSION_OUTPUTS_VERSION} to main." |