diff --git a/template/.github/workflows/ci.yaml b/template/.github/workflows/ci.yaml index d0d1e90..45004fe 100644 --- a/template/.github/workflows/ci.yaml +++ b/template/.github/workflows/ci.yaml @@ -5,6 +5,7 @@ on: env: COVERAGE_THRESHOLD: 80 + ATOMI_SERVICE: let___svc___ jobs: precommit: @@ -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 @@ -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___' @@ -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: @@ -92,6 +95,7 @@ jobs: - precommit - publish - test + - sonarqube if: github.ref == 'refs/heads/main' runs-on: diff --git a/template/Taskfile.yaml b/template/Taskfile.yaml index 3ed2560..89f21a7 100644 --- a/template/Taskfile.yaml +++ b/template/Taskfile.yaml @@ -2,6 +2,7 @@ version: '3' env: COVERAGE_THRESHOLD: 80 + ATOMI_SERVICE: let___svc___ tasks: setup: @@ -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: diff --git a/template/scripts/ci/sonarqube.sh b/template/scripts/ci/sonarqube.sh index be91879..3a547ad 100755 --- a/template/scripts/ci/sonarqube.sh +++ b/template/scripts/ci/sonarqube.sh @@ -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!" diff --git a/template/scripts/ci/test.sh b/template/scripts/ci/test.sh index 1c5c9ce..ff77490 100755 --- a/template/scripts/ci/test.sh +++ b/template/scripts/ci/test.sh @@ -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 @@ -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}%"