Skip to content

Commit

Permalink
fix: better coverage calculation in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Feb 1, 2025
1 parent 1f62218 commit 833292e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions template/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

env:
COVERAGE_THRESHOLD: 80
ATOMI_SERVICE: let___svc___

jobs:
precommit:
Expand All @@ -19,7 +20,7 @@ jobs:
- uses: AtomiCloud/actions.setup-nix@v1
- uses: AtomiCloud/actions.cache-nuget@v1

# pre commit
# Pre Commit
- name: Run pre-commit
run: nix develop .#ci -c ./scripts/ci/pre-commit.sh

Expand All @@ -35,7 +36,7 @@ jobs:
- uses: AtomiCloud/actions.setup-nix@v1
- uses: AtomiCloud/actions.cache-nuget@v1

# sonarqube
# Sonarqube
- name: Build and analyze
env:
ATOMI_PLATFORM: 'let___platform___'
Expand All @@ -58,8 +59,10 @@ jobs:
- uses: AtomiCloud/actions.setup-nix@v1
- uses: AtomiCloud/actions.cache-nuget@v1

# pre commit
# Test
- name: Run Test
env:
ATOMI_SERVICE: ${{ env.ATOMI_SERVICE }}
run: nix develop .#ci -c ./scripts/ci/test.sh ${{ env.COVERAGE_THRESHOLD }}

publish:
Expand Down Expand Up @@ -92,6 +95,7 @@ jobs:
- precommit
- publish
- test
- sonarqube

if: github.ref == 'refs/heads/main'
runs-on:
Expand Down
3 changes: 2 additions & 1 deletion template/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: '3'

env:
COVERAGE_THRESHOLD: 80
ATOMI_SERVICE: let___svc___

tasks:
setup:
Expand Down Expand Up @@ -31,7 +32,7 @@ tasks:
silent: true
cmds:
- dotnet build --no-incremental > /dev/null
- dotnet dotcover test --dcReportType=HTML --dcFilters=-:testhost
- dotnet dotcover test --dcReportType=HTML
test:clean:
desc: 'Clean the test results'
cmds:
Expand Down
2 changes: 1 addition & 1 deletion template/scripts/ci/sonarqube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ project="AtomiCloud_${ATOMI_PLATFORM}.${ATOMI_SERVICE}"
echo "📡 Starting SonarQube..."
dotnet sonarscanner begin /k:"${project}" /o:"${SONAR_ORG}" /d:sonar.token="${SONAR_TOKEN}" /d:sonar.host.url="${SONAR_HOST}" /d:sonar.cs.dotcover.reportsPaths=dotCover.Output.html
dotnet build --no-incremental
dotnet dotcover test --dcReportType=HTML --dcFilters=-:testhost
dotnet dotcover test --dcReportType=HTML
dotnet sonarscanner end /d:sonar.token="${SONAR_TOKEN}"
echo "✅ Done!"
6 changes: 4 additions & 2 deletions template/scripts/ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

[ "${ATOMI_SERVICE}" = '' ] && echo "❌ 'ATOMI_SERVICE' env var not set" && exit 1

threshold=${1:-50}

set -eou pipefail
Expand All @@ -19,11 +21,11 @@ echo "✅ Done!"

# run tests
echo "🧪 Running and Coverage..."
dotnet dotcover test --dcReportType=Json --dcFilters=-:testhost
dotnet dotcover test --dcReportType=Json
echo "✅ Done!"

# print coverage
coverage=$(jq -r '.CoveragePercent' ./dotCover.Output.json)
coverage=$(jq --arg name "${ATOMI_SERVICE}" '.Children[] | select(.Name == $name and .Kind == "Assembly") | .CoveragePercent' ./dotCover.Output.json)

echo "🧪 Current test coverage: ${coverage}%"

Expand Down

0 comments on commit 833292e

Please sign in to comment.