From 999fa3080b0aaa51b39746b5d6b315367cead726 Mon Sep 17 00:00:00 2001 From: Barry Attwater Date: Tue, 14 May 2024 15:09:12 +0100 Subject: [PATCH] Autoversion --- .github/workflows/autoversion.yml | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/autoversion.yml diff --git a/.github/workflows/autoversion.yml b/.github/workflows/autoversion.yml new file mode 100644 index 0000000..ef895ef --- /dev/null +++ b/.github/workflows/autoversion.yml @@ -0,0 +1,47 @@ +name: Auto-Version new contributions to Flyway Community DB Support + +on: + pull_request: + branches: + - main + types: + - closed +jobs: + auto-version: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: Checkout Flyway Community DB Support + uses: actions/checkout@v4 + with: + ref: main + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + cache: 'maven' + - name: Check for new module + id: check_module + run: | + git fetch origin ${{ github.event.pull_request.head.ref }} + if git diff --name-only FETCH_HEAD..HEAD -- '*/pom.xml' | grep pom.xml; then + echo "::set-output name=NEW_MODULE::true" + else + echo "::set-output name=NEW_MODULE::false" + fi + - name: Update version + run: | + if ${{ steps.check_module.outputs.NEW_MODULE }}; then + NEW_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | awk -F'[.-]' '{print $1"."$2+1".0"}') + else + NEW_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | awk -F'[.-]' '{print $1"."$2"."$3+1}') + fi + mvn versions:set -DnewVersion=$NEW_VERSION + git commit -am "Bump Flyway Community DB Support to $NEW_VERSION" + - name: Tag and Push + run: | + git tag -a $NEW_VERSION -m "Flyway Community DB Support $NEW_VERSION" + git push origin main --tags + +