From 291f50345bd815699054d3ce179574ba604a1ac7 Mon Sep 17 00:00:00 2001 From: Ashley Willard Date: Fri, 27 Jun 2025 11:59:32 -0700 Subject: [PATCH] combine tag and release actions Co-authored-by: Martin Emde Co-authored-by: Sweta Sanghavi --- .github/workflows/release.yml | 59 +++++++++++++++++++++++++++++------ .github/workflows/tag.yml | 53 ------------------------------- 2 files changed, 49 insertions(+), 63 deletions(-) delete mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 55eac5c..6265d43 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,19 +1,58 @@ -name: Release Gem +name: Tag and Release Gem + +env: + GEM_NAME: query_packwerk + GEM_CLASS_NAME: QueryPackwerk on: - push: - tags: - - v* + pull_request: + types: [closed] + branches: [main] permissions: - contents: read + contents: write + actions: read jobs: - push: - if: | - github.event.workflow_run.conclusion == 'success' && - github.repository == 'rubyatscale/query_packwerk' && - startsWith(github.ref, 'refs/tags/v') + tag: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + + - name: Determine release type + id: version + run: | + if [[ "${{ github.event.pull_request.labels[*] }}" == *"major"* ]]; then + echo "bump=major" >> $GITHUB_OUTPUT + elif [[ "${{ github.event.pull_request.labels[*] }}" == *"minor"* ]]; then + echo "bump=minor" >> $GITHUB_OUTPUT + else + echo "bump=patch" >> $GITHUB_OUTPUT + fi + + - name: Bump version + run: | + gem install bump + bump ${{ steps.version.outputs.bump }} + + - name: Commit and tag version bump + run: | + # Attribute commits to the last committer on HEAD + git config --global user.email "$(git log -1 --pretty=format:'%ae')" + git config --global user.name "$(git log -1 --pretty=format:'%an')" + git remote set-url origin "https://x-access-token:${{ github.token }}@github.com/$GITHUB_REPOSITORY" + VERSION=$(ruby -e "require './lib/${{ env.GEM_NAME }}/version'; puts ${{ env.GEM_CLASS_NAME }}::VERSION") + git commit -am "Bump version to $VERSION" + git tag "v$VERSION" + git push origin main "v$VERSION" + release: + if: github.repository == 'rubyatscale/query_packwerk' runs-on: ubuntu-latest environment: release permissions: diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml deleted file mode 100644 index 0add967..0000000 --- a/.github/workflows/tag.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Tag Release - -env: - GEM_NAME: query_packwerk - GEM_CLASS_NAME: QueryPackwerk - -on: - pull_request: - types: [closed] - branches: [main] - -permissions: - contents: write - actions: read - -jobs: - release: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.2 - - - name: Determine release type - id: version - run: | - if [[ "${{ github.event.pull_request.labels[*] }}" == *"major"* ]]; then - echo "bump=major" >> $GITHUB_OUTPUT - elif [[ "${{ github.event.pull_request.labels[*] }}" == *"minor"* ]]; then - echo "bump=minor" >> $GITHUB_OUTPUT - else - echo "bump=patch" >> $GITHUB_OUTPUT - fi - - - name: Bump version - run: | - gem install bump - bump ${{ steps.version.outputs.bump }} - - - name: Commit and tag version bump - run: | - # Attribute commits to the last committer on HEAD - git config --global user.email "$(git log -1 --pretty=format:'%ae')" - git config --global user.name "$(git log -1 --pretty=format:'%an')" - git remote set-url origin "https://x-access-token:${{ github.token }}@github.com/$GITHUB_REPOSITORY" - VERSION=$(ruby -e "require './lib/${{ env.GEM_NAME }}/version'; puts ${{ env.GEM_CLASS_NAME }}::VERSION") - git commit -am "Bump version to $VERSION" - git tag "v$VERSION" - git push origin main "v$VERSION"