Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit a4a575d

Browse files
committed
Update to create separate test coverage script and incorporate into pipeline
1 parent 198967b commit a4a575d

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

.github/actions/perform-static-analysis/action.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ runs:
4848
- name: Build and analyze
4949
shell: bash
5050
run: |
51-
echo "${{ inputs.sonar_project_key }}"
52-
echo "${{ inputs.sonar_organisation_key }}"
53-
echo "${{ inputs.sonar_token }}"
54-
./.sonar/scanner/dotnet-sonarscanner begin /k:"${{ inputs.sonar_project_key }}" /o:"${{ inputs.sonar_organisation_key }}" /d:sonar.token="${{ inputs.sonar_token }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths="coverage.xml" /d:sonar.typescript.lcov.reportsPaths="src/web/coverage/lcov.info" /d:sonar.lang.patterns.ts=**/*.ts,**/*.tsx,**/*.cts,**/*.mts /d:sonar.lang.patterns.js=**/*.js,**/*.jsx,**/*.cjs,**/*.mjs,**/*.vue /d:sonar.javascript.enabled=false
55-
dotnet build src/ServiceLayer.sln
56-
./.sonar/scanner/dotnet-coverage collect -f xml -o coverage.xml dotnet test src/ServiceLayer.sln
57-
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ inputs.sonar_token }}"
51+
export SONAR_PROJECT_KEY="${{ inputs.sonar_project_key }}"
52+
export SONAR_ORGANISATION_KEY="${{ inputs.sonar_organisation_key }}"
53+
export SONAR_TOKEN="${{ inputs.sonar_token }}"
54+
make test-coverage

scripts/tests/coverage.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
: "${SONAR_TOKEN:?SONAR_TOKEN is required}"
5+
: "${SONAR_PROJECT_KEY:?SONAR_PROJECT_KEY is required}"
6+
: "${SONAR_ORGANISATION_KEY:?SONAR_ORGANISATION_KEY is required}"
7+
8+
SONAR_SCANNER="./.sonar/scanner/dotnet-sonarscanner"
9+
COVERAGE_FILES=$(find coverage -name '*.coverage.xml' | paste -sd "," -)
10+
11+
$SONAR_SCANNER begin /k:"$SONAR_PROJECT_KEY" /o:"$SONAR_ORGANISATION_KEY" /d:sonar.token="$SONAR_TOKEN" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths="$COVERAGE_FILES"
12+
13+
dotnet build src/ServiceLayer.sln
14+
15+
make test-unit
16+
17+
$SONAR_SCANNER end /d:sonar.token="$SONAR_TOKEN"

scripts/tests/unit.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ set -euo pipefail
44
COVERAGE_DIR="coverage"
55
TEST_PROJECTS=$(find tests -name '*.csproj')
66

7+
rm -rf "$COVERAGE_DIR"
8+
mkdir -p "$COVERAGE_DIR"
9+
710
for proj in $TEST_PROJECTS; do
8-
echo "🧪 Running tests for $proj..."
9-
dotnet test "$proj" \
10-
--collect:"XPlat Code Coverage" \
11-
--results-directory "$COVERAGE_DIR/$(basename "$proj" .csproj)"
11+
proj_name=$(basename "$proj" .csproj)
12+
out_file="$COVERAGE_DIR/$proj_name.coverage.xml"
13+
echo "🧪 Running coverage for $proj -> $out_file"
14+
dotnet-coverage collect -f xml -o "$out_file" dotnet test "$proj"
1215
done
13-
14-
echo "✅ All tests completed. Coverage reports in $COVERAGE_DIR/"

0 commit comments

Comments
 (0)