From 9313d4129f83247d53508030cfd68c3d05f3c8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Greffier?= Date: Thu, 31 Oct 2024 13:44:00 +0100 Subject: [PATCH] Add hotfix management --- .github/workflows/hotfix_branch.yml | 32 +++++++++++++++++++++++++++ .github/workflows/on_pull_request.yml | 6 ++--- .github/workflows/on_push_master.yml | 2 +- .github/workflows/on_push_tag.yml | 10 ++++++++- .github/workflows/tag.yml | 2 +- 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/hotfix_branch.yml diff --git a/.github/workflows/hotfix_branch.yml b/.github/workflows/hotfix_branch.yml new file mode 100644 index 000000000..e02a5b6b0 --- /dev/null +++ b/.github/workflows/hotfix_branch.yml @@ -0,0 +1,32 @@ +name: Hotfix Branch + +on: + workflow_dispatch: + inputs: + tag_version: + description: 'Tag version' + required: true + +jobs: + create-branch: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - name: Checkout project + uses: actions/checkout@v4 + with: + token: ${{ secrets.CI_CD_TOKEN }} + + - name: Create hotfix branch + run: | + START_TAG=v${{ github.event.inputs.tag_version }} + echo "Start from tag $START_TAG" + MAJOR_MINOR_DIGIT=$(echo "$START_TAG" | cut -d '.' -f 1-2) + PATCH_DIGIT=$(echo "$START_TAG" | cut -d '.' -f 3) + NEW_PATCH_DIGIT=$((PATCH_DIGIT + 1)) + HOTFIX_VERSION="${MAJOR_MINOR_DIGIT}.${NEW_PATCH_DIGIT}" + HOTFIX_BRANCH_NAME="hotfix/$HOTFIX_VERSION" + echo "Create hotfix branch $HOTFIX_BRANCH_NAME" + git fetch --all + git checkout tags/$START_TAG -b $HOTFIX_BRANCH_NAME + git push origin $HOTFIX_BRANCH_NAME \ No newline at end of file diff --git a/.github/workflows/on_pull_request.yml b/.github/workflows/on_pull_request.yml index 42ebf3e3c..f82eff9b2 100644 --- a/.github/workflows/on_pull_request.yml +++ b/.github/workflows/on_pull_request.yml @@ -1,8 +1,8 @@ -name: Pull request +name: Pull Request on: pull_request: - branches: [ master ] + branches: [ master, hotfix/* ] jobs: build: @@ -33,7 +33,7 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} restore-keys: ${{ runner.os }}-gradle - - name: Check Style + - name: Check style run: ./gradlew checkstyleMain checkstyleTest - name: Build and analyze diff --git a/.github/workflows/on_push_master.yml b/.github/workflows/on_push_master.yml index f34618c93..7d788ab27 100644 --- a/.github/workflows/on_push_master.yml +++ b/.github/workflows/on_push_master.yml @@ -1,4 +1,4 @@ -name: Continuous integration +name: Continuous Integration on: push: diff --git a/.github/workflows/on_push_tag.yml b/.github/workflows/on_push_tag.yml index 7dc884e62..b6059729b 100644 --- a/.github/workflows/on_push_tag.yml +++ b/.github/workflows/on_push_tag.yml @@ -45,7 +45,15 @@ jobs: report_paths: '**/build/test-results/test/TEST-*.xml' - name: Docker - run: ./gradlew dockerBuild dockerPush -PreleaseLatest + run: | + LATEST_VERSION=$(git tag -l --sort=-version:refname | head -1 | cut -d 'v' -f 2) + if [ "$LATEST_VERSION" == "${{ steps.build_jar.outputs.current_version }}" ]; then + echo "Latest version is $LATEST_VERSION. Current version is ${{ steps.build_jar.outputs.current_version }}. Pushing latest tag." + ./gradlew dockerBuild dockerPush -PreleaseLatest + else + echo "Latest version is $LATEST_VERSION. Current version is ${{ steps.build_jar.outputs.current_version }}. Not pushing latest tag." + ./gradlew dockerBuild dockerPush + fi - name: Generate release changelog uses: mikepenz/release-changelog-builder-action@v5 diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 476dc63f0..1b1154758 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -10,7 +10,7 @@ on: jobs: tag: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/hotfix/v') steps: - name: Checkout project uses: actions/checkout@v4