From 3992689f7364ce6dcf5cab9d16c880eebefb02fa Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Wed, 16 Oct 2024 11:08:28 +0200 Subject: [PATCH] feature: split sonar action from pr action --- .github/workflows/pull-request_backend.yml | 49 ++++++++++++++++++ .github/workflows/sonar.yaml | 60 ---------------------- 2 files changed, 49 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/sonar.yaml diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index e016f2b435..94f1846b7c 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -73,6 +73,55 @@ jobs: - name: Run unit & integration tests run: mvn -pl tx-models,tx-backend,tx-coverage -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B verify + Sonar: + needs: Test + permissions: + checks: write + pull-requests: write + runs-on: ubuntu-latest + if: success() + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + java-version: '${{ env.JAVA_VERSION }}' + distribution: 'temurin' + cache: 'maven' + + - name: Publish integration test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "${{ github.workspace }}/tx-backend/target/failsafe-reports/TEST-*.xml" + check_name: "Integration Test Results" + + - name: Publish unit test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "**/surefire-reports/TEST-*.xml" + check_name: "Unit Test Results" + + - name: Clean working directories + run: | + rm -rf .scannerwork + rm -rf .sonar + + - name: Cache SonarCloud packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Verify Sonar Scan + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} + SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} + SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} + run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=${{ github.workspace }}/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} + Publish-docker-image: # needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml deleted file mode 100644 index 8090e9ce16..0000000000 --- a/.github/workflows/sonar.yaml +++ /dev/null @@ -1,60 +0,0 @@ -name: "[BE][BUILT][DEPLOYMENT] Pull request" - -on: - workflow_run: - workflows: [ "[BE][BUILT] Sonar" ] - branches: [ main ] - types: [ completed ] - -env: - GHCR_REGISTRY: ghcr.io - JAVA_VERSION: 17 - DOCKER_HUB_REGISTRY_NAMESPACE: tractusx - BACKEND_IMAGE_DOCKER_HUB: traceability-foss -jobs: - Sonar: - permissions: - checks: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 - with: - java-version: '${{ env.JAVA_VERSION }}' - distribution: 'temurin' - cache: 'maven' - - - name: Publish integration test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "${{ github.workspace }}/tx-backend/target/failsafe-reports/TEST-*.xml" - check_name: "Integration Test Results" - - - name: Publish unit test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "**/surefire-reports/TEST-*.xml" - check_name: "Unit Test Results" - - - name: Clean working directories - run: | - rm -rf .scannerwork - rm -rf .sonar - - - name: Cache SonarCloud packages - uses: actions/cache@v4 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - - name: Verify Sonar Scan - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} - SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} - SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} - run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=${{ github.workspace }}/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }}