Improve table and tool versions comparison for new Software Report module (#6729)

This commit is contained in:
Maxim Lobanov
2022-12-13 16:54:41 +01:00
committed by GitHub
parent 656d9522e0
commit 6033af8dd1
8 changed files with 120 additions and 135 deletions

View File

@@ -23,14 +23,6 @@ function Take-Part {
return [string]::Join($Delimiter, $selectedParts)
}
function New-MDNewLine {
param (
[int] $Count = 1
)
$newLineSymbol = [System.Environment]::NewLine
return $newLineSymbol * $Count
}
function Get-LinkTarget {
param (
[string] $inputPath
@@ -60,61 +52,3 @@ function Get-BrewPackageVersion {
return $packageVersion
}
function Get-CachedToolInstances {
<#
.SYNOPSIS
Returns hashtable of installed cached tools.
.DESCRIPTION
Return hashtable that contains versions and architectures for the selected cached tool.
.PARAMETER Name
Name of cached tool.
.PARAMETER VersionCommand
Optional parameter. Command to return version of system default tool.
.EXAMPLE
Get-CachedToolInstances -Name "Python" -VersionCommand "--version"
#>
param
(
[String] $Name,
[String] $VersionCommand
)
$toolInstances = @()
$toolPath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath $Name
# Get all installed versions from TOOLSDIRECTORY folder
$versions = Get-ChildItem $toolPath | Sort-Object { [System.Version]$_.Name }
foreach ($version in $versions) {
$instanceInfo = @{}
# Create instance hashtable
[string]$instanceInfo.Path = Join-Path -Path $toolPath -ChildPath $version.Name
[string]$instanceInfo.Version = $version.Name
# Get all architectures for current version
[array]$instanceInfo.Architecture_Array = Get-ChildItem $version.FullName -Name -Directory | Where-Object { $_ -match "^x[0-9]{2}$" }
[string]$instanceInfo.Architecture = $instanceInfo.Architecture_Array -Join ", "
# Add (default) postfix to version name, in case if current version is in environment path
if (-not ([string]::IsNullOrEmpty($VersionCommand))) {
$defaultVersion = $(& ($Name.ToLower()) $VersionCommand 2>&1)
$defaultToolVersion = $defaultVersion | Select-String -Pattern "\d+\.\d+\.\d+" -AllMatches `
| ForEach-Object { $_.Matches.Value }
if ([version]$version.Name -eq [version]$defaultToolVersion) {
$instanceInfo.Version += " (Default)"
}
}
$toolInstances += $instanceInfo
}
return $toolInstances
}