From 94fe2078099667865b507ef8811e29c220f3e0b9 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 11 Nov 2024 13:18:29 -0300 Subject: [PATCH 1/6] feat: ensure the new configurations in generator.sh and github-actions.yml work even if it does not exist in the main branch. --- .github/workflows/github-actions.yml | 55 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 8a6d2a3d4de..4f20f99cab6 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -297,18 +297,24 @@ jobs: if: github.event_name == 'pull_request' id: calculate-md5sum-main working-directory: /tmp/jhlite/${{ matrix.app }}/ + continue-on-error: true run: | - app_md5=$(find . \ - -not -path './.git/*' \ - -not -path './.github/*' \ - -not -path './.jhipster/*' \ - -not -path './node_modules/*' \ - -not -path './target/*' \ - -not -path './build/*' \ - -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | head -n1 | cut -d " " -f1) - echo main branch hash from project ${{ matrix.app }} $app_md5 - echo "hash=$app_md5" >> $GITHUB_OUTPUT - ls -al /tmp/jhlite/${{ matrix.app }} + if [ -d "/tmp/jhlite/${{ matrix.app }}" ]; then + app_md5=$(find . \ + -not -path './.git/*' \ + -not -path './.github/*' \ + -not -path './.jhipster/*' \ + -not -path './node_modules/*' \ + -not -path './target/*' \ + -not -path './build/*' \ + -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | head -n1 | cut -d " " -f1) + echo "hash=$app_md5" >> $GITHUB_OUTPUT + echo "exists=true" >> $GITHUB_OUTPUT + echo "main branch hash from project ${{ matrix.app }} $app_md5" + else + echo "App does not exist in main branch" + echo "exists=false" >> $GITHUB_OUTPUT + fi - name: 'Clean: delete ${{ matrix.app }} from main branch' if: github.event_name == 'pull_request' run: | @@ -352,22 +358,33 @@ jobs: - name: 'Compare hash main x pull request ${{ matrix.app }}' if: github.event_name == 'pull_request' id: compare-hash - working-directory: /tmp/jhlite/${{ matrix.app }}/ run: | - echo main branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum-main.outputs.hash }} - echo pull request branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum.outputs.hash }} - # Compare hashes - if [ "${{ steps.calculate-md5sum-main.outputs.hash }}" != "${{ steps.calculate-md5sum.outputs.hash }}" ]; then - echo "different=true" >> $GITHUB_OUTPUT + if [ "${{ steps.calculate-md5sum-main.outputs.exists }}" == "true" ]; then + echo "main branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum-main.outputs.hash }}" + echo "pull request branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum.outputs.hash }}" + if [ "${{ steps.calculate-md5sum-main.outputs.hash }}" != "${{ steps.calculate-md5sum.outputs.hash }}" ]; then + echo "different=true" >> $GITHUB_OUTPUT + else + echo "different=false" >> $GITHUB_OUTPUT + fi else - echo "different=false" >> $GITHUB_OUTPUT + echo "App doesn't exist in main branch - will run tests" + echo "different=true" >> $GITHUB_OUTPUT fi - name: 'Determine if tests are needed' id: tests-requirement-check run: | - if [[ "${{ steps.compare-hash.outputs.different }}" == "true" || "${{ steps.compare-hash.conclusion }}" == "skipped" ]]; then + if [[ "${{ github.event_name }}" != "pull_request" ]]; then + echo "Not a PR - will run tests" + echo "execute_tests=true" >> $GITHUB_OUTPUT + elif [[ "${{ steps.calculate-md5sum-main.outputs.exists }}" != "true" ]]; then + echo "App doesn't exist in main branch - will run tests" + echo "execute_tests=true" >> $GITHUB_OUTPUT + elif [[ "${{ steps.compare-hash.outputs.different }}" == "true" ]]; then + echo "Hashes are different - will run tests" echo "execute_tests=true" >> $GITHUB_OUTPUT else + echo "Hashes are identical - will skip tests" echo "execute_tests=false" >> $GITHUB_OUTPUT fi - name: 'Test: list ${{ matrix.app }}' From f2b0c60ba2a6ad0d1df1d2058408b0f3ffbea3b0 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 12 Nov 2024 08:59:10 -0300 Subject: [PATCH 2/6] fix: continue the steps in jobs: generation even if the step name: 'Generation: calculate md5sum ${{ matrix.app }} from main branch' failed in generate the matrix.app --- .github/workflows/github-actions.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 4f20f99cab6..9a3e8cec648 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -289,17 +289,21 @@ jobs: - name: 'Generation: generate ${{ matrix.app }} from main branch' if: github.event_name == 'pull_request' working-directory: ./main-branch/tests-ci/ + continue-on-error: true # Allow the step to continue even if generate.sh fails + id: generate-main run: | ./start.sh 7471 ./generate.sh ${{ matrix.app }} ${{ matrix.java-build-tool }} ${{ matrix.spring-config-format }} + GENERATE_EXIT_CODE=$? ./stop.sh + echo "exit_code=$GENERATE_EXIT_CODE" >> $GITHUB_OUTPUT - name: 'Generation: calculate md5sum ${{ matrix.app }} from main branch' if: github.event_name == 'pull_request' id: calculate-md5sum-main - working-directory: /tmp/jhlite/${{ matrix.app }}/ continue-on-error: true run: | - if [ -d "/tmp/jhlite/${{ matrix.app }}" ]; then + if [ -d "/tmp/jhlite/${{ matrix.app }}" ] && [ "${{ steps.generate-main.outputs.exit_code }}" == "0" ]; then + cd /tmp/jhlite/${{ matrix.app }}/ app_md5=$(find . \ -not -path './.git/*' \ -not -path './.github/*' \ @@ -312,7 +316,7 @@ jobs: echo "exists=true" >> $GITHUB_OUTPUT echo "main branch hash from project ${{ matrix.app }} $app_md5" else - echo "App does not exist in main branch" + echo "App does not exist in main branch or generation failed" echo "exists=false" >> $GITHUB_OUTPUT fi - name: 'Clean: delete ${{ matrix.app }} from main branch' From a746e9c84bf7b05b380e2f96f0f2f33b844c021e Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 12 Nov 2024 09:05:11 -0300 Subject: [PATCH 3/6] fix: remove unnecessary continue-on-error: true from step name: 'Generation: calculate md5sum ${{ matrix.app }} from main branch' --- .github/workflows/github-actions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 9a3e8cec648..0a8c1849a68 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -300,7 +300,6 @@ jobs: - name: 'Generation: calculate md5sum ${{ matrix.app }} from main branch' if: github.event_name == 'pull_request' id: calculate-md5sum-main - continue-on-error: true run: | if [ -d "/tmp/jhlite/${{ matrix.app }}" ] && [ "${{ steps.generate-main.outputs.exit_code }}" == "0" ]; then cd /tmp/jhlite/${{ matrix.app }}/ From c9a776c44ef3578f3d30986313875c77f5516f01 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 12 Nov 2024 09:27:51 -0300 Subject: [PATCH 4/6] fix: add a condition to only calculate the md5sum and compare the md5 hashes from the main and pull request if the application exists in the main branch --- .github/workflows/github-actions.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 0a8c1849a68..f51adf8d02f 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -344,6 +344,7 @@ jobs: ./generate.sh ${{ matrix.app }} ${{ matrix.java-build-tool }} ${{ matrix.spring-config-format }} ./stop.sh - name: 'Generation: calculate md5sum ${{ matrix.app }}' + if: github.event_name == 'pull_request' && steps.calculate-md5sum-main.outputs.exists == 'true' id: calculate-md5sum working-directory: /tmp/jhlite/${{ matrix.app }}/ run: | @@ -359,20 +360,15 @@ jobs: echo "hash=$app_md5" >> $GITHUB_OUTPUT ls -al /tmp/jhlite/${{ matrix.app }} - name: 'Compare hash main x pull request ${{ matrix.app }}' - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' && steps.calculate-md5sum-main.outputs.exists == 'true' id: compare-hash run: | - if [ "${{ steps.calculate-md5sum-main.outputs.exists }}" == "true" ]; then - echo "main branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum-main.outputs.hash }}" - echo "pull request branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum.outputs.hash }}" - if [ "${{ steps.calculate-md5sum-main.outputs.hash }}" != "${{ steps.calculate-md5sum.outputs.hash }}" ]; then - echo "different=true" >> $GITHUB_OUTPUT - else - echo "different=false" >> $GITHUB_OUTPUT - fi - else - echo "App doesn't exist in main branch - will run tests" + echo "main branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum-main.outputs.hash }}" + echo "pull request branch hash from project ${{ matrix.app }} ${{ steps.calculate-md5sum.outputs.hash }}" + if [ "${{ steps.calculate-md5sum-main.outputs.hash }}" != "${{ steps.calculate-md5sum.outputs.hash }}" ]; then echo "different=true" >> $GITHUB_OUTPUT + else + echo "different=false" >> $GITHUB_OUTPUT fi - name: 'Determine if tests are needed' id: tests-requirement-check From 4e26ffd6cd51f2f33e66530aa2e614c2752b60a7 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 12 Nov 2024 12:28:58 -0300 Subject: [PATCH 5/6] fix: modify step that generate the matrix.app from main to capture generate.sh exit code and call the ./stop.sh script --- .github/workflows/github-actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index f51adf8d02f..9bbbf12fcea 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -293,10 +293,10 @@ jobs: id: generate-main run: | ./start.sh 7471 - ./generate.sh ${{ matrix.app }} ${{ matrix.java-build-tool }} ${{ matrix.spring-config-format }} - GENERATE_EXIT_CODE=$? + (./generate.sh ${{ matrix.app }} ${{ matrix.java-build-tool }} ${{ matrix.spring-config-format }}; GENERATE_EXIT_CODE=$?) ./stop.sh echo "exit_code=$GENERATE_EXIT_CODE" >> $GITHUB_OUTPUT + exit $GENERATE_EXIT_CODE - name: 'Generation: calculate md5sum ${{ matrix.app }} from main branch' if: github.event_name == 'pull_request' id: calculate-md5sum-main From b3517b52fb8ab54123c96fb92079c5ac580662b7 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 12 Nov 2024 13:01:23 -0300 Subject: [PATCH 6/6] fix: use trap command to ensure that the ./stop script is called on exit of the step name Generation: generate ${{ matrix.app }} from main branch --- .github/workflows/github-actions.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 9bbbf12fcea..963f7b33f25 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -289,12 +289,15 @@ jobs: - name: 'Generation: generate ${{ matrix.app }} from main branch' if: github.event_name == 'pull_request' working-directory: ./main-branch/tests-ci/ - continue-on-error: true # Allow the step to continue even if generate.sh fails + continue-on-error: true id: generate-main run: | + # Set up trap to ensure stop.sh is called on exit + trap './stop.sh' EXIT + ./start.sh 7471 - (./generate.sh ${{ matrix.app }} ${{ matrix.java-build-tool }} ${{ matrix.spring-config-format }}; GENERATE_EXIT_CODE=$?) - ./stop.sh + ./generate.sh ${{ matrix.app }} ${{ matrix.java-build-tool }} ${{ matrix.spring-config-format }} + GENERATE_EXIT_CODE=$? echo "exit_code=$GENERATE_EXIT_CODE" >> $GITHUB_OUTPUT exit $GENERATE_EXIT_CODE - name: 'Generation: calculate md5sum ${{ matrix.app }} from main branch'