From 0820bd47bc05193e1aae97e24fac3a9eddb77189 Mon Sep 17 00:00:00 2001 From: dougollerenshaw Date: Thu, 19 Sep 2024 14:00:53 -0700 Subject: [PATCH] Updated bump_version.yml action --- .github/workflows/bump_version.yml | 49 ++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml index 6c0c063..fca8751 100644 --- a/.github/workflows/bump_version.yml +++ b/.github/workflows/bump_version.yml @@ -1,15 +1,58 @@ -name: Bump version +name: Version Management on: + pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] push: branches: - main jobs: + preview-bump: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + name: "Preview version bump" + steps: + - name: Check out + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install commitizen + run: pip install commitizen + + - name: Preview version bump + id: preview + run: | + if git log -1 --pretty=%B | grep -qE '^(feat|fix|BREAKING CHANGE):|#(minor|major)'; then + NEW_VERSION=$(cz bump --dry-run) + else + NEW_VERSION=$(cz bump --increment PATCH --dry-run) + fi + echo "New version would be: $NEW_VERSION" + echo "::set-output name=new_version::$NEW_VERSION" + + - name: Comment PR + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.name, + body: 'When merged, this PR will bump the version to: ${{ steps.preview.outputs.new_version }}' + }) + bump-version: - if: "!startsWith(github.event.head_commit.message, 'bump:')" + if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest - name: "Bump version and create changelog with commitizen" + name: "Bump version and create changelog" steps: - name: Check out uses: actions/checkout@v2