Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Publish Test Results

on:
workflow_run:
workflows: ["Build and Test"]
types:
- completed

permissions: {}

jobs:
test-results:
if: github.event.workflow_run.conclusion != 'skipped' && github.event.workflow_run.event == 'pull_request'
name: Test Results
runs-on: ubuntu-latest

permissions:
actions: read
checks: write
pull-requests: write

steps:
- name: Download event file
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
path: artifacts
name: EventFile

- name: Download test results
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
path: test-results
name: ^test-results-.*
name_is_regexp: true
if_no_artifact_found: warn

- name: Resolve event file path
id: event_file
shell: pwsh
run: |
$eventFilePath =
Get-ChildItem -Path artifacts -Filter event.json -Recurse |
Select-Object -First 1 -ExpandProperty FullName

if ($null -eq $eventFilePath) {
throw "event.json file was not found in downloaded artifacts"
}

"path=$eventFilePath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append

- name: Publish test results
if: ${{ hashFiles('test-results/**/*.trx') != '' }}
uses: EnricoMi/publish-unit-test-result-action@v2
with:
commit: ${{ github.event.workflow_run.head_sha }}
comment_mode: always
event_file: ${{ steps.event_file.outputs.path }}
event_name: ${{ github.event.workflow_run.event }}
files: "test-results/**/*.trx"
Comment on lines +55 to +61

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot what does it mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means the workflow would publish only a check unless PR comment publishing is enabled/configured. I updated it in commit 1cf3cef by setting comment_mode: always, so PR discussion comments are explicitly enabled. No UI changes were made, so there is no screenshot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means PR-discussion comments were not explicitly configured in the publish step. Commit 1cf3cef now sets comment_mode: always, making PR commenting explicit alongside check publication. No UI changes were made, so there is no screenshot.

24 changes: 24 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,25 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true

permissions: {}

jobs:
event_file:
if: github.event_name == 'pull_request'
name: Publish event file
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Upload event file
uses: actions/upload-artifact@v4
with:
name: EventFile
path: ${{ github.event_path }}

build:
permissions:
contents: read

strategy:
fail-fast: false
Expand Down Expand Up @@ -50,3 +67,10 @@ jobs:

- name: Build and run integration tests
run: dotnet run --project build/Build.fsproj --launch-profile BuildAndTest

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}
path: test-results
Comment thread
xperiandri marked this conversation as resolved.
49 changes: 36 additions & 13 deletions build/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ let startGraphQLServer (project : string) port (streamRef : DataRef<Stream>) =

System.Threading.Thread.Sleep (2000)

let runTests (project : string) (args : string) =
let runTests (project : string) =
let projectName = Path.GetFileNameWithoutExtension project
let resultsFileName = $"{projectName}.trx"

DotNet.test
(fun options ->
{
options with
NoBuild = true
Logger = Some $"trx;LogFileName={resultsFileName}"
ResultsDirectory = Some "test-results"
Framework = Some DotNetMoniker
Configuration = configuration
MSBuildParams = {
Expand Down Expand Up @@ -164,18 +169,36 @@ let integrationTestsProjectPath =

let [<Literal>] UpdateIntrospectionFileTarget = "UpdateIntrospectionFile"
Target.create UpdateIntrospectionFileTarget <| fun _ ->
integrationTestsProjectPath
|> DotNet.test (fun options -> {
options with
Framework = Some DotNetMoniker
Configuration = configuration
Common = { DotNetCli.setVersion options.Common with CustomParams = Some "--filter FullyQualifiedName~IntrospectionUpdateTests" }
MSBuildParams = {
options.MSBuildParams with
DisableInternalBinLog = true
Verbosity = Some Normal
let projectName = Path.GetFileNameWithoutExtension integrationTestsProjectPath
let resultsFileName = $"{projectName}.trx"

DotNet.test
(fun options ->
{
options with
NoBuild = true
Logger = Some $"trx;LogFileName={resultsFileName}"
ResultsDirectory = Some "test-results"
Framework = Some DotNetMoniker
Configuration = configuration
Common = {
options.Common with
CustomParams = Some "--filter FullyQualifiedName~IntrospectionUpdateTests"
}
MSBuildParams = {
options.MSBuildParams with
DisableInternalBinLog = true
Verbosity = Some Normal
Properties = [
if embedAll then
("DebugType", "embedded")
("EmbedAllSources", "true")
]
}
}
})
|> _.WithRedirectOutput(true)
|> _.WithCommon(DotNetCli.setVersion))
integrationTestsProjectPath

let unitTestsProjectPath =
"tests"
Expand All @@ -184,7 +207,7 @@ let unitTestsProjectPath =

let [<Literal>] RunUnitTestsTarget = "RunUnitTests"
Target.create RunUnitTestsTarget <| fun _ ->
runTests unitTestsProjectPath ""
runTests unitTestsProjectPath
Comment thread
xperiandri marked this conversation as resolved.

let prepareDocGen () =
Shell.rm "docs/release-notes.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,66 @@ let normalizeJsonDocument options (document : JsonDocument) =
JsonDocument.Parse buffer

let parseAndNormalizeJsonAsync ct options stream = task {
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
return normalizeJsonDocument options document
}
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
return normalizeJsonDocument options document
}

let areSchemasEqual (document1 : JsonDocument) (document2 : JsonDocument) =
let schema1 = document1.RootElement.GetProperty("data").GetProperty ("__schema")
let schema2 = document2.RootElement.GetProperty("data").GetProperty ("__schema")
schema1.GetRawText () = schema2.GetRawText ()

let readDestinationDocumentAsync ct (stream : FileStream) = task {
try
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
return ValueSome document
with :? JsonException ->
return ValueNone
}
try
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
return ValueSome document
with :? JsonException ->
return ValueNone
}

let updateIntrospectionFileAsync ct sourceStream = task {
use destinationStream =
new FileStream (introspectionFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)
use destinationStream =
new FileStream (introspectionFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)

let options = JsonWriterOptions (Indented = true)
let! sourceDocument = parseAndNormalizeJsonAsync ct options sourceStream
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
let! destinationDocument = readDestinationDocumentAsync ct destinationStream
let! sourceDocument = parseAndNormalizeJsonAsync ct options sourceStream
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
let! destinationDocument = readDestinationDocumentAsync ct destinationStream

let shouldUpdate =
match destinationDocument with
| ValueNone -> true
| ValueSome document -> not (areSchemasEqual document sourceDocument)
let shouldUpdate =
match destinationDocument with
| ValueNone -> true
| ValueSome document -> not (areSchemasEqual document sourceDocument)

if shouldUpdate then
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
destinationStream.SetLength 0
use writer = new Utf8JsonWriter (destinationStream, options)
sourceDocument.WriteTo writer
writer.Flush ()
if shouldUpdate then
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
destinationStream.SetLength 0
use writer = new Utf8JsonWriter (destinationStream, options)
sourceDocument.WriteTo writer
writer.Flush ()

return shouldUpdate
}
return shouldUpdate
}

[<Fact>]
let ``Get GraphQL introspection response returns schema`` () = task {
use httpClient = TestHosts.createIntegrationHttpClient ()
use httpClient = TestHosts.createIntegrationHttpClient ()
let! response = httpClient.GetFromJsonAsync<JsonElement> ("/", CancellationToken.None)
let schema = response.GetProperty("data").GetProperty ("__schema")
Assert.NotEqual (Unchecked.defaultof<JsonElement>, schema)
let hasErrors, _ = response.TryGetProperty "errors"
Assert.False hasErrors
}
let hasErrors, _ = response.TryGetProperty "errors"
Assert.False hasErrors
}

[<Fact>]
let ``Update integration introspection file when schema changes`` () = task {
use httpClient = TestHosts.createIntegrationHttpClient ()
use httpClient = TestHosts.createIntegrationHttpClient ()
let! sourceStream = httpClient.GetStreamAsync ("/")
let! wasUpdated = updateIntrospectionFileAsync CancellationToken.None sourceStream
let! wasUpdated = updateIntrospectionFileAsync CancellationToken.None sourceStream
Assert.True (File.Exists introspectionFilePath)
if wasUpdated then
if wasUpdated then
let! sourceStreamSecondRun = httpClient.GetStreamAsync ("/")
use sourceStreamForVerification = sourceStreamSecondRun
let! wasUpdatedSecondRun = updateIntrospectionFileAsync CancellationToken.None sourceStreamForVerification
Assert.False wasUpdatedSecondRun
}
use sourceStreamForVerification = sourceStreamSecondRun
let! wasUpdatedSecondRun = updateIntrospectionFileAsync CancellationToken.None sourceStreamForVerification
Assert.False wasUpdatedSecondRun
}
Loading
Loading