Skip to content

Commit df07cd7

Browse files
committed
ci: add .NET coverage 🧮 (#6)
1 parent 2813e4b commit df07cd7

File tree

7 files changed

+72
-36
lines changed

7 files changed

+72
-36
lines changed

‎.github/workflows/azure-dev.yml‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
# Run when commits are pushed to main
1+
name: Default
2+
23
on:
3-
workflow_dispatch:
44
pull_request:
55
types: [opened, synchronize, reopened, closed]
66
branches:
77
- main
88
push:
99
branches:
1010
- main
11+
workflow_dispatch:
12+
13+
run-name: Deploy to ${{ inputs.deploy_target }} by @${{ github.actor }}
1114

1215
# Set up permissions for deploying with secretless Azure federated credentials
1316
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
1417
permissions:
1518
id-token: write
1619
contents: read
20+
pull-requests: write
1721

1822
concurrency:
1923
group: ${{ github.workflow }}-${{ github.ref }}
@@ -47,7 +51,8 @@ jobs:
4751
run: pnpm install --frozen-lockfile
4852

4953
- name: Install Playwright Browsers
50-
run: pnpx playwright install --with-deps
54+
run: pnpm exec playwright install --with-deps
55+
working-directory: Sandbox.EndToEndTests
5156

5257
- name: Install SOPS
5358
run: |
@@ -67,7 +72,34 @@ jobs:
6772
run: dotnet build
6873

6974
- name: Run .NET tests
70-
run: dotnet test --no-build
75+
run: dotnet test --no-build -- --coverage --coverage-output coverage.xml --coverage-output-format cobertura --coverage-settings "../coverage.config"
76+
77+
- name: ReportGenerator
78+
uses: danielpalme/[email protected]
79+
with:
80+
reports: '**/coverage.xml'
81+
targetdir: 'coveragereport'
82+
reporttypes: 'HtmlInline;Cobertura;MarkdownSummaryGithub'
83+
tag: '${{ github.run_number }}_${{ github.run_id }}'
84+
customSettings: 'minimumCoverageThresholds:lineCoverage=70'
85+
86+
- name: Upload .NET coverage report artifact
87+
uses: actions/upload-artifact@v4
88+
if: ${{ !cancelled() }}
89+
with:
90+
name: CoverageReport
91+
path: coveragereport
92+
93+
- name: Add comment to PR
94+
if: github.event_name == 'pull_request'
95+
run: gh pr comment $PR_NUMBER --edit-last --create-if-none --body-file coveragereport/SummaryGithub.md
96+
env:
97+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
PR_NUMBER: ${{ github.event.number }}
99+
100+
- name: Publish coverage in build summary
101+
run: cat coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
102+
shell: bash
71103

72104
- name: Build Angular workspace
73105
run: pnpm --filter="sandbox.angular-workspace" build
@@ -79,17 +111,18 @@ jobs:
79111
run: pnpm --filter="!sandbox.e2e" test
80112

81113
- name: E2E test frontend projects
82-
run: DEBUG=pw:webserver pnpm --filter="sandbox.e2e" test
114+
run: pnpm --filter="sandbox.e2e" test
83115
env:
84116
PLAYWRIGHT_USERNAME: ${{ secrets.PLAYWRIGHT_USERNAME }}
85117
PLAYWRIGHT_PASSWORD: ${{ secrets.PLAYWRIGHT_PASSWORD }}
118+
APPLICATION_URL: ${{ secrets.APPLICATION_URL }}
86119

87-
- name: 📦 Upload Test Results Artifact
120+
- name: Upload E2E Results Artifact
88121
uses: actions/upload-artifact@v4
89-
if: always()
122+
if: ${{ !cancelled() }}
90123
with:
91-
name: playwright-test-results
92-
path: playwright-report
124+
name: playwright-report
125+
path: ./Sandbox.EndToEndTests/playwright-report/
93126

94127
release:
95128
runs-on: ubuntu-latest

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ obj/
99
packages/
1010
.vs/
1111
TestResults/
12+
CoverageReport/
1213

1314
# Angular
1415
node_modules/

‎.runsettings‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎Sandbox.Architectural.Tests/DomainLayerTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ await Types()
2424
.That()
2525
.Are(Domain)
2626
.Should()
27-
.OnlyDependOn(Types().That().HaveFullNameMatching("(Domain|StronglyTypedIds|System)"))
27+
.OnlyDependOn(Types().That().HaveFullNameMatching("(Domain|StronglyTypedIds|System|Microsoft\\.CodeCoverage)"))
2828
.Because("Domain layer must only depend on itself")
2929
.Check(Architecture);
3030
}

‎Sandbox.EndToEndTests/playwright.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default defineConfig({
1818
/* Opt out of parallel tests on CI. */
1919
workers: process.env.CI ? 1 : undefined,
2020
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
21-
reporter: process.env.CI || process.env['ASPIRE'] ? 'list' : 'html',
21+
reporter: process.env.CI ? [['github'], ['html'], ['dot']] : process.env['ASPIRE'] ? 'list' : 'html',
2222
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2323
use: {
2424
/* Base URL to use in actions like `await page.goto('/')`. */

‎Sandbox.Modules.CustomerManagement.Tests/Sandbox.Modules.CustomerManagement.Tests.csproj‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<ItemGroup>
1313
<ProjectReference Include="..\Sandbox.ApiService\Sandbox.ApiService.csproj" />
14-
<ProjectReference Include="..\Sandbox.Modules.CustomerManagement\Sandbox.Modules.CustomerManagement.csproj" />
14+
<ProjectReference
15+
Include="..\Sandbox.Modules.CustomerManagement\Sandbox.Modules.CustomerManagement.csproj" />
1516
</ItemGroup>
16-
</Project>
17+
</Project>

‎coverage.config‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Configuration>
3+
<IncludeTestAssembly>False</IncludeTestAssembly>
4+
<CodeCoverage>
5+
<Attributes>
6+
<Exclude>
7+
<Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
8+
<Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
9+
<Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
10+
<Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute>
11+
</Exclude>
12+
</Attributes>
13+
<Sources>
14+
<Exclude>
15+
<Source>.*\\.*\.Generated\.cs$</Source>
16+
<Source>.*\\.*\.g\.cs$</Source>
17+
<Source>.*\\.*_g\.cs$</Source>
18+
<Source>.*\\Sandbox\.Migrations\\.*\.cs$</Source>
19+
<Source>.*\\.*\.Tests\\.*\.cs$</Source>
20+
<Source>.*\\.*\.IntegrationTests\\.*\.cs$</Source>
21+
</Exclude>
22+
</Sources>
23+
</CodeCoverage>
24+
</Configuration>

0 commit comments

Comments
 (0)