diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 index 11840825b..19dd7cee3 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 @@ -32,6 +32,19 @@ $webDrivers = @{ } } +function Build-BrowserSection { + return @( + $(Get-BrowserVersion -Browser "chrome"), + $(Get-SeleniumWebDriverVersion -Driver "chrome"), + $(Get-BrowserVersion -Browser "edge"), + $(Get-SeleniumWebDriverVersion -Driver "edge"), + $(Get-BrowserVersion -Browser "firefox"), + $(Get-SeleniumWebDriverVersion -Driver "firefox"), + $(Get-SeleniumWebDriverVersion -Driver "iexplorer"), + $(Get-SeleniumVersion) + ) +} + function Get-BrowserVersion { param( [string] $Browser @@ -40,7 +53,7 @@ function Get-BrowserVersion { $browserFile = $browsers.$Browser.File $registryKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\$browserFile" $browserVersion = (Get-Item (Get-ItemProperty $registryKey)."(Default)").VersionInfo.FileVersion - return "$browserName $browserVersion" + return [ToolVersionNode]::new($browserName, $browserVersion) } function Get-SeleniumWebDriverVersion { @@ -51,13 +64,13 @@ function Get-SeleniumWebDriverVersion { $driverPath = $webDrivers.$Driver.Path $versionFileName = "versioninfo.txt"; $webDriverVersion = Get-Content -Path "$driverPath\$versionFileName" - return "$driverName $webDriverVersion" + return [ToolVersionNode]::new($driverName, $webDriverVersion) } function Get-SeleniumVersion { $seleniumBinaryName = (Get-ToolsetContent).selenium.binary_name $fullSeleniumVersion = (Get-ChildItem "C:\selenium\${seleniumBinaryName}-*").Name -replace "${seleniumBinaryName}-" - return "Selenium server $fullSeleniumVersion" + return [ToolVersionNode]::new("Selenium server", $fullSeleniumVersion) } function Build-BrowserWebdriversEnvironmentTable { diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 index 47374c111..d76837730 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 @@ -30,22 +30,11 @@ function Get-ToolcachePyPyVersions { function Build-CachedToolsSection { - $output = "" - - $output += New-MDHeader "Go" -Level 4 - $output += New-MDList -Lines (Get-ToolcacheGoVersions) -Style Unordered - - $output += New-MDHeader "Node.js" -Level 4 - $output += New-MDList -Lines (Get-ToolcacheNodeVersions) -Style Unordered - - $output += New-MDHeader "Python" -Level 4 - $output += New-MDList -Lines (Get-ToolcachePythonVersions) -Style Unordered - - $output += New-MDHeader "PyPy" -Level 4 - $output += New-MDList -Lines (Get-ToolcachePyPyVersions) -Style Unordered - - $output += New-MDHeader "Ruby" -Level 4 - $output += New-MDList -Lines (Get-ToolcacheRubyVersions) -Style Unordered - - return $output + return @( + [ToolVersionsListNode]::new("Go", $(Get-ToolcacheGoVersions), '^\d+\.\d+', 'List'), + [ToolVersionsListNode]::new("Node.js", $(Get-ToolcacheNodeVersions), '^\d+', 'List'), + [ToolVersionsListNode]::new("Python", $(Get-ToolcachePythonVersions), '^\d+\.\d+', 'List'), + [ToolVersionsListNode]::new("PyPy", $(Get-ToolcachePyPyVersions), '^\d+\.\d+', 'List'), + [ToolVersionsListNode]::new("Ruby", $(Get-ToolcacheRubyVersions), '^\d+\.\d+', 'List') + ) } diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 index 37bb9df1b..2ccce45b6 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Common.psm1 @@ -11,16 +11,22 @@ function Get-OSName { function Get-OSVersion { $OSVersion = (Get-CimInstance -ClassName Win32_OperatingSystem).Version $OSBuild = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion' UBR).UBR - return "OS Version: $OSVersion Build $OSBuild" + return "$OSVersion Build $OSBuild" +} + +function Build-OSInfoSection { + $osInfoNode = [HeaderNode]::new($(Get-OSName)) + $osInfoNode.AddToolVersion("OS Version:", $(Get-OSVersion)) + $osInfoNode.AddToolVersion("Image Version:", $env:IMAGE_VERSION) + return $osInfoNode } function Get-BashVersion { $version = bash --% -c 'echo ${BASH_VERSION}' - return "Bash $version" + return $version } function Get-RustVersion { - Initialize-RustEnvironment $rustVersion = [regex]::matches($(rustc --version), "\d+\.\d+\.\d+").Value return $rustVersion } @@ -52,145 +58,144 @@ function Get-RustClippyVersion { } function Get-BindgenVersion { - return bindgen --version + return ((bindgen --version) -replace "^bindgen").Trim() } function Get-CbindgenVersion { - return cbindgen --version + return ((cbindgen --version) -replace "^cbindgen").Trim() } function Get-CargoAuditVersion { - return cargo-audit --version + return ((cargo-audit --version) -replace "^cargo-audit").Trim() } function Get-CargoOutdatedVersion { - return cargo outdated --version + return ((cargo outdated --version) -replace "^cargo-outdated").Trim() } function Get-PythonVersion { - return & python --version + return ((python --version) -replace "^Python").Trim() } function Get-PowershellCoreVersion { - return & pwsh --version + return ((pwsh --version) -replace "^PowerShell").Trim() } function Get-RubyVersion { $rubyVersion = $(ruby --version).split(" ")[1] - return "Ruby $rubyVersion" + return $rubyVersion } function Get-GoVersion { $(go version) -match "go(?\d+\.\d+\.\d+)" | Out-Null $goVersion = $Matches.Version - return "Go $goVersion" + return $goVersion } function Get-KotlinVersion { $kotlinVersion = $((cmd /c "kotlinc -version 2>&1") | Out-String).split(" ")[2] - return "Kotlin $kotlinVersion" + return $kotlinVersion } function Get-PHPVersion { ($(php --version) | Out-String) -match "PHP (?\d+\.\d+\.\d+)" | Out-Null $phpVersion = $Matches.Version - return "PHP $phpVersion" + return $phpVersion } function Get-JuliaVersion { $juliaVersion = [regex]::matches($(julia --version), "\d+\.\d+\.\d+").Value - return "Julia $juliaVersion" + return $juliaVersion } function Get-LLVMVersion { $llvmVersion = [regex]::matches($(clang --version), "\d+\.\d+\.\d+").Value - return "LLVM $llvmVersion" + return $llvmVersion } function Get-PerlVersion { ($(perl --version) | Out-String) -match "\(v(?\d+\.\d+\.\d+)\)" | Out-Null $perlVersion = $Matches.Version - return "Perl $perlVersion" + return $perlVersion } function Get-NodeVersion { $nodeVersion = $(node --version).split("v")[1] - return "Node $nodeVersion" + return $nodeVersion } function Get-ChocoVersion { - return "Chocolatey $(choco --version)" + return $(choco --version) } function Get-VcpkgVersion { $commitId = git -C "C:\vcpkg" rev-parse --short HEAD - return "Vcpkg (build from commit $commitId)" + return "(build from commit $commitId)" } function Get-NPMVersion { - return "NPM $(npm -version)" + return $(npm -version) } function Get-YarnVersion { - return "Yarn $(yarn -version)" + return $(yarn -version) } function Get-RubyGemsVersion { - return "RubyGems $(gem --version)" + return $(gem --version) } function Get-HelmVersion { ($(helm version --short) | Out-String) -match "v(?\d+\.\d+\.\d+)" | Out-Null $helmVersion = $Matches.Version - return "Helm $helmVersion" + return $helmVersion } function Get-PipVersion { ($(pip --version) | Out-String) -match "(?pip [\d\.]+) .+ (?\(python [\d\.]+\))" | Out-Null $pipVersion = $Matches.Version $pythonVersion = $Matches.Python - return "$pipVersion $pythonVersion" + return ("$pipVersion $pythonVersion" -replace "^pip").Trim() } function Get-CondaVersion { - $condaVersion = & "$env:CONDA\Scripts\conda.exe" --version - return "Mini$condaVersion (pre-installed on the image but not added to PATH)" + $condaVersion = ((& "$env:CONDA\Scripts\conda.exe" --version) -replace "^conda").Trim() + return "$condaVersion (pre-installed on the image but not added to PATH)" } function Get-ComposerVersion { - composer --version | Take-Part -Part 0,2 + composer --version | Take-Part -Part 2 } function Get-NugetVersion { - (nuget help) -match "NuGet Version" -replace "Version: " + return (((nuget help) -match "NuGet Version") -replace "NuGet Version:").Trim() } function Get-AntVersion { ($(ant -version) | Out-String) -match "version (?\d+\.\d+\.\d+)" | Out-Null $antVersion = $Matches.Version - return "Ant $antVersion" + return $antVersion } function Get-MavenVersion { ($(mvn -version) | Out-String) -match "Apache Maven (?\d+\.\d+\.\d+)" | Out-Null $mavenVersion = $Matches.Version - return "Maven $mavenVersion" + return $mavenVersion } function Get-GradleVersion { ($(gradle -version) | Out-String) -match "Gradle (?\d+\.\d+)" | Out-Null $gradleVersion = $Matches.Version - return "Gradle $gradleVersion" + return $gradleVersion } function Get-SbtVersion { - $sbtVersion = (sbt -version) -match "sbt script version:" -replace "script version: " - return "$sbtVersion" + return ((sbt -version) -match "sbt script version:" -replace "sbt script version:").Trim() } function Get-DotnetSdks { $sdksRawList = dotnet --list-sdks - $sdkVersions = ($sdksRawList | Foreach-Object {$_.Split()[0]}) -join ', ' + $sdkVersions = $sdksRawList | Foreach-Object {$_.Split()[0]} $sdkPath = $sdksRawList[0].Split(' ', 2)[1] -replace '\[|]' [PSCustomObject]@{ Versions = $sdkVersions @@ -205,7 +210,8 @@ function Get-DotnetTools { $toolsList = @() foreach ($dotnetTool in $dotnetTools) { - $toolsList += $dotnetTool.name + " " + (Invoke-Expression $dotnetTool.getversion) + $version = Invoke-Expression $dotnetTool.getversion + $toolsList += [ToolVersionNode]::new($dotnetTool.name, $version) } return $toolsList } @@ -214,7 +220,7 @@ function Get-DotnetRuntimes { $runtimesRawList = dotnet --list-runtimes $runtimesRawList | Group-Object {$_.Split()[0]} | ForEach-Object { $runtimeName = $_.Name - $runtimeVersions = ($_.Group | Foreach-Object {$_.split()[1]}) -join ', ' + $runtimeVersions = $_.Group | Foreach-Object {$_.split()[1]} $runtimePath = $_.Group[0].Split(' ', 3)[2] -replace '\[|]' [PSCustomObject]@{ "Runtime" = $runtimeName @@ -226,8 +232,7 @@ function Get-DotnetRuntimes { function Get-DotnetFrameworkVersions { $path = "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\*\*\NETFX * Tools" - $versions = Get-ChildItem -Path $path -Directory | ForEach-Object { $_.Name | Take-Part -Part 1 } - $versions -join ', ' + return Get-ChildItem -Path $path -Directory | ForEach-Object { $_.Name | Take-Part -Part 1 } } function Get-PowerShellAzureModules { @@ -236,32 +241,32 @@ function Get-PowerShellAzureModules { [Array] $azInstalledModules = Get-ChildItem -Path "C:\Modules\az_*" -Directory | ForEach-Object { $_.Name.Split("_")[1] } if ($azInstalledModules.Count -gt 0) { - $result += "Az: $($azInstalledModules -join ', ')" + $result += [ToolVersionsListNode]::new("Az", $($azInstalledModules), '^\d+\.\d+', "Inline") } [Array] $azureInstalledModules = Get-ChildItem -Path "C:\Modules\azure_*" -Directory | ForEach-Object { $_.Name.Split("_")[1] } | ForEach-Object { if ($_ -eq $defaultAzureModuleVersion) { "$($_) (Default)" } else { $_ } } if ($azureInstalledModules.Count -gt 0) { - $result += "Azure: $($azureInstalledModules -join ', ')" + $result += [ToolVersionsListNode]::new("Azure", $($azureInstalledModules), '^\d+\.\d+', "Inline") } [Array] $azurermInstalledModules = Get-ChildItem -Path "C:\Modules\azurerm_*" -Directory | ForEach-Object { $_.Name.Split("_")[1] } | ForEach-Object { if ($_ -eq $defaultAzureModuleVersion) { "$($_) (Default)" } else { $_ } } if ($azurermInstalledModules.Count -gt 0) { - $result += "AzureRM: $($azurermInstalledModules -join ', ')" + $result += [ToolVersionsListNode]::new("AzureRM", $($azurermInstalledModules), '^\d+\.\d+', "Inline") } [Array] $azCachedModules = Get-ChildItem -Path "C:\Modules\az_*.zip" -File | ForEach-Object { $_.Name.Split("_")[1] } if ($azCachedModules.Count -gt 0) { - $result += "Az (Cached): $($azCachedModules -join ', ')" + $result += [ToolVersionsListNode]::new("Az (Cached)", $($azCachedModules), '^\d+\.\d+', "Inline") } [Array] $azureCachedModules = Get-ChildItem -Path "C:\Modules\azure_*.zip" -File | ForEach-Object { $_.Name.Split("_")[1] } if ($azureCachedModules.Count -gt 0) { - $result += "Azure (Cached): $($azureCachedModules -join ', ')" + $result += [ToolVersionsListNode]::new("Azure (Cached)", $($azureCachedModules), '^\d+\.\d+', "Inline") } [Array] $azurermCachedModules = Get-ChildItem -Path "C:\Modules\azurerm_*.zip" -File | ForEach-Object { $_.Name.Split("_")[1] } if ($azurermCachedModules.Count -gt 0) { - $result += "AzureRM: $($azurermCachedModules -join ', ')" + $result += [ToolVersionsListNode]::new("AzureRM (Cached)", $($azurermCachedModules), '^\d+\.\d+', "Inline") } return $result @@ -275,7 +280,7 @@ function Get-PowerShellModules { $result += (Get-ToolsetContent).powershellModules.name | Sort-Object | ForEach-Object { $moduleName = $_ $moduleVersions = Get-Module -Name $moduleName -ListAvailable | Select-Object -ExpandProperty Version | Sort-Object -Unique - return "$($moduleName): $($moduleVersions -join ', ')" + return [ToolVersionsListNode]::new($moduleName, $moduleVersions, '^\d+', "Inline") } return $result @@ -302,14 +307,13 @@ function Get-CachedDockerImagesTableData { } function Get-ShellTarget { - $shells = Get-ChildItem C:\shells -File | Select-Object Name, @{n="Target";e={ + return Get-ChildItem C:\shells -File | Select-Object Name, @{n="Target";e={ if ($_.Name -eq "msys2bash.cmd") { "C:\msys64\usr\bin\bash.exe" } else { @($_.Target)[0] } }} | Sort-Object Name - $shells | New-MDTable -Columns ([ordered]@{Name = "left"; Target = "left";}) } function Get-PacmanVersion { @@ -318,21 +322,21 @@ function Get-PacmanVersion { $rawVersion = & $pacmanPath --version $rawVersion.Split([System.Environment]::NewLine)[1] -match "\d+\.\d+(\.\d+)?" | Out-Null $pacmanVersion = $matches[0] - return "Pacman $pacmanVersion" + return $pacmanVersion } function Get-YAMLLintVersion { - yamllint --version + return ((yamllint --version) -replace "^yamllint").Trim() } function Get-BizTalkVersion { $bizTalkReg = Get-ItemProperty "HKLM:\SOFTWARE\WOW6432Node\Microsoft\BizTalk Server\3.0" - return "$($bizTalkReg.ProductName) $($bizTalkReg.ProductVersion)" + return [ToolVersionNode]::new($bizTalkReg.ProductName, $bizTalkReg.ProductVersion) } function Get-PipxVersion { $pipxVersion = pipx --version - return "Pipx $pipxVersion" + return $pipxVersion } function Build-PackageManagementEnvironmentTable { diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 index 86c58bc17..9d5e612bc 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 @@ -1,13 +1,12 @@ -function Get-PostgreSQLMarkdown +function Get-PostgreSQLTable { - $name = "PostgreSQL" $pgService = Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'" $pgPath = $pgService.PathName $pgRoot = $pgPath.split('"')[1].replace("\bin\pg_ctl.exe", "") $env:Path += ";${env:PGBIN}" $pgVersion = (postgres --version).split()[2].Trim() - $content = @( + return @( [PSCustomObject]@{ Property = "ServiceName"; Value = $pgService.Name }, [PSCustomObject]@{ Property = "Version"; Value = $pgVersion }, [PSCustomObject]@{ Property = "ServiceStatus"; Value = $pgService.State }, @@ -16,29 +15,18 @@ function Get-PostgreSQLMarkdown [PSCustomObject]@{ Property = "Path"; Value = $pgRoot }, [PSCustomObject]@{ Property = "UserName"; Value = $env:PGUSER }, [PSCustomObject]@{ Property = "Password"; Value = $env:PGPASSWORD } - ) | New-MDTable - - Build-MarkdownElement -Head $name -Content $content + ) } -function Get-MongoDBMarkdown +function Get-MongoDBTable { $name = "MongoDB" $mongoService = Get-Service -Name $name $mongoVersion = (Get-Command -Name 'mongo').Version.ToString() - $content = [PSCustomObject]@{ + return [PSCustomObject]@{ Version = $mongoVersion ServiceName = $name ServiceStatus = $mongoService.Status ServiceStartType = $mongoService.StartType - } | New-MDTable - Build-MarkdownElement -Head $name -Content $content + } } - -function Build-DatabasesMarkdown -{ - $markdown = "" - $markdown += Get-PostgreSQLMarkdown - $markdown += Get-MongoDBMarkdown - $markdown -} \ No newline at end of file diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index 806323d9e..a89db9cf3 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -1,9 +1,11 @@ +using module ./software-report-base/SoftwareReport.psm1 +using module ./software-report-base/SoftwareReport.Nodes.psm1 + $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 Import-Module (Join-Path $PSScriptRoot "SoftwareReport.CachedTools.psm1") -DisableNameChecking @@ -15,279 +17,222 @@ Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Java.psm1") -DisableNameC Import-Module (Join-Path $PSScriptRoot "SoftwareReport.WebServers.psm1") -DisableNameChecking Import-Module (Join-Path $PSScriptRoot "SoftwareReport.VisualStudio.psm1") -DisableNameChecking -$markdown = "" +# Software report +$softwareReport = [SoftwareReport]::new($(Build-OSInfoSection)) +$optionalFeatures = $softwareReport.Root.AddHeader("Windows features") +$optionalFeatures.AddToolVersion("Windows Subsystem for Linux (WSLv1):", "Enabled") +$installedSoftware = $softwareReport.Root.AddHeader("Installed Software") -$OSName = Get-OSName -$markdown += New-MDHeader "$OSName" -Level 1 +# Language and Runtime +$languageAndRuntime = $installedSoftware.AddHeader("Language and Runtime") +$languageAndRuntime.AddToolVersion("Bash", $(Get-BashVersion)) +$languageAndRuntime.AddToolVersion("Go", $(Get-GoVersion)) +$languageAndRuntime.AddToolVersion("Julia", $(Get-JuliaVersion)) +$languageAndRuntime.AddToolVersion("Kotlin", $(Get-KotlinVersion)) +$languageAndRuntime.AddToolVersion("LLVM", $(Get-LLVMVersion)) +$languageAndRuntime.AddToolVersion("Node", $(Get-NodeVersion)) +$languageAndRuntime.AddToolVersion("Perl", $(Get-PerlVersion)) +$languageAndRuntime.AddToolVersion("PHP", $(Get-PHPVersion)) +$languageAndRuntime.AddToolVersion("Python", $(Get-PythonVersion)) +$languageAndRuntime.AddToolVersion("Ruby", $(Get-RubyVersion)) -$OSVersion = Get-OSVersion -$markdown += New-MDList -Style Unordered -Lines @( - "$OSVersion" - "Image Version: $env:IMAGE_VERSION" -) +# Package Management +$packageManagement = $installedSoftware.AddHeader("Package Management") +$packageManagement.AddToolVersion("Chocolatey", $(Get-ChocoVersion)) +$packageManagement.AddToolVersion("Composer", $(Get-ComposerVersion)) +$packageManagement.AddToolVersion("Helm", $(Get-HelmVersion)) +$packageManagement.AddToolVersion("Miniconda", $(Get-CondaVersion)) +$packageManagement.AddToolVersion("NPM", $(Get-NPMVersion)) +$packageManagement.AddToolVersion("NuGet", $(Get-NugetVersion)) +$packageManagement.AddToolVersion("pip", $(Get-PipVersion)) +$packageManagement.AddToolVersion("Pipx", $(Get-PipxVersion)) +$packageManagement.AddToolVersion("RubyGems", $(Get-RubyGemsVersion)) +$packageManagement.AddToolVersion("Vcpkg", $(Get-VcpkgVersion)) +$packageManagement.AddToolVersion("Yarn", $(Get-YarnVersion)) -$markdown += New-MDHeader "Windows features" -Level 2 -$markdown += New-MDList -Style Unordered -Lines @( - "Windows Subsystem for Linux (WSLv1): Enabled" -) +$packageManagement.AddHeader("Environment variables").AddTable($(Build-PackageManagementEnvironmentTable)) -$markdown += New-MDHeader "Installed Software" -Level 2 -$markdown += New-MDHeader "Language and Runtime" -Level 3 -$languageTools = @( - (Get-BashVersion), - (Get-GoVersion), - (Get-JuliaVersion), - (Get-LLVMVersion), - (Get-NodeVersion), - (Get-PerlVersion) - (Get-PHPVersion), - (Get-PythonVersion), - (Get-RubyVersion), - (Get-KotlinVersion) -) -$markdown += New-MDList -Style Unordered -Lines ($languageTools | Sort-Object) +# Project Management +$projectManagement = $installedSoftware.AddHeader("Project Management") +$projectManagement.AddToolVersion("Ant", $(Get-AntVersion)) +$projectManagement.AddToolVersion("Gradle", $(Get-GradleVersion)) +$projectManagement.AddToolVersion("Maven", $(Get-MavenVersion)) +$projectManagement.AddToolVersion("sbt", $(Get-SbtVersion)) -$packageManagementList = @( - (Get-ChocoVersion), - (Get-CondaVersion), - (Get-ComposerVersion), - (Get-HelmVersion), - (Get-NPMVersion), - (Get-NugetVersion), - (Get-PipxVersion), - (Get-PipVersion), - (Get-RubyGemsVersion), - (Get-VcpkgVersion), - (Get-YarnVersion) -) - -$markdown += New-MDHeader "Package Management" -Level 3 -$markdown += New-MDList -Style Unordered -Lines ($packageManagementList | Sort-Object) - -$markdown += New-MDHeader "Environment variables" -Level 4 -$markdown += Build-PackageManagementEnvironmentTable | New-MDTable -$markdown += New-MDNewLine - -$markdown += New-MDHeader "Project Management" -Level 3 -$projectManagementTools = @( - (Get-AntVersion), - (Get-GradleVersion), - (Get-MavenVersion), - (Get-SbtVersion) -) - -$markdown += New-MDList -Style Unordered -Lines ($projectManagementTools | Sort-Object) - -$markdown += New-MDHeader "Tools" -Level 3 -$toolsList = @( - (Get-7zipVersion), - (Get-Aria2Version), - (Get-AzCopyVersion), - (Get-BazelVersion), - (Get-BazeliskVersion), - (Get-BicepVersion), - (Get-CabalVersion), - (Get-CMakeVersion), - (Get-CodeQLBundleVersion), - (Get-DockerVersion), - (Get-DockerComposeVersion), - (Get-DockerComposeVersionV2), - (Get-DockerWincredVersion), - (Get-GHCVersion), - (Get-GitVersion), - (Get-GitLFSVersion), - (Get-InnoSetupVersion), - (Get-JQVersion), - (Get-KindVersion), - (Get-KubectlVersion), - (Get-MercurialVersion), - (Get-MinGWVersion), - (Get-NewmanVersion), - (Get-NSISVersion), - (Get-OpenSSLVersion), - (Get-PackerVersion), - (Get-PulumiVersion), - (Get-RVersion), - (Get-ServiceFabricSDKVersion), - (Get-StackVersion), - (Get-SVNVersion), - (Get-VSWhereVersion), - (Get-SwigVersion), - (Get-WinAppDriver), - (Get-WixVersion), - (Get-ZstdVersion), - (Get-YAMLLintVersion), - (Get-ImageMagickVersion) -) +# Tools +$tools = $installedSoftware.AddHeader("Tools") +$tools.AddToolVersion("7zip", $(Get-7zipVersion)) +$tools.AddToolVersion("aria2", $(Get-Aria2Version)) +$tools.AddToolVersion("azcopy", $(Get-AzCopyVersion)) +$tools.AddToolVersion("Bazel", $(Get-BazelVersion)) +$tools.AddToolVersion("Bazelisk", $(Get-BazeliskVersion)) +$tools.AddToolVersion("Bicep", $(Get-BicepVersion)) +$tools.AddToolVersion("Cabal", $(Get-CabalVersion)) +$tools.AddToolVersion("CMake", $(Get-CMakeVersion)) +$tools.AddToolVersion("CodeQL Action Bundle", $(Get-CodeQLBundleVersion)) +$tools.AddToolVersion("Docker", $(Get-DockerVersion)) +$tools.AddToolVersion("Docker Compose v1", $(Get-DockerComposeVersion)) +$tools.AddToolVersion("Docker Compose v2", $(Get-DockerComposeVersionV2)) +$tools.AddToolVersion("Docker-wincred", $(Get-DockerWincredVersion)) +$tools.AddToolVersion("ghc", $(Get-GHCVersion)) +$tools.AddToolVersion("Git", $(Get-GitVersion)) +$tools.AddToolVersion("Git LFS", $(Get-GitLFSVersion)) if (Test-IsWin19) { - $toolsList += @( - (Get-GoogleCloudSDKVersion), - (Get-ParcelVersion) - ) + $tools.AddToolVersion("Google Cloud SDK", $(Get-GoogleCloudSDKVersion)) } -$markdown += New-MDList -Style Unordered -Lines ($toolsList | Sort-Object) - -$markdown += New-MDHeader "CLI Tools" -Level 3 -$cliTools = @( - (Get-AlibabaCLIVersion), - (Get-AWSCLIVersion), - (Get-AWSSAMVersion), - (Get-AWSSessionManagerVersion), - (Get-AzureCLIVersion), - (Get-AzureDevopsExtVersion), - (Get-GHVersion), - (Get-HubVersion) -) +$tools.AddToolVersion("ImageMagick", $(Get-ImageMagickVersion)) +$tools.AddToolVersion("InnoSetup", $(Get-InnoSetupVersion)) +$tools.AddToolVersion("jq", $(Get-JQVersion)) +$tools.AddToolVersion("Kind", $(Get-KindVersion)) +$tools.AddToolVersion("Kubectl", $(Get-KubectlVersion)) +$tools.AddToolVersion("Mercurial", $(Get-MercurialVersion)) +$tools.AddToolVersion("Mingw-w64", $(Get-MinGWVersion)) +$tools.AddToolVersion("Newman", $(Get-NewmanVersion)) +$tools.AddToolVersion("NSIS", $(Get-NSISVersion)) +$tools.AddToolVersion("OpenSSL", $(Get-OpenSSLVersion)) +$tools.AddToolVersion("Packer", $(Get-PackerVersion)) if (Test-IsWin19) { - $cliTools += @( - (Get-CloudFoundryVersion) - ) + $tools.AddToolVersion("Parcel", $(Get-ParcelVersion)) } -$markdown += New-MDList -Style Unordered -Lines ($cliTools | Sort-Object) +$tools.AddToolVersion("Pulumi", $(Get-PulumiVersion)) +$tools.AddToolVersion("R", $(Get-RVersion)) +$tools.AddToolVersion("Service Fabric SDK", $(Get-ServiceFabricSDKVersion)) +$tools.AddToolVersion("Stack", $(Get-StackVersion)) +$tools.AddToolVersion("Subversion (SVN)", $(Get-SVNVersion)) +$tools.AddToolVersion("Swig", $(Get-SwigVersion)) +$tools.AddToolVersion("VSWhere", $(Get-VSWhereVersion)) +$tools.AddToolVersion("WinAppDriver", $(Get-WinAppDriver)) +$tools.AddToolVersion("WiX Toolset", $(Get-WixVersion)) +$tools.AddToolVersion("yamllint", $(Get-YAMLLintVersion)) +$tools.AddToolVersion("zstd", $(Get-ZstdVersion)) -$markdown += New-MDHeader "Rust Tools" -Level 3 -$markdown += New-MDList -Style Unordered -Lines (@( - "Rust $(Get-RustVersion)", - "Rustup $(Get-RustupVersion)", - "Cargo $(Get-RustCargoVersion)", - "Rustdoc $(Get-RustdocVersion)" - ) | Sort-Object -) +# CLI Tools +$cliTools = $installedSoftware.AddHeader("CLI Tools") +$cliTools.AddToolVersion("Alibaba Cloud CLI", $(Get-AlibabaCLIVersion)) +$cliTools.AddToolVersion("AWS CLI", $(Get-AWSCLIVersion)) +$cliTools.AddToolVersion("AWS SAM CLI", $(Get-AWSSAMVersion)) +$cliTools.AddToolVersion("AWS Session Manager CLI", $(Get-AWSSessionManagerVersion)) +$cliTools.AddToolVersion("Azure CLI", $(Get-AzureCLIVersion)) +$cliTools.AddToolVersion("Azure DevOps CLI extension", $(Get-AzureDevopsExtVersion)) +if (Test-IsWin19) { + $cliTools.AddToolVersion("Cloud Foundry CLI", $(Get-CloudFoundryVersion)) +} +$cliTools.AddToolVersion("GitHub CLI", $(Get-GHVersion)) +$cliTools.AddToolVersion("Hub CLI", $(Get-HubVersion)) -$markdown += New-MDHeader "Packages" -Level 4 -$markdown += New-MDList -Style Unordered -Lines (@( - (Get-BindgenVersion), - (Get-CargoAuditVersion), - (Get-CargoOutdatedVersion), - (Get-CbindgenVersion), - "Rustfmt $(Get-RustfmtVersion)", - "Clippy $(Get-RustClippyVersion)" - ) | Sort-Object -) +# Rust Tools +Initialize-RustEnvironment +$rustTools = $installedSoftware.AddHeader("Rust Tools") +$rustTools.AddToolVersion("Cargo", $(Get-RustCargoVersion)) +$rustTools.AddToolVersion("Rust", $(Get-RustVersion)) +$rustTools.AddToolVersion("Rustdoc", $(Get-RustdocVersion)) +$rustTools.AddToolVersion("Rustup", $(Get-RustupVersion)) -$markdown += New-MDHeader "Browsers and Drivers" -Level 3 -$markdown += New-MDList -Style Unordered -Lines @( - (Get-BrowserVersion -Browser "chrome"), - (Get-SeleniumWebDriverVersion -Driver "chrome"), - (Get-BrowserVersion -Browser "edge"), - (Get-SeleniumWebDriverVersion -Driver "edge"), - (Get-BrowserVersion -Browser "firefox"), - (Get-SeleniumWebDriverVersion -Driver "firefox"), - (Get-SeleniumWebDriverVersion -Driver "iexplorer"), - (Get-SeleniumVersion) -) +$rustToolsPackages = $rustTools.AddHeader("Packages") +$rustToolsPackages.AddToolVersion("bindgen", $(Get-BindgenVersion)) +$rustToolsPackages.AddToolVersion("cargo-audit", $(Get-CargoAuditVersion)) +$rustToolsPackages.AddToolVersion("cargo-outdated", $(Get-CargoOutdatedVersion)) +$rustToolsPackages.AddToolVersion("cbindgen", $(Get-CbindgenVersion)) +$rustToolsPackages.AddToolVersion("Clippy", $(Get-RustClippyVersion)) +$rustToolsPackages.AddToolVersion("Rustfmt", $(Get-RustfmtVersion)) -$markdown += New-MDHeader "Environment variables" -Level 4 -$markdown += Build-BrowserWebdriversEnvironmentTable | New-MDTable -$markdown += New-MDNewLine +# Browsers and Drivers +$browsersAndWebdrivers = $installedSoftware.AddHeader("Browsers and Drivers") +$browsersAndWebdrivers.AddNodes($(Build-BrowserSection)) +$browsersAndWebdrivers.AddHeader("Environment variables").AddTable($(Build-BrowserWebdriversEnvironmentTable)) -$markdown += New-MDHeader "Java" -Level 3 -$markdown += Get-JavaVersions | New-MDTable -$markdown += New-MDNewLine +# Java +$installedSoftware.AddHeader("Java").AddTable($(Get-JavaVersions)) -$markdown += New-MDHeader "Shells" -Level 3 -$markdown += Get-ShellTarget -$markdown += New-MDNewLine +# Shells +$installedSoftware.AddHeader("Shells").AddTable($(Get-ShellTarget)) -$markdown += New-MDHeader "MSYS2" -Level 3 -$markdown += "$(Get-PacmanVersion)" | New-MDList -Style Unordered -$markdown += New-MDHeader "Notes:" -Level 5 -$reportMsys64 = @' -``` +# MSYS2 +$msys2 = $installedSoftware.AddHeader("MSYS2") +$msys2.AddToolVersion("Pacman", $(Get-PacmanVersion)) + +$notes = @' Location: C:\msys64 Note: MSYS2 is pre-installed on image but not added to PATH. -``` '@ -$markdown += New-MDParagraph -Lines $reportMsys64 +$msys2.AddHeader("Notes").AddNote($notes) +# BizTalk Server if (Test-IsWin19) { - $markdown += New-MDHeader "BizTalk Server" -Level 3 - $markdown += "$(Get-BizTalkVersion)" | New-MDList -Style Unordered + $installedSoftware.AddHeader("BizTalk Server").AddNode($(Get-BizTalkVersion)) } -$markdown += New-MDHeader "Cached Tools" -Level 3 -$markdown += (Build-CachedToolsSection) +# Cached Tools +$installedSoftware.AddHeader("Cached Tools").AddNodes($(Build-CachedToolsSection)) -$markdown += New-MDHeader "Databases" -Level 3 -$markdown += Build-DatabasesMarkdown +# Databases +$databases = $installedSoftware.AddHeader("Databases") +$databases.AddHeader("PostgreSQL").AddTable($(Get-PostgreSQLTable)) +$databases.AddHeader("MongoDB").AddTable($(Get-MongoDBTable)) -$markdown += New-MDHeader "Database tools" -Level 3 -$databaseTools = @( - (Get-AzCosmosDBEmulatorVersion), - (Get-DacFxVersion), - (Get-MySQLVersion), - (Get-SQLPSVersion), - (Get-SQLOLEDBDriverVersion) -) +# Database tools +$databaseTools = $installedSoftware.AddHeader("Database tools") +$databaseTools.AddToolVersion("Azure CosmosDb Emulator", $(Get-AzCosmosDBEmulatorVersion)) +$databaseTools.AddToolVersion("DacFx", $(Get-DacFxVersion)) +$databaseTools.AddToolVersion("MySQL", $(Get-MySQLVersion)) +$databaseTools.AddToolVersion("SQL OLEDB Driver", $(Get-SQLOLEDBDriverVersion)) +$databaseTools.AddToolVersion("SQLPS", $(Get-SQLPSVersion)) -$markdown += New-MDList -Style Unordered -Lines ($databaseTools | Sort-Object) +# Web Servers +$installedSoftware.AddHeader("Web Servers").AddTable($(Build-WebServersSection)) -$markdown += Build-WebServersSection +# Visual Studio +$vsTable = Get-VisualStudioVersion +$visualStudio = $installedSoftware.AddHeader($vsTable.Name) +$visualStudio.AddTable($vsTable) -$vs = Get-VisualStudioVersion -$markdown += New-MDHeader "$($vs.Name)" -Level 3 -$markdown += $vs | New-MDTable -$markdown += New-MDNewLine +$workloads = $visualStudio.AddHeader("Workloads, components and extensions") +$workloads.AddTable((Get-VisualStudioComponents) + (Get-VisualStudioExtensions)) -$markdown += New-MDHeader "Workloads, components and extensions:" -Level 4 -$markdown += ((Get-VisualStudioComponents) + (Get-VisualStudioExtensions)) | New-MDTable -$markdown += New-MDNewLine +$msVisualCpp = $visualStudio.AddHeader("Microsoft Visual C++") +$msVisualCpp.AddTable($(Get-VisualCPPComponents)) -$markdown += New-MDHeader "Microsoft Visual C++:" -Level 4 -$markdown += Get-VisualCPPComponents | New-MDTable -$markdown += New-MDNewLine +$visualStudio.AddToolVersionsList("Installed Windows SDKs", $(Get-WindowsSDKs).Versions, '^.+') -$markdown += New-MDHeader "Installed Windows SDKs" -Level 4 -$sdk = Get-WindowsSDKs -$markdown += New-MDNewLine -$markdown += New-MDList -Lines $sdk.Versions -Style Unordered - -$markdown += New-MDHeader ".NET Core Tools" -Level 3 -$dotnetSdk = Get-DotnetSdks -$dotnetFrameworkVersions = Get-DotnetFrameworkVersions -$dotnetTools = @( - ".NET Core SDK: $($dotnetSdk.Versions)", - ".NET Framework: $($dotnetFrameworkVersions)" -) -$dotnetTools += Get-DotnetRuntimes | ForEach-Object { - "$($_.Runtime): $($_.Versions)" +# .NET Core Tools +$netCoreTools = $installedSoftware.AddHeader(".NET Core Tools") +if (Test-IsWin19) { + # Visual Studio 2019 brings own version of .NET Core which is different from latest official version + $netCoreTools.AddToolVersionsListInline(".NET Core SDK", $(Get-DotnetSdks).Versions, '^\d+\.\d+\.\d{2}') +} else { + $netCoreTools.AddToolVersionsListInline(".NET Core SDK", $(Get-DotnetSdks).Versions, '^\d+\.\d+\.\d') } -$dotnetTools += Get-DotnetTools -$markdown += New-MDList -Style Unordered -Lines $dotnetTools - +$netCoreTools.AddToolVersionsListInline(".NET Framework", $(Get-DotnetFrameworkVersions), '^.+') +Get-DotnetRuntimes | ForEach-Object { + $netCoreTools.AddToolVersionsListInline($_.Runtime, $_.Versions, '^.+') +} +$netCoreTools.AddNodes($(Get-DotnetTools)) # PowerShell Tools -$markdown += New-MDHeader "PowerShell Tools" -Level 3 -$markdown += New-MDList -Lines (Get-PowershellCoreVersion) -Style Unordered +$psTools = $installedSoftware.AddHeader("PowerShell Tools") +$psTools.AddToolVersion("PowerShell", $(Get-PowershellCoreVersion)) -$markdown += New-MDHeader "Powershell Modules" -Level 4 -$markdown += New-MDList -Lines $(Get-PowerShellModules) -Style Unordered -$reportAzPwsh = @' -``` +$psModules = $psTools.AddHeader("Powershell Modules") +$psModules.AddNodes($(Get-PowerShellModules)) + +$azPsNotes = @' Azure PowerShell module 2.1.0 and AzureRM PowerShell module 2.1.0 are installed and are available via 'Get-Module -ListAvailable'. All other versions are saved but not installed. -``` '@ -$markdown += New-MDParagraph -Lines $reportAzPwsh +$psModules.AddNote($azPsNotes) +# Android +$android = $installedSoftware.AddHeader("Android") +$android.AddTable($(Build-AndroidTable)) -# Android section -$markdown += New-MDHeader "Android" -Level 3 -$markdown += Build-AndroidTable | New-MDTable -$markdown += New-MDNewLine -$markdown += New-MDHeader "Environment variables" -Level 4 -$markdown += Build-AndroidEnvironmentTable | New-MDTable -$markdown += New-MDNewLine +$android.AddHeader("Environment variables").AddTable($(Build-AndroidEnvironmentTable)) -# Docker images section -$cachedImages = Get-CachedDockerImagesTableData -if ($cachedImages) { - $markdown += New-MDHeader "Cached Docker images" -Level 3 - $markdown += $cachedImages | New-MDTable -} +# Cached Docker images +$installedSoftware.AddHeader("Cached Docker images").AddTable($(Get-CachedDockerImagesTableData)) -Test-BlankElement -Markdown $markdown -$markdown | Out-File -FilePath "C:\InstalledSoftware.md" +# Generate reports +$softwareReport.ToJson() | Out-File -FilePath "C:\software-report.json" -Encoding UTF8NoBOM +$softwareReport.ToMarkdown() | Out-File -FilePath "C:\software-report.md" -Encoding UTF8NoBOM diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Helpers.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Helpers.psm1 index 0e366bd14..7166911e8 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Helpers.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Helpers.psm1 @@ -1,101 +1,3 @@ -function Build-MarkdownElement -{ - <# - .SYNOPSIS - Build markdown element for cached tool. - - .DESCRIPTION - Build markdown element that contains name of tool, set of versions and additional notes. - - .PARAMETER Head - Header of cached tool markdown element - - .PARAMETER Content - Array of lines that contains required information about installed tool instances. - #> - - param - ( - [String] $Head, - [Object[]] $Content - ) - - $markdown = New-MDHeader $Head -Level 4 - $markdown += New-MDParagraph -Lines $Content -NoNewLine - - return $markdown -} - -function Get-CachedToolInstances -{ - <# - .SYNOPSIS - Returns hastable of installed cached tools. - - .DESCRIPTION - Return hastable that contains versions and architectures for 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 -} - -function New-MDNewLine { - param ( - [int] $Count = 1 - ) - $newLineSymbol = [System.Environment]::NewLine - return $newLineSymbol * $Count -} - function Get-LinkTarget { param ( [string] $inputPath @@ -115,53 +17,6 @@ function Get-PathWithLink { 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|Docker|\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 - } -} - function Take-Part { param ( [Parameter(ValueFromPipeline)] diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 index 1267428de..df5c5f6cc 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 @@ -1,7 +1,7 @@ function Get-Aria2Version { (aria2c -v | Out-String) -match "(?(\d+\.){1,}\d+)" | Out-Null $aria2Version = $Matches.Version - return "aria2 $aria2Version" + return $aria2Version } function Get-AzCosmosDBEmulatorVersion { @@ -9,37 +9,37 @@ function Get-AzCosmosDBEmulatorVersion { $installDir = $regKey.InstallLocation $exeFilePath = Join-Path $installDir 'CosmosDB.Emulator.exe' $version = (Get-Item $exeFilePath).VersionInfo.FileVersion - return "Azure CosmosDb Emulator $version" + return $version } function Get-BazelVersion { ((cmd /c "bazel --version 2>&1") | Out-String) -match "bazel (?\d+\.\d+\.\d+)" | Out-Null $bazelVersion = $Matches.Version - return "Bazel $bazelVersion" + return $bazelVersion } function Get-BazeliskVersion { ((cmd /c "bazelisk version 2>&1") | Out-String) -match "Bazelisk version: v(?\d+\.\d+\.\d+)" | Out-Null $bazeliskVersion = $Matches.Version - return "Bazelisk $bazeliskVersion" + return $bazeliskVersion } function Get-BicepVersion { (bicep --version | Out-String) -match "bicep cli version (?\d+\.\d+\.\d+)" | Out-Null $bicepVersion = $Matches.Version - return "Bicep $bicepVersion" + return $bicepVersion } function Get-RVersion { ($(cmd /c "Rscript --version 2>&1") | Out-String) -match "Rscript .* version (?\d+\.\d+\.\d+)" | Out-Null $rVersion = $Matches.Version - return "R $rVersion" + return $rVersion } function Get-CMakeVersion { ($(cmake -version) | Out-String) -match "cmake version (?\d+\.\d+\.\d+)" | Out-Null $cmakeVersion = $Matches.Version - return "CMake $cmakeVersion" + return $cmakeVersion } function Get-CodeQLBundleVersion { @@ -47,99 +47,100 @@ function Get-CodeQLBundleVersion { $CodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Select-Object -First 1 -Expand FullName $CodeQLPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe" $CodeQLVersion = & $CodeQLPath version --quiet - return "CodeQL Action Bundle $CodeQLVersion" + return $CodeQLVersion } function Get-DockerVersion { $dockerVersion = $(docker version --format "{{.Server.Version}}") - return "Docker $dockerVersion" + return $dockerVersion } function Get-DockerComposeVersion { $dockerComposeVersion = docker-compose version --short - return "Docker Compose v1 $dockerComposeVersion" + return $dockerComposeVersion } function Get-DockerComposeVersionV2 { $dockerComposeVersion = docker compose version --short - return "Docker Compose v2 $dockerComposeVersion" + return $dockerComposeVersion } function Get-DockerWincredVersion { $dockerCredVersion = docker-credential-wincred version | Take-Part -Part 2 | Take-Part -Part 0 -Delimiter "v" - return "Docker-wincred $dockerCredVersion" + return $dockerCredVersion } function Get-GitVersion { $gitVersion = git --version | Take-Part -Part -1 - return "Git $gitVersion" + return $gitVersion } function Get-GitLFSVersion { $(git-lfs version) -match "git-lfs\/(?\d+\.\d+\.\d+)" | Out-Null $gitLfsVersion = $Matches.Version - return "Git LFS $gitLfsVersion" + return $gitLfsVersion } function Get-InnoSetupVersion { - return $(choco list --local-only innosetup) | Select-String -Pattern "InnoSetup" + $innoSetupVersion = $(choco list --local-only innosetup) | Select-String -Pattern "InnoSetup" + return ($innoSetupVersion -replace "^InnoSetup").Trim() } function Get-JQVersion { $jqVersion = ($(jq --version) -Split "jq-")[1] - return "jq $jqVersion" + return $jqVersion } function Get-KubectlVersion { $kubectlVersion = (kubectl version --client --output=json | ConvertFrom-Json).clientVersion.gitVersion.Replace('v','') - return "Kubectl $kubectlVersion" + return $kubectlVersion } function Get-KindVersion { $(kind version) -match "kind v(?\d+\.\d+\.\d+)" | Out-Null $kindVersion = $Matches.Version - return "Kind $kindVersion" + return $kindVersion } function Get-MinGWVersion { (gcc --version | Select-String -Pattern "MinGW-W64") -match "(?\d+\.\d+\.\d+)" | Out-Null $mingwVersion = $Matches.Version - return "Mingw-w64 $mingwVersion" + return $mingwVersion } function Get-MySQLVersion { $mysqlCommand = Get-Command -Name "mysql" $mysqlVersion = $mysqlCommand.Version.ToString() - return "MySQL $mysqlVersion" + return $mysqlVersion } function Get-SQLOLEDBDriverVersion { $SQLOLEDBDriverVersion = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSOLEDBSQL' InstalledVersion).InstalledVersion - return "SQL OLEDB Driver $SQLOLEDBDriverVersion" + return $SQLOLEDBDriverVersion } function Get-MercurialVersion { ($(hg --version) | Out-String) -match "version (?\d+\.\d+\.?\d*)" | Out-Null $mercurialVersion = $Matches.Version - return "Mercurial $mercurialVersion" + return $mercurialVersion } function Get-NSISVersion { $nsisVersion = &"c:\Program Files (x86)\NSIS\makensis.exe" "/Version" - return "NSIS $($nsisVersion.TrimStart('v'))" + return $nsisVersion.TrimStart("v") } function Get-OpenSSLVersion { $(openssl version) -match "OpenSSL (?\d+\.\d+\.\d+\w?) " | Out-Null $opensslVersion = $Matches.Version - return "OpenSSL $opensslVersion" + return $opensslVersion } function Get-PackerVersion { # Packer 1.7.1 has a bug and outputs version to stderr instead of stdout https://github.com/hashicorp/packer/issues/10855 ($(cmd /c "packer --version 2>&1") | Out-String) -match "(?(\d+.){2}\d+)" | Out-Null $packerVersion = $Matches.Version - return "Packer $packerVersion" + return $packerVersion } function Get-ParcelVersion { @@ -148,133 +149,133 @@ function Get-ParcelVersion { } function Get-PulumiVersion { - $pulumiVersion = $(pulumi version) - return "Pulumi $($pulumiVersion.TrimStart('v'))" + return (pulumi version).TrimStart("v") } function Get-SQLPSVersion { $module = Get-Module -Name SQLPS -ListAvailable $version = $module.Version - return "SQLPS $version" + return $version } function Get-SVNVersion { $svnVersion = $(svn --version --quiet) - return "Subversion (SVN) $svnVersion" + return $svnVersion } function Get-VSWhereVersion { ($(Get-Command -Name vswhere).FileVersionInfo.ProductVersion) -match "(?\d+\.\d+\.\d+)" | Out-Null $vswhereVersion = $Matches.Version - return "VSWhere $vswhereVersion" + return $vswhereVersion } function Get-WinAppDriver { $winAppDriverVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe").FileVersion - return "WinAppDriver $winAppDriverVersion" + return $winAppDriverVersion } function Get-WixVersion { $regKey = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" $installedApplications = Get-ItemProperty -Path $regKey - return ($installedApplications | Where-Object { $_.BundleCachePath -imatch ".*\\WiX\d*\.exe$" } | Select-Object -First 1).DisplayName + $wixToolsetVersion = ($installedApplications | Where-Object { $_.BundleCachePath -imatch ".*\\WiX\d*\.exe$" } | Select-Object -First 1).DisplayName + return ($wixToolsetVersion -replace "^WiX Toolset v").Trim() } function Get-ZstdVersion { $(zstd --version) -match "v(?\d+\.\d+\.\d+)" | Out-Null $zstdVersion = $Matches.Version - return "zstd $zstdVersion" + return $zstdVersion } function Get-AzureCLIVersion { $azureCLIVersion = $(az version) | ConvertFrom-Json | Foreach{ $_."azure-cli" } - return "Azure CLI $azureCLIVersion" + return $azureCLIVersion } function Get-AzCopyVersion { - return ($(azcopy --version) -replace "version ") + return ($(azcopy --version) -replace "^azcopy version").Trim() } function Get-AzureDevopsExtVersion { $azureDevExtVersion = (az version | ConvertFrom-Json | ForEach-Object { $_."extensions" })."azure-devops" - return "Azure DevOps CLI extension $azureDevExtVersion" + return $azureDevExtVersion } function Get-AWSCLIVersion { $(aws --version) -match "aws-cli\/(?\d+\.\d+\.\d+)" | Out-Null $awscliVersion = $Matches.Version - return "AWS CLI $awscliVersion" + return $awscliVersion } function Get-AWSSAMVersion { $(sam --version) -match "version (?\d+\.\d+\.\d+)" | Out-Null $awssamVersion = $Matches.Version - return "AWS SAM CLI $awssamVersion" + return $awssamVersion } function Get-AWSSessionManagerVersion { $awsSessionManagerVersion = $(session-manager-plugin --version) - return "AWS Session Manager CLI $awsSessionManagerVersion" + return $awsSessionManagerVersion } function Get-AlibabaCLIVersion { $alicliVersion = $(aliyun version) - return "Alibaba Cloud CLI $alicliVersion" + return $alicliVersion } function Get-CloudFoundryVersion { $(cf version) -match "(?\d+\.\d+\.\d+)" | Out-Null $cfVersion = $Matches.Version - return "Cloud Foundry CLI $cfVersion" + return $cfVersion } function Get-HubVersion { ($(hub version) | Select-String -Pattern "hub version") -match "hub version (?\d+\.\d+\.\d+)" | Out-Null $hubVersion = $Matches.Version - return "Hub CLI $hubVersion" + return $hubVersion } function Get-7zipVersion { (7z | Out-String) -match "7-Zip (?\d+\.\d+\.?\d*)" | Out-Null $version = $Matches.Version - return "7zip $version" + return $version } function Get-GHCVersion { ((ghc --version) | Out-String) -match "version (?\d+\.\d+\.\d+)" | Out-Null $ghcVersion = $Matches.Version - return "ghc $ghcVersion" + return $ghcVersion } function Get-CabalVersion { ((cabal --version) | Out-String) -match "version (?\d+\.\d+\.\d+\.\d+)" | Out-Null $cabalVersion = $Matches.Version - return "Cabal $cabalVersion" + return $cabalVersion } function Get-StackVersion { ((stack --version --quiet) | Out-String) -match "Version (?\d+\.\d+\.\d+)," | Out-Null $stackVersion = $Matches.Version - return "Stack $stackVersion" + return $stackVersion } function Get-GoogleCloudSDKVersion { - (cmd /c "gcloud --version") -match "Google Cloud SDK" + return (((cmd /c "gcloud --version") -match "Google Cloud SDK") -replace "Google Cloud SDK").Trim() } function Get-ServiceFabricSDKVersion { $serviceFabricSDKVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Service Fabric\' -Name FabricVersion - return "Service Fabric SDK $serviceFabricSDKVersion" + return $serviceFabricSDKVersion } function Get-NewmanVersion { - return "Newman $(newman --version)" + return $(newman --version) } function Get-GHVersion { ($(gh --version) | Select-String -Pattern "gh version") -match "gh version (?\d+\.\d+\.\d+)" | Out-Null $ghVersion = $Matches.Version - return "GitHub CLI $ghVersion" + return $ghVersion } function Get-VisualCPPComponents { @@ -300,17 +301,17 @@ function Get-VisualCPPComponents { function Get-DacFxVersion { $dacfxversion = & "$env:ProgramFiles\Microsoft SQL Server\160\DAC\bin\sqlpackage.exe" /version - return "DacFx $dacfxversion" + return $dacfxversion } function Get-SwigVersion { (swig -version | Out-String) -match "version (?\d+\.\d+\.\d+)" | Out-Null $swigVersion = $Matches.Version - return "Swig $swigVersion" + return $swigVersion } function Get-ImageMagickVersion { (magick -version | Select-String -Pattern "Version") -match "(?\d+\.\d+\.\d+-\d+)" | Out-Null $magickVersion = $Matches.Version - return "ImageMagick $magickVersion" + return $magickVersion } diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 index 17f1f9890..1f77829ab 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 @@ -18,7 +18,7 @@ function Get-NginxVersion { return $Matches.Version } -function Get-ApacheMarkdown +function Get-ApacheSection { $name = "Apache" $apachePort = "80" @@ -35,7 +35,7 @@ function Get-ApacheMarkdown } } -function Get-NginxMarkdown +function Get-NginxSection { $name = "Nginx" $nginxPort = "80" @@ -53,13 +53,8 @@ function Get-NginxMarkdown } function Build-WebServersSection { - $output = "" - $output += New-MDHeader "Web Servers" -Level 3 - $output += @( - (Get-ApacheMarkdown), - (Get-NginxMarkdown) - ) | Sort-Object Name | New-MDTable - - $output += New-MDNewLine - return $output + return @( + (Get-ApacheSection), + (Get-NginxSection) + ) } \ No newline at end of file diff --git a/images/win/windows2019.json b/images/win/windows2019.json index c66c0a214..55eaeedb9 100644 --- a/images/win/windows2019.json +++ b/images/win/windows2019.json @@ -82,6 +82,11 @@ "source": "{{ template_dir }}/scripts/SoftwareReport", "destination": "{{user `image_folder`}}" }, + { + "type": "file", + "source": "{{ template_dir }}/../../helpers/software-report-base", + "destination": "{{user `image_folder`}}/SoftwareReport/" + }, { "type": "file", "source": "{{ template_dir }}/post-generation", @@ -299,15 +304,22 @@ { "type": "powershell", "inline": [ - "if (-not (Test-Path C:\\InstalledSoftware.md)) { throw 'C:\\InstalledSoftware.md not found' }" + "if (-not (Test-Path C:\\software-report.md)) { throw 'C:\\software-report.md not found' }", + "if (-not (Test-Path C:\\software-report.json)) { throw 'C:\\software-report.json not found' }" ] }, { "type": "file", - "source": "C:\\InstalledSoftware.md", + "source": "C:\\software-report.md", "destination": "{{ template_dir }}/Windows2019-Readme.md", "direction": "download" }, + { + "type": "file", + "source": "C:\\software-report.json", + "destination": "{{ template_dir }}/software-report.json", + "direction": "download" + }, { "type": "powershell", "skip_clean": true, diff --git a/images/win/windows2022.json b/images/win/windows2022.json index 1ee985842..c4dc8f646 100644 --- a/images/win/windows2022.json +++ b/images/win/windows2022.json @@ -82,6 +82,11 @@ "source": "{{ template_dir }}/scripts/SoftwareReport", "destination": "{{user `image_folder`}}" }, + { + "type": "file", + "source": "{{ template_dir }}/../../helpers/software-report-base", + "destination": "{{user `image_folder`}}/SoftwareReport/" + }, { "type": "file", "source": "{{ template_dir }}/post-generation", @@ -302,15 +307,22 @@ { "type": "powershell", "inline": [ - "if (-not (Test-Path C:\\InstalledSoftware.md)) { throw 'C:\\InstalledSoftware.md not found' }" + "if (-not (Test-Path C:\\software-report.md)) { throw 'C:\\software-report.md not found' }", + "if (-not (Test-Path C:\\software-report.json)) { throw 'C:\\software-report.json not found' }" ] }, { "type": "file", - "source": "C:\\InstalledSoftware.md", + "source": "C:\\software-report.md", "destination": "{{ template_dir }}/Windows2022-Readme.md", "direction": "download" }, + { + "type": "file", + "source": "C:\\software-report.json", + "destination": "{{ template_dir }}/software-report.json", + "direction": "download" + }, { "type": "powershell", "skip_clean": true,