Skip to content

Commit a49330f

Browse files
committed
💚 refactor CI workflow for improved clarity and coverage reporting
1 parent 6171279 commit a49330f

File tree

1 file changed

+47
-60
lines changed

1 file changed

+47
-60
lines changed

.github/workflows/test.yml

Lines changed: 47 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,50 @@ env:
1313

1414
jobs:
1515
lint:
16-
name: Lint & Build (Release, warn-as-error)
1716
runs-on: ubuntu-latest
18-
1917
steps:
20-
- uses: actions/checkout@v4
18+
- name: Checkout
19+
uses: actions/checkout@v4
2120

2221
- name: Setup .NET 8 SDK
2322
uses: actions/setup-dotnet@v4
2423
with:
25-
dotnet-version: '8.0.x'
26-
27-
- name: Cache NuGet
28-
uses: actions/cache@v4
29-
with:
30-
path: ~/.nuget/packages
31-
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.[cC][sS]proj', '**/*.props', '**/*.targets') }}
32-
restore-keys: nuget-${{ runner.os }}-
24+
dotnet-version: 8.0.x
3325

3426
- name: Restore
3527
run: dotnet restore
3628

37-
- name: dotnet format (verify)
38-
run: dotnet format --verify-no-changes --verbosity minimal
29+
- name: Verify formatting
30+
run: dotnet format --verify-no-changes --verbosity diagnostic
31+
32+
- name: Build (warnings as errors)
33+
run: dotnet build --configuration Release -p:TreatWarningsAsErrors=true
3934

40-
- name: Build (warnings -> errors)
41-
run: dotnet build --configuration Release -p:TreatWarningsAsErrors=true --no-restore
42-
4335
test:
44-
name: Test ${{ matrix.dotnet }} on ${{ matrix.os }}
4536
needs: lint
4637
runs-on: ${{ matrix.os }}
4738

4839
strategy:
4940
fail-fast: false
5041
matrix:
5142
os: [ ubuntu-latest ]
52-
dotnet: [ '8.0.x', '9.0.x' ]
43+
dotnet-version: [ '8.0.x', '9.0.x' ]
5344

5445
steps:
55-
- uses: actions/checkout@v4
46+
- name: Checkout
47+
uses: actions/checkout@v4
5648

57-
- name: Setup .NET SDK
49+
- name: Setup .NET ${{ matrix.dotnet-version }}
5850
uses: actions/setup-dotnet@v4
5951
with:
60-
dotnet-version: ${{ matrix.dotnet }}
52+
dotnet-version: ${{ matrix.dotnet-version }}
6153

6254
- name: Cache NuGet
6355
uses: actions/cache@v4
6456
with:
6557
path: ~/.nuget/packages
66-
key: nuget-${{ runner.os }}-${{ matrix.dotnet }}-${{ hashFiles('**/*.[cC][sS]proj') }}
58+
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
6759
restore-keys: |
68-
nuget-${{ runner.os }}-${{ matrix.dotnet }}-
6960
nuget-${{ runner.os }}-
7061
7162
- name: Restore
@@ -74,75 +65,71 @@ jobs:
7465
- name: Build
7566
run: dotnet build --configuration Release --no-restore
7667

77-
- name: Test + Coverage
68+
- name: Test (with coverage)
7869
run: |
7970
dotnet test --configuration Release --no-build \
8071
--verbosity normal \
8172
--logger "trx;LogFileName=test-results.trx" \
82-
--collect "XPlat Code Coverage"
73+
--collect "XPlat Code Coverage" \
74+
--results-directory ./TestResults \
75+
-- \
76+
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura \
77+
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.OutputDirectory=coverage
8378
84-
- name: Upload TRX
79+
- name: Upload TRX results
8580
uses: actions/upload-artifact@v4
86-
if: always()
8781
with:
88-
name: test-results-${{ matrix.dotnet }}
89-
path: '**/*.trx'
82+
name: test-results-${{ matrix.dotnet-version }}
83+
path: TestResults/*.trx
9084

91-
- name: Upload coverage
85+
- name: Upload raw coverage
9286
uses: actions/upload-artifact@v4
93-
if: always()
9487
with:
95-
name: coverage-${{ matrix.dotnet }}
96-
path: '**/coverage.cobertura.xml'
97-
88+
name: coverage-${{ matrix.dotnet-version }}
89+
path: coverage/**/*.cobertura.xml
90+
if-no-files-found: error
91+
9892
coverage:
99-
name: Coverage (merged)
100-
runs-on: ubuntu-latest
10193
needs: test
94+
if: github.event_name == 'push' || github.event_name == 'pull_request'
95+
runs-on: ubuntu-latest
10296

10397
steps:
104-
- uses: actions/checkout@v4
98+
- name: Checkout
99+
uses: actions/checkout@v4
105100

106101
- name: Setup .NET 8 SDK
107102
uses: actions/setup-dotnet@v4
108103
with:
109-
dotnet-version: '8.0.x'
110-
111-
- name: Restore
112-
run: dotnet restore
104+
dotnet-version: 8.0.x
113105

114-
- name: Build
115-
run: dotnet build --configuration Release --no-restore
116-
117-
- name: Test w/ coverage (8.0—single run)
118-
run: |
119-
dotnet test --configuration Release --no-build \
120-
--collect "XPlat Code Coverage" \
121-
--results-directory coverage \
122-
--settings coverlet.runsettings
106+
- name: Download coverage artifacts
107+
uses: actions/download-artifact@v4
108+
with:
109+
pattern: coverage-*
110+
path: coverage
123111

124112
- name: Install ReportGenerator
125113
run: dotnet tool install -g dotnet-reportgenerator-globaltool
126114

127-
- name: Generate HTML & Cobertura
115+
- name: Generate consolidated report
128116
run: |
129117
reportgenerator \
130-
-reports:"coverage/**/*.cobertura.xml"
118+
-reports:"coverage/**/*.cobertura.xml" \
131119
-targetdir:"coverage/report" \
132120
-reporttypes:"Html;Cobertura;JsonSummary"
133121
122+
- name: Upload coverage report artifact
123+
uses: actions/upload-artifact@v4
124+
with:
125+
name: coverage-report
126+
path: coverage/report
127+
134128
- name: Upload to Codecov
135129
uses: codecov/codecov-action@v5
136130
env:
137131
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
138132
with:
139133
files: coverage/report/Cobertura.xml
140134
flags: unittests
141-
name: codecov-umbrella
142-
fail_ci_if_error: false
143-
144-
- name: Upload coverage report artifact
145-
uses: actions/upload-artifact@v4
146-
with:
147-
name: coverage-report
148-
path: coverage/report/
135+
fail_ci_if_error: false

0 commit comments

Comments
 (0)