Patches #2
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 on PR merge | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, labeled] | |
| branches: | |
| - master | |
| permissions: | |
| contents: write | |
| id-token: write | |
| pull-requests: write | |
| jobs: | |
| update-version-and-changelog: | |
| # Run when PR has release labels (but not yet merged) | |
| if: | | |
| github.event.pull_request.merged == false && ( | |
| contains(github.event.pull_request.labels.*.name, 'release:major') || | |
| contains(github.event.pull_request.labels.*.name, 'release:minor') || | |
| contains(github.event.pull_request.labels.*.name, 'release:patch') || | |
| contains(github.event.pull_request.labels.*.name, 'release-dry-run') | |
| ) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install tools | |
| run: | | |
| pip install bump-my-version build | |
| sudo apt-get update | |
| cargo install git-cliff | |
| - name: Set up Git user | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| - name: Detect dry-run mode | |
| id: dryrun | |
| run: | | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'release-dry-run') }}" == "true" ]]; then | |
| echo "dryrun=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "dryrun=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Determine version bump type | |
| id: bump | |
| run: | | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:major') }}" == "true" ]]; then | |
| echo "type=major" >> $GITHUB_OUTPUT | |
| elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:minor') }}" == "true" ]]; then | |
| echo "type=minor" >> $GITHUB_OUTPUT | |
| else | |
| echo "type=patch" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Bump version | |
| run: | | |
| if [[ "${{ steps.dryrun.outputs.dryrun }}" == "true" ]]; then | |
| echo "Dry run: version bump simulated" | |
| else | |
| bump-my-version bump ${{ steps.bump.outputs.type }} | |
| fi | |
| env: | |
| BMV_ALLOW_DIRTY: "true" | |
| - name: Extract version | |
| id: version | |
| run: | | |
| VERSION=$(bump-my-version show current) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| run: | | |
| git cliff -o CHANGELOG.md | |
| echo "Generated changelog for version ${{ steps.version.outputs.version }}" | |
| - name: Commit and push changes to PR branch | |
| if: steps.dryrun.outputs.dryrun == 'false' | |
| run: | | |
| git add . | |
| git commit -m "chore: bump version to ${{ steps.version.outputs.version }} and update changelog [skip ci]" || echo "No changes to commit" | |
| git push origin HEAD:${{ github.head_ref }} | |
| - name: Comment on PR | |
| if: steps.dryrun.outputs.dryrun == 'false' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `✅ Version bumped to **${{ steps.version.outputs.version }}** and changelog updated. Please review the changes before merging.` | |
| }) | |
| publish-after-merge: | |
| # Run only after PR is merged | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install tools | |
| run: pip install bump-my-version build | |
| - name: Extract version | |
| id: version | |
| run: | | |
| VERSION=$(bump-my-version show current) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: v${{ steps.version.outputs.version }} | |
| body_path: CHANGELOG.md | |
| generate_release_notes: false | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@v1.10.0 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| skip-existing: true | |
| publish-pypi: | |
| needs: publish-after-merge | |
| if: needs.publish-after-merge.result == 'success' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Build package | |
| run: | | |
| pip install build | |
| python -m build | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@v1.10.0 | |
| with: | |
| skip-existing: true |