diff --git a/.github/workflows/.common.yml b/.github/workflows/.common.yml index 5d0e6123..8ce53048 100644 --- a/.github/workflows/.common.yml +++ b/.github/workflows/.common.yml @@ -6,13 +6,16 @@ on: type: string default: ${{ github.workflow }} test: - description: Test + description: Test update type: boolean force: description: Force update type: boolean - test_scripts: - description: JSON serialized list of Powershell scripts to test a package + test_cases: + description: | + List of test cases + - {title} + {script} type: string jobs: @@ -117,22 +120,22 @@ jobs: name: Packages - name: Tests before install - if: inputs.test_scripts + if: inputs.test_cases run: | - $results = $env:scripts -split "`r?`n" | Where-Object { $_ } | ForEach-Object { - if ($env:debug) { - $VerbosePreference = $DebugPreference = $InformationPreference = "Continue" - } - $script = $_ + if ($env:debug) { + $VerbosePreference = $DebugPreference = $InformationPreference = "Continue" + } + $test_cases = $env:test_cases -split "^-\s+(.+)\s*$", 0, "Multiline" + for ($i = 1; $i -lt $test_cases.length - 1; $i += 2) { try { $out = @() - Invoke-Expression $script *>&1 | ForEach-Object { $out += $_ } + Invoke-Expression $test_cases[$i + 1] *>&1 | ForEach-Object { $out += $_ } if ($LASTEXITCODE) { throw "Test failed." } - Write-Host "❌ $script" + "❌ {0}" -f $test_cases[$i] | Write-Host $out | Out-Host return $true } catch { - Write-Host "✅ $script" + "✅ {0}" -f $test_cases[$i] | Write-Host } } if ($results -contains $true) { @@ -140,7 +143,7 @@ jobs: } env: debug: ${{ runner.debug }} - scripts: ${{ inputs.test_scripts }} + test_cases: ${{ inputs.test_cases }} - name: Install package run: | @@ -166,20 +169,20 @@ jobs: path: ${{ steps.information.outputs.path }} - name: Tests after install - if: inputs.test_scripts + if: inputs.test_cases run: | - $results = $env:scripts -split "`r?`n" | Where-Object { $_ } | ForEach-Object { - if ($env:debug) { - $VerbosePreference = $DebugPreference = $InformationPreference = "Continue" - } - $script = $_ + if ($env:debug) { + $VerbosePreference = $DebugPreference = $InformationPreference = "Continue" + } + $test_cases = $env:test_cases -split "^-\s+(.+)\s*$", 0, "Multiline" + for ($i = 1; $i -lt $test_cases.length - 1; $i += 2) { try { $out = @() - Invoke-Expression $script *>&1 | ForEach-Object { $out += $_ } + Invoke-Expression $test_cases[$i + 1] *>&1 | ForEach-Object { $out += $_ } if ($LASTEXITCODE) { throw "Test failed." } - Write-Host "✅ $script" + "✅ {0}" -f $test_cases[$i] | Write-Host } catch { - Write-Host "❌ $script" + "❌ {0}" -f $test_cases[$i] | Write-Host $out, $_ | Out-Host return $true } @@ -189,7 +192,7 @@ jobs: } env: debug: ${{ runner.debug }} - scripts: ${{ inputs.test_scripts }} + scripts: ${{ inputs.test_cases }} - name: Uninstall package # AirServer requires Wireless-Networking while uninstalling, feature not installed on GitHub agents @@ -203,22 +206,22 @@ jobs: timeout-minutes: 10 - name: Tests after uninstall - if: inputs.test_scripts + if: inputs.test_cases run: | - $results = $env:scripts -split "`r?`n" | Where-Object { $_ } | ForEach-Object { - if ($env:debug) { - $VerbosePreference = $DebugPreference = $InformationPreference = "Continue" - } - $script = $_ + if ($env:debug) { + $VerbosePreference = $DebugPreference = $InformationPreference = "Continue" + } + $test_cases = $env:test_cases -split "^-\s+(.+)\s*$", 0, "Multiline" + for ($i = 1; $i -lt $test_cases.length - 1; $i += 2) { try { $out = @() - Invoke-Expression $script *>&1 | ForEach-Object { $out += $_ } + Invoke-Expression $test_cases[$i + 1] *>&1 | ForEach-Object { $out += $_ } if ($LASTEXITCODE) { throw "Test failed." } - Write-Host "❌ $script" + "❌ {0}" -f $test_cases[$i] | Write-Host $out | Out-Host return $true } catch { - Write-Host "✅ $script" + "✅ {0}" -f $test_cases[$i] | Write-Host } } if ($results -contains $true) { @@ -226,7 +229,7 @@ jobs: } env: debug: ${{ runner.debug }} - scripts: ${{ inputs.test_scripts }} + scripts: ${{ inputs.test_cases }} - name: Take failure screenshot if: failure() diff --git a/.github/workflows/procexp.yml b/.github/workflows/procexp.yml index 0a29e540..15553bdf 100644 --- a/.github/workflows/procexp.yml +++ b/.github/workflows/procexp.yml @@ -32,4 +32,17 @@ jobs: with: test: ${{ github.event_name == 'pull_request' || github.event.schedule == '0 4 * * *' || inputs.type == 'Test' }} force: ${{ inputs.type == 'Force update' }} + test_cases: | + - Start procexp + procexp + $sw = [System.Diagnostics.Stopwatch]::StartNew() + while ($sw.ElapsedMilliseconds -lt 60000) { + if (Get-Process procexp* -ErrorAction SilentlyContinue | Where-Object MainWindowHandle -NE 0) { + return + } + Start-Sleep -Milliseconds 500 + } + throw "Process start timed out." + - Close procexp + Get-Process procexp* | Should -Not -BeNullOrEmpty; Stop-Process -Name procexp* secrets: inherit diff --git a/.github/workflows/psinfo.yml b/.github/workflows/psinfo.yml index efc5f357..622f9b45 100644 --- a/.github/workflows/psinfo.yml +++ b/.github/workflows/psinfo.yml @@ -32,5 +32,7 @@ jobs: with: test: ${{ github.event_name == 'pull_request' || github.event.schedule == '0 4 * * *' || inputs.type == 'Test' }} force: ${{ inputs.type == 'Force update' }} - test_scripts: psinfo + test_cases: | + - Run psinfo + psinfo secrets: inherit diff --git a/.github/workflows/sabnzbd.yml b/.github/workflows/sabnzbd.yml index 2dda7a55..90213f72 100644 --- a/.github/workflows/sabnzbd.yml +++ b/.github/workflows/sabnzbd.yml @@ -32,7 +32,9 @@ jobs: with: test: ${{ github.event_name == 'pull_request' || github.event.schedule == '0 4 * * *' || inputs.type == 'Test' }} force: ${{ inputs.type == 'Force update' }} - test_scripts: | - Get-Service SABnzbd | ForEach-Object Status | Should -Be "Running" - Invoke-WebRequest "http://127.0.0.1:8080/" -UseBasicParsing + test_cases: | + - Check SABnzbd service + Get-Service SABnzbd | ForEach-Object Status | Should -Be "Running" + - Test web interface + Invoke-WebRequest "http://127.0.0.1:8080/" -UseBasicParsing secrets: inherit