mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 06:08:07 +00:00
[Ubuntu] Add verbosity during software report generation (#4811)
* Add verbosity during software report generation * Fix Get-CpanVersion * set default ValidateExitCode value to $true * update java test * use lower-case for parameters
This commit is contained in:
committed by
GitHub
parent
bb56fb7ef4
commit
92eeb55189
@@ -2,11 +2,27 @@ function Get-CommandResult {
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $Command,
|
||||
[switch] $Multiline
|
||||
[int[]] $ExpectExitCode = 0,
|
||||
[switch] $Multiline,
|
||||
[bool] $ValidateExitCode = $true
|
||||
)
|
||||
|
||||
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
|
||||
$stdout = & bash -c "$Command 2>&1"
|
||||
$exitCode = $LASTEXITCODE
|
||||
|
||||
if ($ValidateExitCode) {
|
||||
if ($ExpectExitCode -notcontains $exitCode) {
|
||||
try {
|
||||
throw "StdOut: '$stdout' ExitCode: '$exitCode'"
|
||||
} catch {
|
||||
Write-Host $_.Exception.Message
|
||||
Write-Host $_.ScriptStackTrace
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return @{
|
||||
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout }
|
||||
ExitCode = $exitCode
|
||||
|
||||
@@ -110,3 +110,49 @@ function Get-AptSourceRepository {
|
||||
return $sourceUrl
|
||||
}
|
||||
|
||||
function Test-BlankElement {
|
||||
param(
|
||||
[string] $Markdown
|
||||
)
|
||||
|
||||
$splitByLines = $Markdown.Split("`n")
|
||||
# Validate entry without version
|
||||
$blankVersions = $splitByLines -match "^-" -notmatch "Image Version|MySQL Server|Vcpkg|\d\." | Out-String
|
||||
|
||||
# Validate tables with blank rows
|
||||
$blankRows = ""
|
||||
for($i = 0; $i -lt $splitByLines.Length; $i++) {
|
||||
$addRows= $false
|
||||
$table = @()
|
||||
if ($splitByLines[$i].StartsWith("#") -and $splitByLines[$i+1].StartsWith("|")) {
|
||||
$table += $splitByLines[$i,($i+1),($i+2)]
|
||||
$i += 3
|
||||
$current = $splitByLines[$i]
|
||||
while ($current.StartsWith("|")) {
|
||||
$isBlankRow = $current.Substring(1, $current.LastIndexOf("|") - 2).Split("|").Trim() -contains ""
|
||||
if ($isBlankRow) {
|
||||
$table += $current
|
||||
$addRows = $true
|
||||
}
|
||||
$current = $splitByLines[++$i]
|
||||
}
|
||||
if ($addRows) {
|
||||
$blankRows += $table | Out-String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Display report
|
||||
$isReport = $false
|
||||
if ($blankVersions) {
|
||||
Write-Host "Software list with blank version:`n${blankVersions}"
|
||||
$isReport = $true
|
||||
}
|
||||
if ($blankRows) {
|
||||
Write-Host "Tables with blank rows:`n${blankRows}"
|
||||
$isReport = $true
|
||||
}
|
||||
if ($isReport) {
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ function Invoke-PesterTests {
|
||||
|
||||
function ShouldReturnZeroExitCode {
|
||||
Param(
|
||||
[String] $ActualValue,
|
||||
[string] $ActualValue,
|
||||
[switch] $Negate,
|
||||
[string] $Because # This parameter is unused but we need it to match Pester asserts signature
|
||||
)
|
||||
|
||||
$result = Get-CommandResult $ActualValue
|
||||
$result = Get-CommandResult $ActualValue -ValidateExitCode $false
|
||||
|
||||
[bool]$succeeded = $result.ExitCode -eq 0
|
||||
if ($Negate) { $succeeded = -not $succeeded }
|
||||
@@ -69,12 +69,12 @@ function ShouldReturnZeroExitCode {
|
||||
|
||||
function ShouldMatchCommandOutput {
|
||||
Param(
|
||||
[String] $ActualValue,
|
||||
[String] $RegularExpression,
|
||||
[string] $ActualValue,
|
||||
[string] $RegularExpression,
|
||||
[switch] $Negate
|
||||
)
|
||||
|
||||
$output = (Get-CommandResult $ActualValue).Output | Out-String
|
||||
$output = (Get-CommandResult $ActualValue -ValidateExitCode $false).Output | Out-String
|
||||
[bool] $succeeded = $output -cmatch $RegularExpression
|
||||
|
||||
if ($Negate) {
|
||||
|
||||
Reference in New Issue
Block a user