Skip to content

Commit 70c2a53

Browse files
committed
Add main-only code coverage job that runs dotCover and uploads to SonarCloud, and restore the coverage badge in README
1 parent 51039ef commit 70c2a53

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

.github/workflows/code-style.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ jobs:
236236
237237
sonarcloud:
238238
name: SonarCloud Analysis
239+
if: false # TEMP: disabled while verifying the coverage job; restore to `github.ref != 'refs/heads/main'` before merge.
239240
needs: detect-scope
240241
runs-on: ubuntu-24.04
241242

@@ -305,3 +306,71 @@ jobs:
305306
dotnet test account/Account.slnf --no-build &&
306307
dotnet test main/Main.slnf --no-build &&
307308
dotnet sonarscanner end
309+
310+
coverage:
311+
name: Code Coverage
312+
needs: detect-scope
313+
runs-on: ubuntu-24.04
314+
315+
steps:
316+
- name: Checkout Code
317+
uses: actions/checkout@v6
318+
319+
- name: Setup Node.js Environment
320+
uses: actions/setup-node@v6
321+
with:
322+
node-version: 24
323+
324+
- name: Install Node Modules
325+
working-directory: application
326+
run: npm ci
327+
328+
- name: Setup .NET Core SDK
329+
uses: actions/setup-dotnet@v5
330+
with:
331+
global-json-file: application/global.json
332+
333+
- name: Restore .NET Tools
334+
working-directory: application
335+
run: dotnet tool restore
336+
337+
- name: Restore .NET Dependencies
338+
working-directory: application
339+
run: dotnet restore
340+
341+
- name: Generate and Set User Secret for Token Signing Key
342+
working-directory: application/shared-kernel/SharedKernel
343+
run: |
344+
# Extract UserSecretsId from the .csproj file
345+
USER_SECRETS_ID=$(grep -oP '(?<=<UserSecretsId>).*?(?=</UserSecretsId>)' SharedKernel.csproj)
346+
347+
# Generate a 512-bit key and set it as a user secret that can be use for token signing when running tests
348+
dotnet user-secrets set "authentication-token-signing-key" "$(openssl rand -base64 64)" --id $USER_SECRETS_ID
349+
350+
- name: Setup Java JDK for SonarScanner
351+
uses: actions/setup-java@v5
352+
with:
353+
distribution: "microsoft"
354+
java-version: "17"
355+
356+
- name: Build Email Templates
357+
working-directory: application
358+
run: npx turbo run build --filter=@repo/emails
359+
360+
- name: Run dotCover and Upload to SonarCloud
361+
working-directory: application
362+
env:
363+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
364+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
365+
run: |
366+
if [[ "${{ vars.SONAR_PROJECT_KEY }}" == "" ]] || [[ "${{ vars.SONAR_ORGANIZATION }}" == "" ]] || [[ "${{ secrets.SONAR_TOKEN }}" == "" ]]; then
367+
echo "SonarCloud is not enabled. Skipping coverage upload."
368+
exit 0
369+
fi
370+
371+
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="coverage/*.html" /d:sonar.coverage.exclusions="**/*.ts,**/*.tsx,**/*.js,**/*.jsx,**/Tests/**,**/*.Tests/**" &&
372+
dotnet build PlatformPlatform.slnx --no-restore &&
373+
dotnet dotcover test account/Account.slnf --no-build --dcOutput=coverage/account.html --dcReportType=HTML --dcFilters="+:Account*;+:SharedKernel;-:*.Tests;-:type=*.AppHost.*" &&
374+
dotnet dotcover test main/Main.slnf --no-build --dcOutput=coverage/main.html --dcReportType=HTML --dcFilters="+:Main*;+:SharedKernel;-:*.Tests;-:type=*.AppHost.*" &&
375+
dotnet dotcover test AppGateway.Tests/AppGateway.Tests.csproj --no-build --dcOutput=coverage/app-gateway.html --dcReportType=HTML --dcFilters="+:AppGateway*;+:SharedKernel;-:*.Tests;-:type=*.AppHost.*" &&
376+
dotnet sonarscanner end

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[![GitHub issues with roadmap label](https://img.shields.io/github/issues-raw/platformplatform/PlatformPlatform/roadmap?label=roadmap&logo=github&color=%23006B75)](https://github.com/orgs/PlatformPlatform/projects/2/views/2?filterQuery=is%3Aopen+label%3Aroadmap)
1212
[![GitHub issues with bug label](https://img.shields.io/github/issues-raw/platformplatform/PlatformPlatform/bug?label=bugs&logo=github&color=red)](https://github.com/platformplatform/PlatformPlatform/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
1313

14+
<a href="https://sonarcloud.io/component_measures?id=PlatformPlatform_platformplatform&metric=coverage" target="_blank" rel="noopener noreferrer"><img src="https://sonarcloud.io/api/project_badges/measure?project=PlatformPlatform_platformplatform&metric=coverage" alt="Coverage" /></a>
1415
<a href="https://sonarcloud.io/summary/overall?id=PlatformPlatform_platformplatform" target="_blank" rel="noopener noreferrer"><img src="https://sonarcloud.io/api/project_badges/measure?project=PlatformPlatform_platformplatform&metric=alert_status" alt="Quality Gate Status" /></a>
1516
<a href="https://sonarcloud.io/component_measures?id=PlatformPlatform_platformplatform&metric=Security" target="_blank" rel="noopener noreferrer"><img src="https://sonarcloud.io/api/project_badges/measure?project=PlatformPlatform_platformplatform&metric=security_rating" alt="Security Rating" /></a>
1617
<a href="https://sonarcloud.io/component_measures?id=PlatformPlatform_platformplatform&metric=Reliability" target="_blank" rel="noopener noreferrer"><img src="https://sonarcloud.io/api/project_badges/measure?project=PlatformPlatform_platformplatform&metric=reliability_rating" alt="Reliability Rating" /></a>

0 commit comments

Comments
 (0)