diff --git a/.github/actions/build-dotnet/Build-DotNetSolutionOrProject.ps1 b/.github/actions/build-dotnet/Build-DotNetSolutionOrProject.ps1 index e66b6f736..8c9c00625 100644 --- a/.github/actions/build-dotnet/Build-DotNetSolutionOrProject.ps1 +++ b/.github/actions/build-dotnet/Build-DotNetSolutionOrProject.ps1 @@ -8,7 +8,7 @@ param ( function ConvertTo-Array([string] $rawInput) { - $rawInput.Replace("`r", "").Split("`n") | % { $_.Trim() } | ? { $_ } + $rawInput.Replace("`r", "").Split("`n") | ForEach-Object { $_.Trim() } | Where-Object { $_ } } Write-Output ".NET version number: $Version" @@ -33,7 +33,7 @@ $buildSwitches = ConvertTo-Array @" $Switches "@ -[array] $expectedErrorCodes = ConvertTo-Array $ExpectedCodeAnalysisErrors | % { $_.Split(':')[0] } | Sort-Object +[array] $expectedErrorCodes = ConvertTo-Array $ExpectedCodeAnalysisErrors | ForEach-Object { $_.Split(':')[0] } | Sort-Object $noErrors = $expectedErrorCodes.Count -eq 0 if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj) @@ -59,7 +59,7 @@ $errorLines = New-Object "System.Collections.Generic.List[string]" $errorCodes = New-Object "System.Collections.Generic.List[string]" $errorFormat = '^(.*)\((\d+),(\d+)\): error (.*)' -dotnet build $SolutionOrProject @buildSwitches 2>&1 | % { +dotnet build $SolutionOrProject @buildSwitches 2>&1 | ForEach-Object { if ($_ -notmatch $errorFormat) { return $_ } ($null, $file, $line, $column, $message) = [regex]::Match($_, $errorFormat, 'Compiled').Groups.Value diff --git a/.github/actions/build-dotnet/Write-CacheConfiguration.ps1 b/.github/actions/build-dotnet/Write-CacheConfiguration.ps1 index f49361e42..888671420 100644 --- a/.github/actions/build-dotnet/Write-CacheConfiguration.ps1 +++ b/.github/actions/build-dotnet/Write-CacheConfiguration.ps1 @@ -9,12 +9,12 @@ if ($IsNuget) { $paths += ,'~/.nuget/packages' } if ($IsNpm) { (Invoke-Maybe { pnpm store path }), (npm config get cache) | - ? { -not [string]::IsNullOrEmpty($_) } | - % { $paths += $_ } + Where-Object { -not [string]::IsNullOrEmpty($_) } | + ForEach-Object { $paths += $_ } } # Ensure the paths exist. -$paths | % { New-Item -ItemType Directory -Force $_ } | Out-Null +$paths | ForEach-Object { New-Item -ItemType Directory -Force $_ } | Out-Null # Multiple paths must be separated by "\n", but we can't include newline in the workflow command so we have to misuse # the format function like this. diff --git a/.github/actions/cancel-workflow/action.yml b/.github/actions/cancel-workflow/action.yml index 880634a2a..e85419d97 100644 --- a/.github/actions/cancel-workflow/action.yml +++ b/.github/actions/cancel-workflow/action.yml @@ -1,7 +1,13 @@ name: Cancel Workflow description: > Cancels the current workflow run, i.e. all jobs. Useful if you want to cancel the rest of the workflow when one job - fails. + fails. Note that this will cause the workflow to appear cancelled, not failed. + +# Cancelling the workflow in a post-script (like this: +# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runspost; can also be done with +# this action: https://github.com/webiny/action-post-run, see Git history of this file) wouldn't help the status, it +# would still be cancelled. It actually indeed is, but it would be nicer to set it to failed, but there seems to be no +# way to do this. runs: using: "composite" @@ -11,6 +17,7 @@ runs: if: github.event.pull_request == '' || github.event.pull_request.head.repo.fork == false shell: pwsh run: | + Write-Output "::error::Canceling workflow due to one of the jobs failing." $url = "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel" $headers = @{"Authorization" = "Bearer ${{ env.GITHUB_TOKEN }}"; "Accept" = "application/vnd.github+json"} Invoke-WebRequest $url -Headers $headers -Method Post diff --git a/.github/actions/test-dotnet/Invoke-SolutionTests.ps1 b/.github/actions/test-dotnet/Invoke-SolutionTests.ps1 index f4cc0a983..006415e1c 100644 --- a/.github/actions/test-dotnet/Invoke-SolutionTests.ps1 +++ b/.github/actions/test-dotnet/Invoke-SolutionTests.ps1 @@ -31,39 +31,47 @@ $tests = dotnet sln list | Select-String "\.Tests\." | Select-String -NotMatch "Lombiq.Tests.UI.csproj" | Select-String -NotMatch "Lombiq.Tests.csproj" | - ? { + Where-Object { $result = dotnet test --no-restore --list-tests --verbosity $Verbosity $_ 2>&1 | Out-String -Width 9999 -not [string]::IsNullOrEmpty($result) -and $result.Contains("The following Tests are available") } +Write-Output "Starting to execute tests from $($tests.Length) projects." + foreach ($test in $tests) { + # This could benefit from grouping, above the level of the potential groups created by the tests (the Lombiq UI + # Testing Toolbox adds per-test groups too). However, there's no nested grouping, see + # https://github.com/actions/runner/issues/1477. See the # c341ef145d2a0898c5900f64604b67b21d2ea5db commit for a + # nested grouping implementation. + + Write-Output "Starting to execute tests from the $test project." + $dotnetTestSwitches = @( '--configuration', 'Release' '--no-restore', '--no-build', '--nologo', '--logger', 'trx;LogFileName=test-results.trx' + # This is for xUnit ITestOutputHelper, see https://xunit.net/docs/capturing-output. + '--logger', 'console;verbosity=detailed' '--verbosity', $Verbosity $Filter ? '--filter' : '' $Filter ? $Filter : '' $test ) - dotnet test @dotnetTestSwitches 2>&1 >test.out + # Filtering is necessary for annoying messages coming from UI testing but only under Ubuntu. There are no actual + # errors. + dotnet test @dotnetTestSwitches 2>&1 | + Where-Object { $_ -notlike '*Connection refused [[]::ffff:127.0.0.1[]]*' -and $_ -notlike '*ChromeDriver was started successfully*' } if ($?) { - Write-Output "Test Successful: $test" + Write-Output "Test successful: $test" continue } - $needsGrouping = (Select-String "::group::" test.out).Length -eq 0 - - if ($needsGrouping) { Write-Output "::group::Test Failed: $test" } - - bash -c "cat test.out | grep -v 'Connection refused \[::ffff:127.0.0.1\]' | grep -v 'ChromeDriver was started successfully'" - - if ($needsGrouping) { Write-Output "::endgroup::" } + Write-Output "Test failed: $test" exit 100 } diff --git a/.github/actions/test-dotnet/Merge-FailureDumps.ps1 b/.github/actions/test-dotnet/Merge-FailureDumps.ps1 index 92618aab6..b6d3acdea 100644 --- a/.github/actions/test-dotnet/Merge-FailureDumps.ps1 +++ b/.github/actions/test-dotnet/Merge-FailureDumps.ps1 @@ -6,6 +6,6 @@ $testDirectory = "$Directory/test" $rootDirectory = (Test-Path -Path $testDirectory) ? $testDirectory : $Directory Get-ChildItem $rootDirectory -Recurse | - ? { $_.Name -eq 'FailureDumps' } | - % { $_.GetDirectories() } | - % { Move-Item $_.FullName "$Directory/FailureDumps/${_.Name}" } + Where-Object { $_.Name -eq 'FailureDumps' } | + ForEach-Object { $_.GetDirectories() } | + ForEach-Object { Move-Item $_.FullName "$Directory/FailureDumps/${_.Name}" } diff --git a/.github/actions/test-dotnet/action.yml b/.github/actions/test-dotnet/action.yml index c2010060c..00c645f02 100644 --- a/.github/actions/test-dotnet/action.yml +++ b/.github/actions/test-dotnet/action.yml @@ -73,9 +73,7 @@ runs: if: success() || failure() with: name: ui-test-failure-dump-${{ steps.setup.outputs.friendly-build-directory-name }}-${{ steps.setup.outputs.runner-suffix }} - path: | - ${{ inputs.build-directory }}/FailureDumps/ - test.out + path: ${{ inputs.build-directory }}/FailureDumps/ if-no-files-found: ignore - name: Test Report diff --git a/.github/actions/verify-submodule-pull-request/Check-Parent.ps1 b/.github/actions/verify-submodule-pull-request/Check-Parent.ps1 index 9a301938b..97874d100 100644 --- a/.github/actions/verify-submodule-pull-request/Check-Parent.ps1 +++ b/.github/actions/verify-submodule-pull-request/Check-Parent.ps1 @@ -4,7 +4,7 @@ param( ) $url = "https://api.github.com/repos/$Repository/pulls?state=open&per_page=100" -$titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } +$titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | ForEach-Object { $_.title } $issueCode = $Title -replace '^\s*(\w+-\d+)\s*:.*$', '$1' $lookFor = "${issueCode}:"