[Windows] Stop SoftwareReport script if error (#4801)

* Stop SoftwareReport script if error

* Validate blank versions

* Fix tables parsing
This commit is contained in:
Aleksandr Chebotov
2021-12-24 10:58:19 +03:00
committed by GitHub
parent d4793cf476
commit 7518d04a3a
4 changed files with 66 additions and 14 deletions

View File

@@ -122,7 +122,7 @@ function Get-AndroidPlatformVersions {
function Get-AndroidCommandLineToolsVersion {
$commandLineTools = Get-AndroidSDKManagerPath
(& $commandLineTools --version | Out-String).Trim() -match "(?<version>^(\d+\.){1,}\d+$)" | Out-Null
(cmd /c "$commandLineTools --version 2>NUL" | Out-String).Trim() -match "(?<version>^(\d+\.){1,}\d+$)" | Out-Null
$commandLineToolsVersion = $Matches.Version
return $commandLineToolsVersion
}

View File

@@ -26,28 +26,29 @@ function Get-RustVersion {
}
function Get-RustupVersion {
$version = [regex]::matches($(rustup --version), "\d+\.\d+\.\d+").Value
return $version
$rustupInfo = cmd /c "rustup --version 2>NUL"
$version = [regex]::matches($rustupInfo, "\d+\.\d+\.\d+").Value
return $version
}
function Get-RustCargoVersion {
$version = [regex]::matches($(cargo --version), "\d+\.\d+\.\d+").Value
return $version
$version = [regex]::matches($(cargo --version), "\d+\.\d+\.\d+").Value
return $version
}
function Get-RustdocVersion {
$version = [regex]::matches($(rustdoc --version), "\d+\.\d+\.\d+").Value
return $version
$version = [regex]::matches($(rustdoc --version), "\d+\.\d+\.\d+").Value
return $version
}
function Get-RustfmtVersion {
$version = [regex]::matches($(rustfmt --version), "\d+\.\d+\.\d+").Value
return $version
$version = [regex]::matches($(rustfmt --version), "\d+\.\d+\.\d+").Value
return $version
}
function Get-RustClippyVersion {
$version = [regex]::matches($(cargo clippy --version), "\d+\.\d+\.\d+").Value
return $version
$version = [regex]::matches($(cargo clippy --version), "\d+\.\d+\.\d+").Value
return $version
}
function Get-BindgenVersion {
@@ -122,10 +123,8 @@ function Get-ChocoVersion {
}
function Get-VcpkgVersion {
($(vcpkg version) | Out-String) -match "version (?<version>\d+\.\d+\.\d+)" | Out-Null
$vcpkgVersion = $Matches.Version
$commitId = git -C "C:\vcpkg" rev-parse --short HEAD
return "Vcpkg $vcpkgVersion (build from master \<$commitId>)"
return "Vcpkg (build from master \<$commitId>)"
}
function Get-NPMVersion {

View File

@@ -1,3 +1,8 @@
$global:ErrorActionPreference = "Stop"
$global:ProgressPreference = "SilentlyContinue"
$ErrorView = "NormalView"
Set-StrictMode -Version Latest
Import-Module MarkdownPS
Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Android.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Browsers.psm1") -DisableNameChecking
@@ -294,4 +299,5 @@ if ($cachedImages) {
$markdown += $cachedImages | New-MDTable
}
Test-BlankElement -Markdown $markdown
$markdown | Out-File -FilePath "C:\InstalledSoftware.md"

View File

@@ -114,3 +114,50 @@ function Get-PathWithLink {
$link = Get-LinkTarget($inputPath)
return "${inputPath}${link}"
}
function Test-BlankElement {
param(
[string] $Markdown
)
$splitByLines = $Markdown.Split("`n")
# Validate entry without version
$blankVersions = $splitByLines -match "^-" -notmatch "(OS|Image) Version|WSL|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
}
}