From 02573dada9465269132990319ddde191619c6711 Mon Sep 17 00:00:00 2001 From: Nick Le Large Date: Thu, 7 Nov 2024 15:24:24 +0100 Subject: [PATCH] Add workflow to auto-bump the version --- .github/workflows/bump-version.yaml | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/bump-version.yaml diff --git a/.github/workflows/bump-version.yaml b/.github/workflows/bump-version.yaml new file mode 100644 index 0000000..ddb2b71 --- /dev/null +++ b/.github/workflows/bump-version.yaml @@ -0,0 +1,50 @@ +name: Bump version +on: + pull_request: + types: + - closed + branches: + - main + - github_action # TODO: Remove before merge + +jobs: + build: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Read version from file + run: | + # Read the version from the version file, only store the number (without the 'v') + INITIAL_VERSION=$(cat version | cut -d'v' -f2) + echo "Current version: $INITIAL_VERSION" + echo "INITIAL_VERSION=${INITIAL_VERSION}" >> $GITHUB_ENV + + - name: Bump version and push tag + id: bump_version + uses: anothrNick/github-tag-action@v1 + env: + DEFAULT_BUMP: patch + DRY_RUN: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + INITIAL_VERSION: ${{ env.INITIAL_VERSION }} + WITH_V: true + + - name: Update version file with new version + run: | + echo "New version: ${{ steps.bump_version.outputs.new_tag }}" + echo "VERSION=${{ steps.bump_version.outputs.new_tag }}" > version + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git add version + git commit -m "chore: update version file to ${{ steps.bump_version.outputs.new_tag }}" + git push + + - name: Push new tag + run: | + git tag ${{ steps.bump_version.outputs.new_tag }} + git push origin ${{ steps.bump_version.outputs.new_tag }}