Patches #6
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') | |
| ) | |
| 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 pandoc | |
| sudo apt-get update | |
| sudo apt-get install -y pandoc | |
| 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: 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: bump-my-version bump ${{ steps.bump.outputs.type }} | |
| 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: Update HISTORY.rst | |
| run: | | |
| # Convert CHANGELOG.md to rst and append to HISTORY.rst | |
| if [ -f CHANGELOG.md ]; then | |
| pandoc CHANGELOG.md -f markdown -t rst -o CHANGELOG.rst | |
| # Prepend new changelog to HISTORY.rst | |
| if [ -f HISTORY.rst ]; then | |
| cat CHANGELOG.rst HISTORY.rst > HISTORY_temp.rst | |
| mv HISTORY_temp.rst HISTORY.rst | |
| else | |
| mv CHANGELOG.rst HISTORY.rst | |
| fi | |
| fi | |
| - name: Commit and push changes to PR branch | |
| 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 }} | |
| publish-after-merge: | |
| # Run only after PR is merged with release labels | |
| if: | | |
| github.event.pull_request.merged == true && ( | |
| 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') | |
| ) | |
| 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 | |
| id: test-pypi | |
| uses: pypa/gh-action-pypi-publish@v1.13.0 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| skip-existing: true | |
| - name: Publish to PyPI | |
| if: steps.test-pypi.outcome == 'success' | |
| uses: pypa/gh-action-pypi-publish@v1.13.0 | |
| with: | |
| skip-existing: true |