-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds code coverage to the repository. Extends `ci-build.ps1` for local builds. Adds Report Generator for merging code coverage reports. Publishes to CodeCov. Updates some test parameters.
- Loading branch information
Showing
10 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ jobs: | |
Build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
@@ -30,9 +32,47 @@ jobs: | |
|
||
- name: dotnet test | ||
run: dotnet test -c release --no-build | ||
|
||
- name: ReportGenerator | ||
uses: danielpalme/[email protected] | ||
with: | ||
reports: coverage/*.cobertura.xml | ||
targetdir: coverage/report | ||
reporttypes: Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub | ||
|
||
- name: Check coverage thresholds | ||
shell: pwsh | ||
run: | | ||
$coverage = Get-Content -Raw coverage/report/Summary.json | ConvertFrom-Json | ||
if ($coverage.summary.linecoverage -lt 80 -or $coverage.summary.branchcoverage -lt 80 -or $coverage.summary.methodcoverage -lt 80) { | ||
Write-Error "Coverage does not meet threshold.`n`nCI build failed."; Exit 1 | ||
} | ||
# End ci-build.ps1 | ||
|
||
- name: Add coverage comment to PR | ||
if: github.event_name == 'pull_request' && always() # Still post coverage comment if tests failed | ||
run: gh pr comment $PR_NUMBER --body-file coverage/report/SummaryGithub.md | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUMBER: ${{ github.event.number }} | ||
|
||
- name: Publish coverage in build summary | ||
if: always() # Still publish coverage if tests failed | ||
run: cat coverage/report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | ||
|
||
- name: Upload coverage report to Codecov | ||
if: always() # Still upload to CodeCov if tests failed | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
disable_search: true | ||
fail_ci_if_error: true | ||
files: coverage/report/Cobertura.xml | ||
flags: unittests | ||
plugins: noop | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: SonarCloud Scan | ||
if: always() # Still run Sonar if tests failed | ||
uses: SonarSource/sonarcloud-github-action@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ node_modules/ | |
|
||
# Test | ||
coverage/ | ||
TestResults/ | ||
|
||
## IDE ## | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# .NET with `.esproj` Example | ||
|
||
Example repository with C# and JS/TS with build orchestration via `dotnet` (`.csproj` and `.esproj`). | ||
|
||
[![codecov](https://codecov.io/gh/connorjs/dotnet-with-esproj-example/graph/badge.svg?token=QFRYKH8OOY)](https://codecov.io/gh/connorjs/dotnet-with-esproj-example) | ||
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=connorjs_dotnet-with-esproj-example&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=connorjs_dotnet-with-esproj-example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
try { | ||
$env:CI = true | ||
dotnet restore | ||
dotnet build -c release --no-restore | ||
dotnet test -c release --no-build | ||
} finally { | ||
$env:CI = $null | ||
# Install reportgenerator if not present | ||
if (-not (Get-Command reportgenerator -ErrorAction SilentlyContinue)) { | ||
dotnet tool install --global dotnet-reportgenerator-globaltool | ||
} | ||
|
||
function Write-Color($color) { | ||
$fc = $host.UI.RawUI.ForegroundColor; $host.UI.RawUI.ForegroundColor = $color; Write-Output $args; $host.UI.RawUI.ForegroundColor = $fc | ||
} | ||
|
||
# Clean coverage directory | ||
Remove-Item -Recurse -Force coverage -ErrorAction SilentlyContinue | ||
|
||
# Run the build | ||
dotnet restore | ||
dotnet build -c release --no-restore | ||
dotnet test -c release --no-build | ||
reportgenerator -reports:"coverage/*.cobertura.xml" -targetdir:coverage/report -reporttypes:"Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub" -verbosity:Warning | ||
|
||
# Output coverage information | ||
$coverage = Get-Content -Raw coverage/report/Summary.json | ConvertFrom-Json | ||
$coverage.summary | Format-Table @{ L = 'Line'; E = { "$($_.linecoverage.toString() )%" }; A = 'center' }, @{ L = 'Branch'; E = { "$( $_.branchcoverage )%" }; A = 'center' }, @{ L = 'Method'; E = { "$( $_.methodcoverage )%" }; A = 'center' } | ||
if ($coverage.summary.linecoverage -lt 80 -or $coverage.summary.branchcoverage -lt 80 -or $coverage.summary.methodcoverage -lt 80) { | ||
Write-Color red "Coverage does not meet threshold.`n`nCI build failed."; Exit 1 | ||
} | ||
|
||
# Print success | ||
Write-Color green "CI build succeeded." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<DataCollectionRunSettings> | ||
<DataCollectors> | ||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<Configuration> | ||
<Format>cobertura</Format> | ||
<CodeCoverage> | ||
<Exclude> | ||
<ModulePath>.*test.dll$</ModulePath> | ||
</Exclude> | ||
</CodeCoverage> | ||
</Configuration> | ||
</DataCollector> | ||
</DataCollectors> | ||
</DataCollectionRunSettings> | ||
</RunSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters