|
1 | | -name: Release Gem |
| 1 | +name: Tag and Release Gem |
| 2 | + |
| 3 | +env: |
| 4 | + GEM_NAME: query_packwerk |
| 5 | + GEM_CLASS_NAME: QueryPackwerk |
2 | 6 |
|
3 | 7 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - v* |
| 8 | + pull_request: |
| 9 | + types: [closed] |
| 10 | + branches: [main] |
7 | 11 |
|
8 | 12 | permissions: |
9 | | - contents: read |
| 13 | + contents: write |
| 14 | + actions: read |
10 | 15 |
|
11 | 16 | jobs: |
12 | | - push: |
13 | | - if: | |
14 | | - github.event.workflow_run.conclusion == 'success' && |
15 | | - github.repository == 'rubyatscale/query_packwerk' && |
16 | | - startsWith(github.ref, 'refs/tags/v') |
| 17 | + tag: |
| 18 | + if: github.event.pull_request.merged == true |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Ruby |
| 24 | + uses: ruby/setup-ruby@v1 |
| 25 | + with: |
| 26 | + ruby-version: 3.2 |
| 27 | + |
| 28 | + - name: Determine release type |
| 29 | + id: version |
| 30 | + run: | |
| 31 | + if [[ "${{ github.event.pull_request.labels[*] }}" == *"major"* ]]; then |
| 32 | + echo "bump=major" >> $GITHUB_OUTPUT |
| 33 | + elif [[ "${{ github.event.pull_request.labels[*] }}" == *"minor"* ]]; then |
| 34 | + echo "bump=minor" >> $GITHUB_OUTPUT |
| 35 | + else |
| 36 | + echo "bump=patch" >> $GITHUB_OUTPUT |
| 37 | + fi |
| 38 | +
|
| 39 | + - name: Bump version |
| 40 | + run: | |
| 41 | + gem install bump |
| 42 | + bump ${{ steps.version.outputs.bump }} |
| 43 | +
|
| 44 | + - name: Commit and tag version bump |
| 45 | + run: | |
| 46 | + # Attribute commits to the last committer on HEAD |
| 47 | + git config --global user.email "$(git log -1 --pretty=format:'%ae')" |
| 48 | + git config --global user.name "$(git log -1 --pretty=format:'%an')" |
| 49 | + git remote set-url origin "https://x-access-token:${{ github.token }}@github.com/$GITHUB_REPOSITORY" |
| 50 | + VERSION=$(ruby -e "require './lib/${{ env.GEM_NAME }}/version'; puts ${{ env.GEM_CLASS_NAME }}::VERSION") |
| 51 | + git commit -am "Bump version to $VERSION" |
| 52 | + git tag "v$VERSION" |
| 53 | + git push origin main "v$VERSION" |
| 54 | + release: |
| 55 | + if: github.repository == 'rubyatscale/query_packwerk' |
17 | 56 | runs-on: ubuntu-latest |
18 | 57 | environment: release |
19 | 58 | permissions: |
|
0 commit comments