From 11e27d2341e90fd00690d4dffb91b07ddae7a287 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 09:13:38 +0100 Subject: [PATCH 1/8] feat: add SonarQube integration for MacOS and update .gitignore for Mac-specific files --- .github/workflows/dotnet.yml | 7 +++++++ .gitignore | 4 ++++ sonar-project.properties | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 sonar-project.properties diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index d9333b7..937702a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -84,6 +84,13 @@ jobs: run: | echo "![Coverage](./coverage-report/badge_combined.svg)" > coverage-badge.md cat coverage-badge.md >> README.md + + - name : Sonarqube (SonarCloud) + if: matrix.platform.name == 'MacOS' + uses: SonarSource/sonarqube-scan-action@v4.2.1 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + publish_badge: runs-on: ubuntu-24.04 diff --git a/.gitignore b/.gitignore index 442c1e5..8f9a7e0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,7 @@ /codeql* /*.dot /*snyk* + +# Mac OS +.DS_Store +.AppleDouble \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..bb937a3 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,5 @@ +sonar.projectKey=magic5644_codeLineCounter + +# relative paths to source directories. More details and properties are described +# at https://docs.sonarsource.com/sonarqube-server/latest/project-administration/analysis-scope/ +sonar.sources=. \ No newline at end of file From 48457ac15ec2c4716c29aeac724421f7281c8360 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 09:25:18 +0100 Subject: [PATCH 2/8] feat: update SonarQube configuration to include organization --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index bb937a3..6ca7613 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,5 @@ sonar.projectKey=magic5644_codeLineCounter - +sonar.organization=magic5644 # relative paths to source directories. More details and properties are described # at https://docs.sonarsource.com/sonarqube-server/latest/project-administration/analysis-scope/ sonar.sources=. \ No newline at end of file From e0380dc32ab7340c1deaaee00487baa73766c624 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 10:18:05 +0100 Subject: [PATCH 3/8] feat: update GitHub Actions workflow to use SonarCloud with Ubuntu --- .github/workflows/dotnet.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 937702a..83c7e9a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -84,13 +84,21 @@ jobs: run: | echo "![Coverage](./coverage-report/badge_combined.svg)" > coverage-badge.md cat coverage-badge.md >> README.md - - - name : Sonarqube (SonarCloud) - if: matrix.platform.name == 'MacOS' - uses: SonarSource/sonarqube-scan-action@v4.2.1 + + sonarcloud: + name: SonarCloud + runs-on: ubuntu-24.04 + needs: build + steps: + - uses: actions/checkout@v4 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@v2 env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} publish_badge: runs-on: ubuntu-24.04 From 266c0240d382bd4061ab24482b58535c483d1c04 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 10:40:02 +0100 Subject: [PATCH 4/8] feat: enhance GitHub Actions workflow for MacOS with SonarCloud integration and caching --- .github/workflows/dotnet.yml | 55 +++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 83c7e9a..6d1c22b 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -31,8 +31,44 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ matrix.dotnet.version }} + + - name: Setup Java + if: matrix.platform.name == 'MacOS' + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '21' + + - name: Cache SonarCloud packages + if: matrix.platform.name == 'MacOS' + uses: actions/cache@v4 + with: + path: ~/sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Cache SonarCloud scanner + if: matrix.platform.name == 'MacOS' + id: cache-sonar-scanner + uses: actions/cache@v4 + with: + path: ./.sonar/scanner + key: ${{ runner.os }}-sonar-scanner + restore-keys: ${{ runner.os }}-sonar-scanner + + - name: Install SonarCloud scanner + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' && matrix.platform.name == 'MacOS' + shell: pwsh + run: | + dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner + - name: Enforce SDK Version run: dotnet new globaljson --sdk-version ${{ steps.setup-dotnet.outputs.dotnet-version }} --force + + - name: pre_build + if: matrix.platform.name == 'MacOS' + run: ./.sonar/scanner/dotnet-sonarscanner begin /k:"magic5644_codeLineCounter" /o:"magic5644" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + - name: Build run: dotnet build -c Release - name: Test @@ -44,6 +80,10 @@ jobs: dotnet tool install --global dotnet-reportgenerator-globaltool reportgenerator -reports:test-result.cobertura.xml -targetdir:coverage-report -reporttypes:"Html;JsonSummary;MarkdownSummaryGithub;Badges" cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY + + - name: post_build + if: matrix.platform.name == 'MacOS' + run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - name: ReportGenerator if: matrix.platform.name == 'MacOS' @@ -85,20 +125,7 @@ jobs: echo "![Coverage](./coverage-report/badge_combined.svg)" > coverage-badge.md cat coverage-badge.md >> README.md - sonarcloud: - name: SonarCloud - runs-on: ubuntu-24.04 - needs: build - steps: - - uses: actions/checkout@v4 - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + publish_badge: runs-on: ubuntu-24.04 From 4540a34ca160672a31cae1d88eb520e5fd4e3fc9 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 10:45:53 +0100 Subject: [PATCH 5/8] feat: remove obsolete sonar-project.properties file --- sonar-project.properties | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 6ca7613..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,5 +0,0 @@ -sonar.projectKey=magic5644_codeLineCounter -sonar.organization=magic5644 -# relative paths to source directories. More details and properties are described -# at https://docs.sonarsource.com/sonarqube-server/latest/project-administration/analysis-scope/ -sonar.sources=. \ No newline at end of file From dd1d4c007ef61d5eda9a53e5f66e4620b13830a5 Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 11:12:03 +0100 Subject: [PATCH 6/8] feat: update MacOS build workflow to include coverage analysis and streamline SonarCloud integration --- .github/workflows/dotnet.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 6d1c22b..210796d 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -65,9 +65,14 @@ jobs: - name: Enforce SDK Version run: dotnet new globaljson --sdk-version ${{ steps.setup-dotnet.outputs.dotnet-version }} --force - - name: pre_build + - name: build and analyze if: matrix.platform.name == 'MacOS' - run: ./.sonar/scanner/dotnet-sonarscanner begin /k:"magic5644_codeLineCounter" /o:"magic5644" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + run: | + dotnet restore + ./.sonar/scanner/dotnet-sonarscanner begin /k:"magic5644_codeLineCounter" /o:"magic5644" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + dotnet build --no-incremental + dotnet-coverage collect 'dotnet test --no-build' -f xml -o 'coverage.xml' + ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - name: Build run: dotnet build -c Release @@ -80,12 +85,8 @@ jobs: dotnet tool install --global dotnet-reportgenerator-globaltool reportgenerator -reports:test-result.cobertura.xml -targetdir:coverage-report -reporttypes:"Html;JsonSummary;MarkdownSummaryGithub;Badges" cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY - - - name: post_build - if: matrix.platform.name == 'MacOS' - run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - - name: ReportGenerator + - name: ReportGenerator_CoverageReport if: matrix.platform.name == 'MacOS' uses: danielpalme/ReportGenerator-GitHub-Action@5.3.11 with: From c412fa8ca7ab0b0e636f1100a31438a284bd1e1e Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 11:14:28 +0100 Subject: [PATCH 7/8] feat: update dotnet workflow to include global dotnet-coverage tool for coverage collection --- .github/workflows/dotnet.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 210796d..327393c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -69,6 +69,7 @@ jobs: if: matrix.platform.name == 'MacOS' run: | dotnet restore + dotnet tool update --global dotnet-coverage ./.sonar/scanner/dotnet-sonarscanner begin /k:"magic5644_codeLineCounter" /o:"magic5644" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml dotnet build --no-incremental dotnet-coverage collect 'dotnet test --no-build' -f xml -o 'coverage.xml' From 9a0a3075325c4da1627d9b351fbf98c0cba14eab Mon Sep 17 00:00:00 2001 From: Gildas Le Bournault Date: Fri, 3 Jan 2025 11:19:03 +0100 Subject: [PATCH 8/8] feat: update dotnet workflow to disable full scan in SonarCloud integration --- .github/workflows/dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 327393c..e59248a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -70,12 +70,12 @@ jobs: run: | dotnet restore dotnet tool update --global dotnet-coverage - ./.sonar/scanner/dotnet-sonarscanner begin /k:"magic5644_codeLineCounter" /o:"magic5644" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + ./.sonar/scanner/dotnet-sonarscanner begin /k:"magic5644_codeLineCounter" /o:"magic5644" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.scanner.scanAll=false dotnet build --no-incremental dotnet-coverage collect 'dotnet test --no-build' -f xml -o 'coverage.xml' ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - - name: Build + - name: Build Release run: dotnet build -c Release - name: Test if: matrix.platform.name == 'MacOS'