From 3dd57f5c92eed871c56e875c3b1870a642520bd8 Mon Sep 17 00:00:00 2001 From: "Shkar T. Noori" Date: Thu, 21 Jul 2022 12:54:45 +0000 Subject: [PATCH] Enable sonarqube analysis --- .config/dotnet-tools.json | 4 +-- .github/workflows/sonarqube.yaml | 51 ++++++++++++++++++++++++++++++ .github/workflows/tests-base.yaml | 52 ++----------------------------- 3 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/sonarqube.yaml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 49bc7f3..b21c6eb 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-sonarscanner": { - "version": "5.6.0", + "version": "5.7.2", "commands": [ "dotnet-sonarscanner" ] @@ -15,4 +15,4 @@ ] } } -} \ No newline at end of file +} diff --git a/.github/workflows/sonarqube.yaml b/.github/workflows/sonarqube.yaml new file mode 100644 index 0000000..2508672 --- /dev/null +++ b/.github/workflows/sonarqube.yaml @@ -0,0 +1,51 @@ +name: Run SonarQube Analysis + +on: + push: + branches: + - main + + paths-ignore: + - "**.md" + - ".vscode/**" + +concurrency: + group: sonarqube-analysis + +jobs: + run-tests: + name: Run SonarQube Analysis + timeout-minutes: 10 + runs-on: ubuntu-latest + + env: + PROJECT_KEY: ditkrg_DIT.Workflower_AYF14rjSb80e2b0bns3t + SONARQUBE_HOST: ${{ secrets.SONARQUBE_HOST }} + SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} + ASPNETCORE_ENVIRONMENT: Testing + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: "zulu" + java-version: "11" + + - name: Restore tools + run: dotnet tool restore + + - name: Run Tests (SonarQube) + run: | + dotnet tool run dotnet-sonarscanner begin -k:"$PROJECT_KEY" \ + -d:sonar.login="$SONARQUBE_TOKEN" \ + -d:sonar.host.url="$SONARQUBE_HOST" \ + -d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + + dotnet build --no-incremental + dotnet dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml" + + dotnet tool run dotnet-sonarscanner end -d:sonar.login="$SONARQUBE_TOKEN" diff --git a/.github/workflows/tests-base.yaml b/.github/workflows/tests-base.yaml index f5053c2..b42a2bf 100644 --- a/.github/workflows/tests-base.yaml +++ b/.github/workflows/tests-base.yaml @@ -9,17 +9,6 @@ on: - "!.github/workflows/tests-base.yaml" workflow_call: - inputs: - sonarqube: - type: boolean - required: false - default: fals - - secrets: - SONARQUBE_HOST: - required: false - SONARQUBE_TOKEN: - required: false jobs: run-tests: @@ -28,51 +17,14 @@ jobs: runs-on: ubuntu-latest env: - PROJECT_KEY: ditkrg_DIT.Workflower_AYF14rjSb80e2b0bns3t - SONARQUBE_HOST: ${{ secrets.SONARQUBE_HOST }} - SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} ASPNETCORE_ENVIRONMENT: Testing steps: + - uses: actions/checkout@v3 + - uses: actions/setup-dotnet@v2 with: dotnet-version: "6.0.x" - - uses: actions/checkout@v3 - if: ${{ !inputs.sonarqube }} - - name: Run tests - if: ${{ !inputs.sonarqube }} run: dotnet test - - ############################### - ########## SONARQUBE ########## - ############################### - - name: Set up JDK 11 - uses: actions/setup-java@v3 - if: ${{ inputs.sonarqube }} - with: - distribution: "zulu" - java-version: "11" - - - uses: actions/checkout@v3 - if: ${{ inputs.sonarqube }} - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Restore tools - if: ${{ inputs.sonarqube }} - run: dotnet tool restore - - - name: Run tests (SonarQube) - if: ${{ inputs.sonarqube }} - run: | - dotnet tool run dotnet-sonarscanner begin -k:"$PROJECT_KEY" \ - -d:sonar.login="$SONARQUBE_TOKEN" \ - -d:sonar.host.url="$SONARQUBE_HOST" \ - -d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml - - dotnet build --no-incremental - dotnet dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml" - - dotnet tool run dotnet-sonarscanner end -d:sonar.login="$SONARQUBE_TOKEN"