mirror of
https://github.com/actions/runner-images.git
synced 2026-01-07 02:28:54 +08:00
Improve table and tool versions comparison for new Software Report module (#6729)
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -9,8 +9,7 @@ function Get-BashVersion {
|
||||
|
||||
function Get-DotnetVersionList {
|
||||
$sdkRawList = Run-Command "dotnet --list-sdks"
|
||||
$sdkVersionList = $sdkRawList | ForEach-Object { Take-Part $_ -Part 0 }
|
||||
return [string]::Join(" ", $sdkVersionList)
|
||||
return $sdkRawList | ForEach-Object { Take-Part $_ -Part 0 }
|
||||
}
|
||||
|
||||
function Get-GoVersion {
|
||||
@@ -148,8 +147,7 @@ function Get-NVMNodeVersionList {
|
||||
$nvmInitCommand = ". ${nvmPath} > /dev/null 2>&1 || true"
|
||||
$nodejsVersionsRaw = Run-Command "${nvmInitCommand} && nvm ls"
|
||||
$nodeVersions = $nodejsVersionsRaw | ForEach-Object { $_.TrimStart(" ").TrimEnd(" *") } | Where-Object { $_.StartsWith("v") }
|
||||
$formattedNodeVersions = $nodeVersions | ForEach-Object { $_.TrimStart("v") }
|
||||
return [string]::Join(" ", $formattedNodeVersions)
|
||||
return $nodeVersions | ForEach-Object { $_.TrimStart("v") }
|
||||
}
|
||||
|
||||
function Build-OSInfoSection {
|
||||
@@ -331,7 +329,7 @@ function Get-PackerVersion {
|
||||
}
|
||||
|
||||
function Get-OpenSSLVersion {
|
||||
$opensslVersion = Get-Item /usr/local/opt/openssl@1.1 | ForEach-Object {"{0} ``({1} -> {2})``" -f (Run-Command "openssl version"), $_.FullName, $_.Target}
|
||||
$opensslVersion = Run-Command "openssl version"
|
||||
return ($opensslVersion -replace "^OpenSSL").Trim()
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ $installedSoftware = $softwareReport.Root.AddHeaderNode("Installed Software")
|
||||
|
||||
# Language and Runtime
|
||||
$languageAndRuntime = $installedSoftware.AddHeaderNode("Language and Runtime")
|
||||
$languageAndRuntime.AddToolNode(".NET SDK", $(Get-DotnetVersionList))
|
||||
$languageAndRuntime.AddToolVersionsNode(".NET Core SDK", $(Get-DotnetVersionList), '^\d+\.\d+\.\d', $true)
|
||||
$languageAndRuntime.AddToolNode("Bash", $(Get-BashVersion))
|
||||
$languageAndRuntime.AddNodes($(Get-ClangLLVMVersions))
|
||||
$languageAndRuntime.AddNodes($(Get-GccVersions))
|
||||
@@ -45,7 +45,7 @@ $languageAndRuntime.AddToolNode("Mono", $(Get-MonoVersion))
|
||||
$languageAndRuntime.AddToolNode("MSBuild", $(Get-MSBuildVersion))
|
||||
$languageAndRuntime.AddToolNode("Node.js", $(Get-NodeVersion))
|
||||
$languageAndRuntime.AddToolNode("NVM", $(Get-NVMVersion))
|
||||
$languageAndRuntime.AddToolNode("NVM - Cached node versions:", $(Get-NVMNodeVersionList))
|
||||
$languageAndRuntime.AddToolVersionsNode("NVM - Cached node versions", $(Get-NVMNodeVersionList), '^\d+', $true)
|
||||
$languageAndRuntime.AddToolNode("Perl", $(Get-PerlVersion))
|
||||
$languageAndRuntime.AddToolNode("PHP", $(Get-PHPVersion))
|
||||
$languageAndRuntime.AddToolNode("Python", $(Get-PythonVersion))
|
||||
@@ -153,7 +153,7 @@ $tools.AddToolNode("Xcode Command Line Tools", $(Get-XcodeCommandLineToolsVersio
|
||||
|
||||
# Linters
|
||||
$linters = $installedSoftware.AddHeaderNode("Linters")
|
||||
$linters.AddToolNode("Swift", $(Get-SwiftLintVersion))
|
||||
$linters.AddToolNode("SwiftLint", $(Get-SwiftLintVersion))
|
||||
$linters.AddToolNode("Yamllint", $(Get-YamllintVersion))
|
||||
|
||||
# Browsers
|
||||
@@ -193,7 +193,7 @@ $powerShell = $installedSoftware.AddHeaderNode("PowerShell Tools")
|
||||
$powerShell.AddToolNode("PowerShell", $(Get-PowershellVersion))
|
||||
|
||||
$powerShellModules = $powerShell.AddHeaderNode("PowerShell Modules")
|
||||
$powerShellModules.AddTableNode($(Get-PowerShellModules))
|
||||
$powerShellModules.AddNodes($(Get-PowerShellModules))
|
||||
|
||||
# Web Servers
|
||||
$webServers = $installedSoftware.AddHeaderNode("Web Servers")
|
||||
|
||||
@@ -28,47 +28,26 @@ function Get-ToolcacheNodeVersions {
|
||||
return Get-ChildItem $toolcachePath -Name | Sort-Object { [Version]$_ }
|
||||
}
|
||||
|
||||
function Get-ToolcacheGoTable {
|
||||
$ToolInstances = Get-CachedToolInstances -Name "Go" -VersionCommand "version"
|
||||
foreach ($Instance in $ToolInstances) {
|
||||
$Version = [System.Version]($Instance.Version -Split(" "))[0]
|
||||
$Instance."Environment Variable" = "GOROOT_$($Version.major)_$($Version.minor)_X64"
|
||||
}
|
||||
|
||||
$Content = $ToolInstances | ForEach-Object {
|
||||
return [PSCustomObject]@{
|
||||
Version = $_.Version
|
||||
Architecture = $_.Architecture
|
||||
"Environment Variable" = $_."Environment Variable"
|
||||
}
|
||||
}
|
||||
|
||||
return $Content
|
||||
function Get-ToolcacheGoVersions {
|
||||
$toolcachePath = Join-Path $env:HOME "hostedtoolcache" "Go"
|
||||
return Get-ChildItem $toolcachePath -Name | Sort-Object { [Version]$_ }
|
||||
}
|
||||
|
||||
function Build-ToolcacheSection {
|
||||
$goToolNode = [HeaderNode]::new("Go")
|
||||
$goToolNode.AddTableNode($(Get-ToolcacheGoTable))
|
||||
return @(
|
||||
[ToolVersionsNode]::new("Ruby", $(Get-ToolcacheRubyVersions))
|
||||
[ToolVersionsNode]::new("Python", $(Get-ToolcachePythonVersions))
|
||||
[ToolVersionsNode]::new("PyPy", $(Get-ToolcachePyPyVersions))
|
||||
[ToolVersionsNode]::new("Node.js", $(Get-ToolcacheNodeVersions))
|
||||
$goToolNode
|
||||
[ToolVersionsNode]::new("Ruby", $(Get-ToolcacheRubyVersions), '^\d+\.\d+', $false),
|
||||
[ToolVersionsNode]::new("Python", $(Get-ToolcachePythonVersions), '^\d+\.\d+', $false),
|
||||
[ToolVersionsNode]::new("PyPy", $(Get-ToolcachePyPyVersions), '^\d+\.\d+', $false),
|
||||
[ToolVersionsNode]::new("Node.js", $(Get-ToolcacheNodeVersions), '^\d+', $false),
|
||||
[ToolVersionsNode]::new("Go", $(Get-ToolcacheGoVersions), '^\d+\.\d+', $false)
|
||||
)
|
||||
}
|
||||
|
||||
function Get-PowerShellModules {
|
||||
$modules = (Get-ToolsetValue powershellModules).name
|
||||
|
||||
$psModules = Get-Module -Name $modules -ListAvailable | Sort-Object Name | Group-Object Name
|
||||
return $psModules | ForEach-Object {
|
||||
$moduleName = $_.Name
|
||||
$moduleVersions = ($_.group.Version | Sort-Object -Unique) -join '<br>'
|
||||
|
||||
[PSCustomObject]@{
|
||||
Module = $moduleName
|
||||
Version = $moduleVersions
|
||||
}
|
||||
$modules | ForEach-Object {
|
||||
$moduleName = $_
|
||||
$moduleVersions = Get-Module -Name $moduleName -ListAvailable | Select-Object -ExpandProperty Version | Sort-Object -Unique
|
||||
return [ToolVersionsNode]::new($moduleName, $moduleVersions, '^\d+', $true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user