diff --git a/.github/workflows/cloud-human-confidence.yml b/.github/workflows/cloud-human-confidence.yml index f13bffa2..a525beb1 100644 --- a/.github/workflows/cloud-human-confidence.yml +++ b/.github/workflows/cloud-human-confidence.yml @@ -28,10 +28,18 @@ on: - cron: '50 6 * * *' pull_request: branches: [main, rc] + # The example and its tests, the files they import, and the files the + # install step uses. paths: - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/humanconfidence_web/**' + - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/example_utils.py' - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/conftest.py' + - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/live_cloud.py' - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_humanconfidence_web.py' + - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/pyproject.toml' + - 'ci/write-package-versions.ps1' + - 'ci/packages.ps1' + - 'ci/packages.json' - '.github/workflows/cloud-human-confidence.yml' permissions: @@ -110,6 +118,11 @@ jobs: Remove-Item $report -ErrorAction SilentlyContinue python -m pytest -m staging -p no:cacheprovider -v -rs ` "--junit-xml=$report" + # pytest exits 5 when it selects no test. + if ($LASTEXITCODE -eq 5) { + Write-Host '::error::No staging test ran.' + exit 1 + } if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } if (-not (Test-Path $report)) { Write-Host '::error::The staging tests did not run.' @@ -117,10 +130,6 @@ jobs: } $suite = ([xml](Get-Content -Raw $report)).SelectSingleNode( '//testsuite') - if ([int]$suite.tests -eq 0) { - Write-Host '::error::No staging test ran.' - exit 1 - } if ([int]$suite.skipped -gt 0) { foreach ($skipped in $suite.SelectNodes('testcase[skipped]')) { Write-Host ("::error::$($skipped.name) skipped, so it proved " + diff --git a/ci/key-names.Tests.ps1 b/ci/key-names.Tests.ps1 index 2146b363..8b5b8607 100644 --- a/ci/key-names.Tests.ps1 +++ b/ci/key-names.Tests.ps1 @@ -105,9 +105,10 @@ foreach ($asset in $Assets) { Set-Content -LiteralPath "assets/$asset" '' } # Runs the Cloud Human Confidence workflow's test step in its own process # and folder, with the names given set and no others, and python replaced - # by a function that writes $Report as the junit report. Gives the exit - # code and the output. - function Invoke-StagingStep([hashtable]$Names, [string]$Report) { + # by a function that writes $Report as the junit report and exits with + # $PytestExitCode. Gives the step's exit code and the output. + function Invoke-StagingStep([hashtable]$Names, [string]$Report, + [int]$PytestExitCode = 0) { $folder = Join-Path $TestDrive ([Guid]::NewGuid().ToString()) $null = New-Item -ItemType Directory $folder $stepFile = Join-Path $folder 'step.ps1' @@ -116,7 +117,7 @@ foreach ($asset in $Assets) { Set-Content -LiteralPath "assets/$asset" '' } ' Write-Output "pytest ran"' ' $path = "$($args | Where-Object { "$_" -like "--junit-xml=*" })" -replace "^--junit-xml=", ""' " if (`$path) { Set-Content `$path '$Report' }" - ' $global:LASTEXITCODE = 0' + " `$global:LASTEXITCODE = $PytestExitCode" '}' ) @($python + @(Get-StepScript 'cloud-human-confidence.yml' 'Human Confidence tests against the staging cloud')) | @@ -527,19 +528,55 @@ Describe 'Keys under their _51DEGREES_ names' { $result.Output | Should -Match 'test_0 skipped' } + # pytest exits 5 when it selects no test, and still writes the report. It 'fail the Cloud Human Confidence step when no staging test ran' { - $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 0 0) + $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 0 0) 5 $result.ExitCode | Should -Not -Be 0 + $result.Output | Should -Match 'pytest ran' $result.Output | Should -Match 'No staging test ran' } + It 'fail the Cloud Human Confidence step with pytest''s exit code when a staging test failed' { + $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 2 0) 1 + + $result.ExitCode | Should -Be 1 + $result.Output | Should -Not -Match 'No staging test ran' + } + It 'pass the Cloud Human Confidence step when every staging test ran' { $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 2 0) $result.ExitCode | Should -Be 0 $result.Output | Should -Match 'pytest ran' } + + # The workflow runs for a pull request that changes one of its + # pull_request paths, so each path it names is a file in this + # repository. + It 'run for a pull request on files that exist, in the Cloud Human Confidence workflow' { + $lines = @(Get-Content (Join-Path $script:Root '.github/workflows/cloud-human-confidence.yml')) + $trigger = ($lines | Select-String -Pattern '^(\s*)pull_request:\s*$' | + Select-Object -First 1) + $trigger | Should -Not -BeNullOrEmpty + $indent = $trigger.Matches[0].Groups[1].Value.Length + $paths = @() + $inPaths = $false + foreach ($line in $lines | Select-Object -Skip $trigger.LineNumber) { + if (-not $line.Trim() -or $line.Trim().StartsWith('#')) { continue } + if ($line -notmatch "^\s{$($indent + 1),}") { break } + if ($line -match '^\s*paths:\s*$') { $inPaths = $true; continue } + if ($inPaths -and $line -match '^\s*-\s*[''"]?(?[^''"]+?)[''"]?\s*$') { + $paths += $Matches['path'] + } elseif ($inPaths) { + break + } + } + $paths | Should -Not -BeNullOrEmpty + $paths | Where-Object { $_ -notmatch '[*?\[!]' } | + Where-Object { -not (Test-Path -LiteralPath (Join-Path $script:Root $_) -PathType Leaf) } | + Should -BeNullOrEmpty + } } Describe 'The live cloud tests' {