2020-04-30 18:11:40 +03:00
|
|
|
################################################################################
|
|
|
|
|
## File: Validate-Toolset.ps1
|
|
|
|
|
## Team: CI-Build
|
|
|
|
|
## Desc: Validate Toolset
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
function Run-ExecutableTests {
|
|
|
|
|
param (
|
|
|
|
|
[Parameter(Mandatory)] [string[]] $Executables,
|
|
|
|
|
[Parameter(Mandatory)] [string] $ToolPath
|
|
|
|
|
)
|
2020-06-19 13:47:55 +03:00
|
|
|
$versionCommand = $Executables["command"]
|
|
|
|
|
foreach ($executable in $Executables["tools"]) {
|
2020-04-30 18:11:40 +03:00
|
|
|
$executablePath = Join-Path $ToolPath $executable
|
|
|
|
|
|
|
|
|
|
Write-Host "Check $executable..."
|
|
|
|
|
if (Test-Path $executablePath) {
|
2020-06-19 13:47:55 +03:00
|
|
|
Write-Host "$executable is successfully installed: $(& $executablePath $versionCommand)"
|
2020-04-30 18:11:40 +03:00
|
|
|
} else {
|
|
|
|
|
Write-Host "$executablePath is not installed!"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Validate-SystemDefaultTool {
|
|
|
|
|
param (
|
|
|
|
|
[Parameter(Mandatory)] [string] $ToolName,
|
|
|
|
|
[Parameter(Mandatory)] [string] $ExpectedVersion
|
|
|
|
|
)
|
|
|
|
|
|
2020-06-19 13:47:55 +03:00
|
|
|
$versionCommand = $toolsExecutables[$ToolName]["command"]
|
2020-04-30 18:11:40 +03:00
|
|
|
$binName = $ToolName.ToLower()
|
|
|
|
|
|
|
|
|
|
# Check if tool on path
|
|
|
|
|
if (Get-Command -Name $binName) {
|
2020-06-19 13:47:55 +03:00
|
|
|
$versionOnPath = $(& $binName $versionCommand 2>&1) | Select-String -Pattern ".*(\d+\.\d+[\.\d+]+)"
|
2020-04-30 18:11:40 +03:00
|
|
|
|
|
|
|
|
# Check if version is correct
|
|
|
|
|
if ($versionOnPath.matches.Groups[1].Value -notlike $ExpectedVersion) {
|
|
|
|
|
Write-Error "$ToolName $ExpectedVersion is not in the PATH"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-Host "$ToolName $versionOnPath on path"
|
|
|
|
|
} else {
|
|
|
|
|
Write-Host "$ToolName is not on path"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
|
|
# Define executables for cached tools
|
2020-05-08 11:14:27 +00:00
|
|
|
$toolsExecutables = @{
|
2020-06-19 13:47:55 +03:00
|
|
|
Python = @{
|
|
|
|
|
tools = @("python.exe", "Scripts\pip.exe")
|
|
|
|
|
command = "--version"
|
|
|
|
|
}
|
|
|
|
|
node = @{
|
|
|
|
|
tools = @("node.exe", "npm")
|
|
|
|
|
command = "--version"
|
|
|
|
|
}
|
|
|
|
|
PyPy = @{
|
|
|
|
|
tools = @("python.exe", "Scripts\pip.exe")
|
|
|
|
|
command = "--version"
|
|
|
|
|
}
|
|
|
|
|
go = @{
|
|
|
|
|
tools = @("bin\go.exe")
|
|
|
|
|
command = "version"
|
|
|
|
|
}
|
2020-05-08 11:14:27 +00:00
|
|
|
}
|
2020-04-30 18:11:40 +03:00
|
|
|
|
|
|
|
|
# Get toolcache content from toolset
|
|
|
|
|
$tools = Get-ToolsetContent | Select-Object -ExpandProperty toolcache
|
|
|
|
|
|
|
|
|
|
foreach($tool in $tools) {
|
|
|
|
|
# Get executables for current tool
|
|
|
|
|
$toolExecs = $toolsExecutables[$tool.name]
|
|
|
|
|
|
|
|
|
|
foreach ($version in $tool.versions) {
|
2020-06-30 07:48:55 +03:00
|
|
|
$foundVersionArchPath = Get-ToolsetToolFullPath -Name $tool.name -Version $version -Arch $tool.arch
|
2020-04-30 18:11:40 +03:00
|
|
|
|
2020-06-10 19:42:15 +03:00
|
|
|
if ($toolExecs) {
|
|
|
|
|
Write-Host "Run validation test for $($tool.name)($($tool.arch)) $($foundVersion.name) executables..."
|
|
|
|
|
Run-ExecutableTests -Executables $toolExecs -ToolPath $foundVersionArchPath
|
|
|
|
|
}
|
2020-04-30 18:11:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (-not ([string]::IsNullOrEmpty($tool.default))) {
|
|
|
|
|
Write-Host "Validate system default $($tool.name)($($tool.arch)) $($tool.default)..."
|
2020-06-02 20:07:12 +03:00
|
|
|
Validate-SystemDefaultTool -ToolName $tool.name -ExpectedVersion $tool.default
|
2020-04-30 18:11:40 +03:00
|
|
|
}
|
|
|
|
|
}
|