Add code coverage and condense unit test actions #1
Workflow file for this run
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
name: Unit Tests | |
on: | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
timeout-minutes: 10 | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: [ "9.x" ] | |
test-project: [ "Api", "Client", "Data", "Web" ] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --no-restore | |
- name: Test with Code Coverage | |
run: dotnet test tests/${{ matrix.test-project }}.UnitTests --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory "TestResults/${{ matrix.test-project }}/${{ matrix.dotnet-version }}" | |
- name: Generate Code Coverage Report | |
uses: irongut/[email protected] | |
with: | |
filename: "TestResults/${{ matrix.test-project }}/${{ matrix.dotnet-version }}/**/coverage.cobertura.xml" | |
badge: true | |
fail_below_min: true | |
format: markdown | |
hide_branch_rate: true | |
hide_complexity: true | |
indicators: true | |
output: both | |
thresholds: "60 80" | |
- name: Upload results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.test-project }}-unit-test-results-${{ matrix.dotnet-version }} | |
path: TestResults/${{ matrix.test-project }}/${{ matrix.dotnet-version }} | |
if: ${{ always() }} | |
- name: Add Coverage PR Comment | |
uses: marocchino/sticky-pull-request-comment@v2 | |
if: github.event_name == 'pull_request' | |
with: | |
recreate: true | |
path: code-coverage-results.md |