Github - Building C#.net application using github actions.
Setup:
Assuming you have the solution with class library and test project using xunit. Make sure the following packages are included in the test project.
The below yaml builds, tests and generate the code coverage report.
name: .NET
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory coverage
- name: ReportGenerator
uses: danielpalme/ReportGenerator-GitHub-Action@5.1.10
with:
reports: coverage/*/coverage.cobertura.xml
targetdir: CoverageReport
reporttypes: Html;Cobertura
- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: CoverageReport/Cobertura.xml
badge: true
format: 'markdown'
output: 'both'
fail_below_min: true
thresholds: '80 90'
- name: Write to Job Summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
As you can see the above yaml, Code coverage summary step generates the report and below step as the summary to build summary.
The below step generates the summary report.
- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: CoverageReport/Cobertura.xml
badge: true
format: 'markdown'
output: 'both'
fail_below_min: true
thresholds: '80 90'
In the above step, the highlighted text indicates, it fails the step if the coverage drops down to 80%
Comments
Post a Comment