Skip to content

Commit c37da58

Browse files
xperiandriclaude
andcommitted
fixup! Publish CI test results into PR discussions, harden artifact download, and add PR preview publishing (#570)
Build the integration tests before running them, fail on empty runs `UpdateIntrospectionFile` switched to `dotnet test --no-build`, but nothing restores or builds FSharp.Data.GraphQL.Integration.slnx: the restore target only covers `src/**` and the build target only builds FSharp.Data.GraphQL.slnx. On an unrestored project the test SDK props are not imported, so `dotnet test` runs nothing and exits with 0. The step has been a silent no-op on CI, which let a non-compiling integration test project stay green. - Add a `BuildIntegrationTests` target that builds the integration solution after `Build` (it needs the client provider assembly). - Make `runTests` fail when the run leaves no results file, deleting a stale one first so an earlier run cannot mask it. - Reuse `runTests` for `UpdateIntrospectionFile` instead of repeating the `dotnet test` options, with its own results file name so it does not overwrite other runs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 3ea20e2 commit c37da58

1 file changed

Lines changed: 33 additions & 37 deletions

File tree

‎build/Program.fs‎

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ Target.create RestoreTarget <| fun _ ->
7070
|> Seq.iter (fun pattern -> DotNet.restore DotNetCli.setRestoreOptions pattern)
7171

7272

73-
let [<Literal>] BuildTarget = "Build"
74-
Target.create BuildTarget <| fun _ ->
75-
"FSharp.Data.GraphQL.slnx"
73+
let buildSolution (solution : string) =
74+
solution
7675
|> DotNet.build (fun options -> {
7776
options with
7877
Common = options.Common.WithRedirectOutput true |> DotNetCli.setVersion
@@ -88,6 +87,14 @@ Target.create BuildTarget <| fun _ ->
8887
}
8988
})
9089

90+
let [<Literal>] BuildTarget = "Build"
91+
Target.create BuildTarget <| fun _ -> buildSolution "FSharp.Data.GraphQL.slnx"
92+
93+
// The integration tests are not part of FSharp.Data.GraphQL.slnx and are neither restored nor built by BuildTarget.
94+
// They reference the client provider assembly produced by BuildTarget, so this must run after it.
95+
let [<Literal>] BuildIntegrationTestsTarget = "BuildIntegrationTests"
96+
Target.create BuildIntegrationTestsTarget <| fun _ -> buildSolution "FSharp.Data.GraphQL.Integration.slnx"
97+
9198
let startGraphQLServer (project : string) port (streamRef : DataRef<Stream>) =
9299
CreateProcess.fromRawCommandLine "dotnet" $"run --project {project} --no-build --no-launch-profile --configuration {configurationString} --urls=http://localhost:%i{port}/"
93100
|> CreateProcess.withStandardInput (CreatePipe streamRef)
@@ -98,19 +105,28 @@ let startGraphQLServer (project : string) port (streamRef : DataRef<Stream>) =
98105

99106
System.Threading.Thread.Sleep (2000)
100107

101-
let runTests (project : string) =
102-
let projectName = Path.GetFileNameWithoutExtension project
103-
let resultsFileName = $"{projectName}.trx"
108+
let [<Literal>] TestResultsDirectory = "test-results"
109+
110+
let runTests (project : string) (resultsFileName : string) (filter : string voption) =
111+
let resultsFilePath = TestResultsDirectory </> resultsFileName
112+
// A stale results file from a previous run must not hide a run that produced none
113+
// (checked first, because File.Delete throws when the results directory does not exist yet)
114+
if File.Exists resultsFilePath then
115+
File.Delete resultsFilePath
104116

105117
DotNet.test
106118
(fun options ->
107119
{
108120
options with
109121
NoBuild = true
110122
Logger = Some $"trx;LogFileName={resultsFileName}"
111-
ResultsDirectory = Some "test-results"
123+
ResultsDirectory = Some TestResultsDirectory
112124
Framework = Some DotNetMoniker
113125
Configuration = configuration
126+
Common = {
127+
options.Common with
128+
CustomParams = filter |> ValueOption.map (fun filter -> $"--filter {filter}") |> ValueOption.toOption
129+
}
114130
MSBuildParams = {
115131
options.MSBuildParams with
116132
DisableInternalBinLog = true
@@ -126,6 +142,11 @@ let runTests (project : string) =
126142
|> _.WithCommon(DotNetCli.setVersion))
127143
project
128144

145+
// `dotnet test --no-build` on a project that was never restored does not import the test SDK,
146+
// so it runs nothing and still exits with 0. The missing results file is the only trace of that.
147+
if not (File.Exists resultsFilePath) then
148+
failwith $"'dotnet test {project}' produced no test results at '{resultsFilePath}'. Was the project restored and built?"
149+
129150
let integrationTestServerProjectPath =
130151
"tests"
131152
</> "FSharp.Data.GraphQL.IntegrationTests.Server"
@@ -169,36 +190,10 @@ let integrationTestsProjectPath =
169190

170191
let [<Literal>] UpdateIntrospectionFileTarget = "UpdateIntrospectionFile"
171192
Target.create UpdateIntrospectionFileTarget <| fun _ ->
172-
let projectName = Path.GetFileNameWithoutExtension integrationTestsProjectPath
173-
let resultsFileName = $"{projectName}.trx"
174-
175-
DotNet.test
176-
(fun options ->
177-
{
178-
options with
179-
NoBuild = true
180-
Logger = Some $"trx;LogFileName={resultsFileName}"
181-
ResultsDirectory = Some "test-results"
182-
Framework = Some DotNetMoniker
183-
Configuration = configuration
184-
Common = {
185-
options.Common with
186-
CustomParams = Some "--filter FullyQualifiedName~IntrospectionUpdateTests"
187-
}
188-
MSBuildParams = {
189-
options.MSBuildParams with
190-
DisableInternalBinLog = true
191-
Verbosity = Some Normal
192-
Properties = [
193-
if embedAll then
194-
("DebugType", "embedded")
195-
("EmbedAllSources", "true")
196-
]
197-
}
198-
}
199-
|> _.WithRedirectOutput(true)
200-
|> _.WithCommon(DotNetCli.setVersion))
193+
runTests
201194
integrationTestsProjectPath
195+
"FSharp.Data.GraphQL.IntegrationTests.IntrospectionUpdate.trx"
196+
(ValueSome "FullyQualifiedName~IntrospectionUpdateTests")
202197

203198
let unitTestsProjectPath =
204199
"tests"
@@ -207,7 +202,7 @@ let unitTestsProjectPath =
207202

208203
let [<Literal>] RunUnitTestsTarget = "RunUnitTests"
209204
Target.create RunUnitTestsTarget <| fun _ ->
210-
runTests unitTestsProjectPath
205+
runTests unitTestsProjectPath "FSharp.Data.GraphQL.Tests.trx" ValueNone
211206

212207
let prepareDocGen () =
213208
Shell.rm "docs/release-notes.md"
@@ -384,6 +379,7 @@ Target.create "PackAndPush" ignore
384379
==> RestoreTarget
385380
==> BuildTarget
386381
==> RunUnitTestsTarget
382+
==> BuildIntegrationTestsTarget
387383
==> UpdateIntrospectionFileTarget
388384
==> "All"
389385
=?> (GenerateDocsTarget, Environment.environVar "GITHUB_ACTIONS" = "True")

0 commit comments

Comments
 (0)