From 944b94a2b910f550fe007e3db7230547d12a2c44 Mon Sep 17 00:00:00 2001 From: Shawn Chan Date: Mon, 7 Apr 2025 15:00:20 +0100 Subject: [PATCH] feat(ci): automate SNAPSHOT version updates in develop post-release - Add GitHub Action to bump version to next SNAPSHOT post-release - Trigger on new version tags (v*) - Update POM version and push to develop branch --- .../gitflow-next-snapshot-version.yml | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/gitflow-next-snapshot-version.yml diff --git a/.github/workflows/gitflow-next-snapshot-version.yml b/.github/workflows/gitflow-next-snapshot-version.yml new file mode 100644 index 0000000..58538ae --- /dev/null +++ b/.github/workflows/gitflow-next-snapshot-version.yml @@ -0,0 +1,67 @@ +name: Update Develop to SNAPSHOT Version + +on: + push: + tags: + - 'v*' # Trigger only when release tags v* are pushed (e.g., v1.2.0) + +jobs: + update-version: + runs-on: ubuntu-latest + permissions: + contents: write # Needed to push to develop branch + + steps: + - name: Checkout develop branch + uses: actions/checkout@v4 + with: + ref: develop + fetch-depth: 0 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Get release tag version + id: tag_version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + with_v: false # Returns version without 'v' prefix + + - name: Calculate next SNAPSHOT version + id: version_calc + run: | + # Parse the version components (1.2.0 → 1.2.1-SNAPSHOT) + IFS='.' read -ra VERSION_PARTS <<< "${{ steps.tag_version.outputs.new_version }}" + MAJOR=${VERSION_PARTS[0]} + MINOR=${VERSION_PARTS[1]} + PATCH=${VERSION_PARTS[2]} + + # Increment patch version by convention + NEXT_PATCH=$((PATCH + 1)) + NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-SNAPSHOT" + + echo "Next version: $NEXT_VERSION" + echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT + + - name: Update POM version + run: | + mvn versions:set -DnewVersion=${{ steps.version_calc.outputs.NEXT_VERSION }} + mvn versions:commit # Clean up backup files + + - name: Commit and push version update + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + git add pom.xml + git commit -m "Update to ${{ steps.version_calc.outputs.NEXT_VERSION }} [skip ci]" + git pull --rebase # Handle potential concurrent changes + git push origin develop + + - name: Verify the update + run: | + echo "Version updated to:" + mvn help:evaluate -Dexpression=project.version -q -DforceStdout \ No newline at end of file