From b9bfb3dbdb488769ad24809659586c0205340336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GREFFIER?= Date: Thu, 31 Oct 2024 12:13:04 +0100 Subject: [PATCH] Fix required execute option for reset-password command (#164) --- .github/workflows/hotfix_branch.yml | 32 +++++++++++++++++++ .github/workflows/on_pull_request.yml | 2 +- .github/workflows/on_push_tag.yml | 20 ++++++++++-- .github/workflows/tag.yml | 2 +- .../kafkactl/command/ResetPassword.java | 1 + .../kafkactl/command/ResetPasswordTest.java | 2 ++ 6 files changed, 55 insertions(+), 4 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 0000000..e02a5b6 --- /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 2c73a8c..01be14f 100644 --- a/.github/workflows/on_pull_request.yml +++ b/.github/workflows/on_pull_request.yml @@ -2,7 +2,7 @@ name: Pull request on: pull_request: - branches: [ main ] + branches: [ main, hotfix/* ] jobs: build-jar: diff --git a/.github/workflows/on_push_tag.yml b/.github/workflows/on_push_tag.yml index 67f230d..43f9dcc 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 @@ -100,7 +108,15 @@ jobs: echo current_version=$(echo $(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}')) >> $GITHUB_OUTPUT - name: Docker - run: ./gradlew dockerBuildNative dockerPushNative -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 dockerBuildNative dockerPushNative -PreleaseLatest + else + echo "Latest version is $LATEST_VERSION. Current version is ${{ steps.build_jar.outputs.current_version }}. Not pushing latest tag." + ./gradlew dockerBuildNative dockerPushNative + 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 3aa667b..c1b7e45 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/main' + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/hotfix/v') steps: - name: Checkout project uses: actions/checkout@v4 diff --git a/src/main/java/com/michelin/kafkactl/command/ResetPassword.java b/src/main/java/com/michelin/kafkactl/command/ResetPassword.java index 12cc64b..901489e 100644 --- a/src/main/java/com/michelin/kafkactl/command/ResetPassword.java +++ b/src/main/java/com/michelin/kafkactl/command/ResetPassword.java @@ -60,6 +60,7 @@ public Integer onAuthSuccess() throws IOException { + "for the namespace " + namespace + ".\n" + "Active connections will be killed instantly.\n\n" + "To execute this operation, rerun the command with option --execute."); + return 0; } return resourceService.resetPassword(namespace, user, output, commandSpec); diff --git a/src/test/java/com/michelin/kafkactl/command/ResetPasswordTest.java b/src/test/java/com/michelin/kafkactl/command/ResetPasswordTest.java index 4cd3630..06a2ebc 100644 --- a/src/test/java/com/michelin/kafkactl/command/ResetPasswordTest.java +++ b/src/test/java/com/michelin/kafkactl/command/ResetPasswordTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -104,6 +105,7 @@ void shouldNotUpdateUserWhenNotConfirmed() { assertTrue(sw.toString().contains("You are about to change your Kafka password for the namespace namespace.")); assertTrue(sw.toString().contains("Active connections will be killed instantly.")); assertTrue(sw.toString().contains("To execute this operation, rerun the command with option --execute.")); + verify(resourceService, never()).resetPassword(any(), any(), any(), any()); } @Test