From e79ef1212813dd10de38c59ff834d3c01f50b5c8 Mon Sep 17 00:00:00 2001 From: Luca Sartori Date: Sun, 17 Nov 2024 21:01:38 +0100 Subject: [PATCH] chore(ZCH-127): added missing sonar change_detections --- .github/workflows/sonar-step-analyze.yml | 43 ++++++++++++++++++- .../workflows/sonar-step-flutter-analyze.yml | 43 +++++++++++++++++++ .../sonar-step-springboot-analyze.yml | 43 +++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar-step-analyze.yml b/.github/workflows/sonar-step-analyze.yml index 212caa86..0d5456ea 100644 --- a/.github/workflows/sonar-step-analyze.yml +++ b/.github/workflows/sonar-step-analyze.yml @@ -34,13 +34,46 @@ on: required: false type: string default: ".coverage-reports/" - + CHECK_WORKDIR_CHANGES: + required: true + type: boolean + default: false + CHECK_CUSTOM_DIR: + required: false + type: string + default: "" + CHECK_CHANGES_BY_JOBS: + required: false + type: string + default: "all" env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }} jobs: + workdir-has-changes: + runs-on: ubuntu-latest + outputs: + changes-detected: ${{ steps.filter.outputs.changes-detected }} + steps: + - name: Set CHECK_DIR to custom directory if provided + if: ${{ inputs.CHECK_CUSTOM_DIR != '' }} + run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV + - name: Set default CHECK_DIR + if: ${{ inputs.CHECK_CUSTOM_DIR == '' }} + run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + changes-detected: + - "${{ env.CHECK_DIR }}/**" sonar-analyze: + needs: workdir-has-changes + if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}} runs-on: labels: ${{ inputs.RUN_ON }} group: ${{ inputs.RUNNERS_CONTAINER_GROUP }} @@ -68,3 +101,11 @@ jobs: ARTIFACT_FILENAME: ${{ inputs.ARTIFACT_FILENAME }} ARTIFACT_PATH: ${{ inputs.ARTIFACT_PATH }} env: "${{secrets}}" + + jobs-succeded: + needs: ["sonar-analyze"] + runs-on: ubuntu-latest + if: ${{ always()}} + steps: + - name: "Jobs: sonar-analyze didn't fail." + run: if [[ "${{ needs.sonar-analyze.result }}" == "failure" ]]; then exit 1; fi diff --git a/.github/workflows/sonar-step-flutter-analyze.yml b/.github/workflows/sonar-step-flutter-analyze.yml index 4b8f1e0c..cd6700fa 100644 --- a/.github/workflows/sonar-step-flutter-analyze.yml +++ b/.github/workflows/sonar-step-flutter-analyze.yml @@ -38,13 +38,48 @@ on: required: false type: boolean default: false + CHECK_WORKDIR_CHANGES: + required: true + type: boolean + default: false + CHECK_CUSTOM_DIR: + required: false + type: string + default: "" + CHECK_CHANGES_BY_JOBS: + required: false + type: string + default: "all" env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }} jobs: + workdir-has-changes: + runs-on: ubuntu-latest + outputs: + changes-detected: ${{ steps.filter.outputs.changes-detected }} + steps: + - name: Set CHECK_DIR to custom directory if provided + if: ${{ inputs.CHECK_CUSTOM_DIR != '' }} + run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV + - name: Set default CHECK_DIR + if: ${{ inputs.CHECK_CUSTOM_DIR == '' }} + run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + changes-detected: + - "${{ env.CHECK_DIR }}/**" + sonar-analyze: + needs: workdir-has-changes + if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}} runs-on: labels: ${{ inputs.RUN_ON }} group: ${{ inputs.RUNNERS_CONTAINER_GROUP }} @@ -71,3 +106,11 @@ jobs: - name: Run Sonar run: sonar-scanner -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.qualitygate.wait=${{ inputs.CHECK_QUALITY_GATE }} + + jobs-succeded: + needs: ["sonar-analyze"] + runs-on: ubuntu-latest + if: ${{ always()}} + steps: + - name: "Jobs: sonar-analyze didn't fail." + run: if [[ "${{ needs.sonar-analyze.result }}" == "failure" ]]; then exit 1; fi diff --git a/.github/workflows/sonar-step-springboot-analyze.yml b/.github/workflows/sonar-step-springboot-analyze.yml index 8866ec57..4798bd97 100644 --- a/.github/workflows/sonar-step-springboot-analyze.yml +++ b/.github/workflows/sonar-step-springboot-analyze.yml @@ -45,13 +45,48 @@ on: required: false type: string default: "" + CHECK_WORKDIR_CHANGES: + required: true + type: boolean + default: false + CHECK_CUSTOM_DIR: + required: false + type: string + default: "" + CHECK_CHANGES_BY_JOBS: + required: false + type: string + default: "all" env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }} jobs: + workdir-has-changes: + runs-on: ubuntu-latest + outputs: + changes-detected: ${{ steps.filter.outputs.changes-detected }} + steps: + - name: Set CHECK_DIR to custom directory if provided + if: ${{ inputs.CHECK_CUSTOM_DIR != '' }} + run: echo "CHECK_DIR=${{ inputs.CHECK_CUSTOM_DIR }}" >> $GITHUB_ENV + - name: Set default CHECK_DIR + if: ${{ inputs.CHECK_CUSTOM_DIR == '' }} + run: echo "CHECK_DIR=${{ inputs.WORKING_DIRECTORY }}" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + changes-detected: + - "${{ env.CHECK_DIR }}/**" + sonar-analyze: + needs: workdir-has-changes + if: ${{ !inputs.CHECK_WORKDIR_CHANGES || (needs.workdir-has-changes.outputs.changes-detected == 'true' && (inputs.CHECK_CHANGES_BY_JOBS == 'all' || contains(fromJson(inputs.CHECK_CHANGES_BY_JOBS), github.job)))}} runs-on: labels: ${{ inputs.RUN_ON }} group: ${{ inputs.RUNNERS_CONTAINER_GROUP }} @@ -76,3 +111,11 @@ jobs: - name: Run Sonar run: ./mvnw -ntp initialize sonar:sonar -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.qualitygate.wait=${{ inputs.CHECK_QUALITY_GATE }} + + jobs-succeded: + needs: ["sonar-analyze"] + runs-on: ubuntu-latest + if: ${{ always()}} + steps: + - name: "Jobs: sonar-analyze didn't fail." + run: if [[ "${{ needs.sonar-analyze.result }}" == "failure" ]]; then exit 1; fi