Skip to content

Commit b2396d8

Browse files
Copilotxperiandri
andcommitted
ci: publish test results to pull request discussions
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/ae314b8b-9c8a-4f87-a8b0-b77c4bfa2cef Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent 022d633 commit b2396d8

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish Test Results
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build and Test"]
6+
types:
7+
- completed
8+
9+
permissions: {}
10+
11+
jobs:
12+
test-results:
13+
if: github.event.workflow_run.conclusion != 'skipped' && github.event.workflow_run.event == 'pull_request'
14+
name: Test Results
15+
runs-on: ubuntu-latest
16+
17+
permissions:
18+
actions: read
19+
checks: write
20+
pull-requests: write
21+
22+
steps:
23+
- name: Download event file
24+
uses: dawidd6/action-download-artifact@v4
25+
with:
26+
run_id: ${{ github.event.workflow_run.id }}
27+
path: artifacts
28+
name: EventFile
29+
30+
- name: Download test results
31+
uses: dawidd6/action-download-artifact@v4
32+
with:
33+
run_id: ${{ github.event.workflow_run.id }}
34+
path: test-results
35+
pattern: test-results-*
36+
37+
- name: Publish test results
38+
uses: EnricoMi/publish-unit-test-result-action@v2
39+
with:
40+
commit: ${{ github.event.workflow_run.head_sha }}
41+
event_file: artifacts/event.json
42+
event_name: ${{ github.event.workflow_run.event }}
43+
files: "test-results/**/*.trx"

.github/workflows/pull-request.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ env:
1515
DOTNET_NOLOGO: true
1616

1717
jobs:
18+
event_file:
19+
if: github.event_name == 'pull_request'
20+
name: Publish event file
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Upload event file
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: EventFile
27+
path: ${{ github.event_path }}
28+
1829
build:
1930

2031
strategy:
@@ -50,3 +61,10 @@ jobs:
5061

5162
- name: Build and run integration tests
5263
run: dotnet run --project build/Build.fsproj --launch-profile BuildAndTest
64+
65+
- name: Upload test results
66+
if: always()
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: test-results-${{ matrix.os }}
70+
path: test-results

build/Program.fs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ let startGraphQLServer (project : string) port (streamRef : DataRef<Stream>) =
9898

9999
System.Threading.Thread.Sleep (2000)
100100

101-
let runTests (project : string) (args : string) =
101+
let runTests (project : string) =
102+
let projectName = Path.GetFileNameWithoutExtension project
103+
let resultsFileName = $"{projectName}.trx"
104+
102105
DotNet.test
103106
(fun options ->
104107
{
105108
options with
106109
NoBuild = true
110+
Logger = Some $"trx;LogFileName={resultsFileName}"
111+
ResultsDirectory = Some "test-results"
107112
Framework = Some DotNetMoniker
108113
Configuration = configuration
109114
MSBuildParams = {
@@ -184,7 +189,7 @@ let unitTestsProjectPath =
184189

185190
let [<Literal>] RunUnitTestsTarget = "RunUnitTests"
186191
Target.create RunUnitTestsTarget <| fun _ ->
187-
runTests unitTestsProjectPath ""
192+
runTests unitTestsProjectPath
188193

189194
let prepareDocGen () =
190195
Shell.rm "docs/release-notes.md"

0 commit comments

Comments
 (0)