Skip to content

Commit d26cb7f

Browse files
authored
Fix test-results reporting for PR builds from repo forks (microsoft#82)
1 parent 898cdf3 commit d26cb7f

File tree

2 files changed

+67
-35
lines changed

2 files changed

+67
-35
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
22

3-
name: napi-dotnet build and test
3+
name: PR Verification
44

55
on:
6-
push:
7-
branches: [ "main" ]
86
pull_request:
97
branches: [ "main" ]
108
workflow_dispatch: # Enable manually starting a build
119

12-
permissions:
13-
checks: write
14-
pull-requests: write
15-
statuses: write
16-
1710
jobs:
1811
build:
19-
20-
runs-on: ${{ matrix.os }}
21-
2212
strategy:
2313
matrix:
2414
os: [ windows-latest, macos-latest, ubuntu-latest ]
2515
node-version: [ 18.x ]
16+
configuration: [ Release ]
2617
fail-fast: false # Don't cancel other jobs when one job fails
2718

19+
runs-on: ${{ matrix.os }}
20+
2821
steps:
2922
- uses: actions/checkout@v3
3023
with:
@@ -49,11 +42,12 @@ jobs:
4942
with:
5043
node-version: ${{ matrix.node-version }}
5144

52-
- name: Build
53-
run: dotnet build --configuration Release
45+
- name: Build ${{ matrix.configuration }}
46+
run: dotnet build --configuration ${{ matrix.configuration }}
5447

5548
- name: Build packages
56-
run: dotnet pack --configuration Release
49+
id: pack
50+
run: dotnet pack --configuration ${{ matrix.configuration }}
5751

5852
# Uncomment to enable an SSH session for debugging
5953
# - name: Setup tmate session
@@ -64,46 +58,50 @@ jobs:
6458
- name: Upload build artifacts
6559
uses: actions/upload-artifact@v3
6660
with:
67-
name: ${{ runner.os }}-packages
61+
name: ${{ matrix.os }}-${{ matrix.configuration }}-packages
6862
path: |
6963
out/pkg/*.nupkg
7064
out/pkg/*.tgz
7165
7266
- name: Test .NET 4.7.2
73-
if: matrix.os == 'windows-latest'
67+
if: matrix.os == 'windows-latest' && steps.pack.conclusion == 'success' && !cancelled()
7468
env:
7569
TRACE_NODE_API_HOST: 1
76-
run: dotnet test -f net472 --configuration Release --logger trx --results-directory "test-netfx47-node${{ matrix.node-version }}"
70+
run: >
71+
dotnet test -f net472
72+
--configuration ${{ matrix.configuration }}
73+
--logger trx
74+
--results-directory "out/test/netfx47-node${{ matrix.node-version }}-${{ matrix.configuration }}"
7775
7876
- name: Test .NET 6
77+
if: steps.pack.conclusion == 'success' && !cancelled()
7978
env:
8079
TRACE_NODE_API_HOST: 1
81-
run: dotnet test -f net6.0 --configuration Release --logger trx --results-directory "test-dotnet6-node${{ matrix.node-version }}"
80+
run: >
81+
dotnet test -f net6.0
82+
--configuration ${{ matrix.configuration }}
83+
--logger trx
84+
--results-directory "out/test/dotnet6-node${{ matrix.node-version }}-${{ matrix.configuration }}"
8285
8386
- name: Test .NET 7
87+
if: steps.pack.conclusion == 'success' && !cancelled()
8488
env:
8589
TRACE_NODE_API_HOST: 1
86-
run: dotnet test -f net7.0 --configuration Release --logger trx --results-directory "test-dotnet7-node${{ matrix.node-version }}"
90+
run: >
91+
dotnet test -f net7.0
92+
--configuration ${{ matrix.configuration }}
93+
--logger trx
94+
--results-directory "out/test/dotnet7-node${{ matrix.node-version }}-${{ matrix.configuration }}"
8795
8896
- name: Upload test logs
97+
if: always() # Update artifacts regardless if code succeeded, failed, or cancelled
8998
uses: actions/upload-artifact@v3
9099
with:
91-
name: test-logs-${{ runner.os }}-node${{ matrix.node-version }}
92-
path: out/obj/Release/**/*.log
93-
if: ${{ always() }}
94-
95-
- name: Publish test results
96-
uses: dorny/test-reporter@v1
97-
with:
98-
name: test (${{ runner.os }}, node${{ matrix.node-version }})
99-
path: test-dotnet*-node${{ matrix.node-version }}/*.trx
100-
reporter: dotnet-trx
101-
if: ${{ always() }} # Run this step even when there are test failures
100+
name: test-logs-${{ matrix.os }}-node${{ matrix.node-version }}-${{ matrix.configuration }}
101+
path: |
102+
out/obj/${{ matrix.configuration }}/**/*.log
103+
out/test/**/*.trx
102104
103105
- name: Check formatting
106+
if: ${{ !cancelled() }} # Run this step even when there are build failures but not when cancelled
104107
run: dotnet format --no-restore --severity info --verbosity detailed --verify-no-changes
105-
if: ${{ always() }} # Run this step even when there are build failures
106-
107-
# TODO: Publish packages
108-
# - name: Publish packages
109-
# run: dotnet nuget push out/pkg/*.nupkg

.github/workflows/test-report.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
2+
# https://github.com/dorny/test-reporter#recommended-setup-for-public-repositories
3+
4+
name: Test Report
5+
on:
6+
workflow_run:
7+
workflows: ['PR Verification'] # runs after 'PR Verification' workflow
8+
types:
9+
- completed
10+
11+
permissions:
12+
checks: write
13+
pull-requests: write
14+
statuses: write
15+
16+
jobs:
17+
report:
18+
strategy:
19+
matrix:
20+
os: [ windows-latest, macos-latest, ubuntu-latest ]
21+
node-version: [ 18.x ]
22+
configuration: [ Release ]
23+
fail-fast: false # Don't cancel other jobs when one job fails
24+
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Publish test results (${{ matrix.os }}, node${{ matrix.node-version }}, ${{ matrix.configuration }})
29+
uses: dorny/test-reporter@v1
30+
with:
31+
artifact: test-logs-${{ matrix.os }}-node${{ matrix.node-version }}-${{ matrix.configuration }}
32+
name: test results (${{ matrix.os }}, node${{ matrix.node-version }}, ${{ matrix.configuration }})
33+
path: test/**/*.trx
34+
reporter: dotnet-trx

0 commit comments

Comments
 (0)