mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-24 10:28:10 +08:00
[Windows] Apply code style rules to Windows scripts (#8957)
* Apply code style rules to Windows scripts * Fix typo * Fix configure-toolset script * Fix parameters in Msys2 installation script * Improve log readability * Remove broken exit code validation
This commit is contained in:
committed by
GitHub
parent
76d6f0f574
commit
7fe65a2204
@@ -4,60 +4,37 @@
|
||||
## Desc: Configure Toolset
|
||||
################################################################################
|
||||
|
||||
Function Set-DefaultVariables
|
||||
{
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[object] $EnvVars,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $ToolVersionPath
|
||||
)
|
||||
|
||||
$templates = $EnvVars.pathTemplates
|
||||
foreach ($template in $templates)
|
||||
{
|
||||
$toolSystemPath = $template -f $ToolVersionPath
|
||||
Add-MachinePathItem -PathItem $toolSystemPath | Out-Null
|
||||
}
|
||||
|
||||
if (-not ([string]::IsNullOrEmpty($EnvVars.defaultVariable)))
|
||||
{
|
||||
[Environment]::SetEnvironmentVariable($toolEnvVars.defaultVariable, $ToolVersionPath, "Machine")
|
||||
}
|
||||
}
|
||||
|
||||
# Define executables for cached tools
|
||||
$toolsEnvironmentVariables = @{
|
||||
$toolEnvConfigs = @{
|
||||
Python = @{
|
||||
pathTemplates = @(
|
||||
"{0}",
|
||||
"{0}"
|
||||
"{0}\Scripts"
|
||||
)
|
||||
}
|
||||
go = @{
|
||||
pathTemplates = @(
|
||||
go = @{
|
||||
pathTemplates = @(
|
||||
"{0}\bin"
|
||||
)
|
||||
variableTemplate = "GOROOT_{0}_{1}_X64"
|
||||
envVarTemplate = "GOROOT_{0}_{1}_X64"
|
||||
}
|
||||
}
|
||||
|
||||
$toolsToConfigure = @("Python", "Go")
|
||||
$tools = Get-ToolsetContent | Select-Object -ExpandProperty toolcache `
|
||||
| Where-Object { $toolsToConfigure -contains $_.name }
|
||||
$tools = Get-ToolsetContent `
|
||||
| Select-Object -ExpandProperty toolcache `
|
||||
| Where-Object { $toolEnvConfigs.Keys -contains $_.name }
|
||||
|
||||
Write-Host "Configure toolset tools environment..."
|
||||
foreach ($tool in $tools) {
|
||||
$toolEnvVars = $toolsEnvironmentVariables[$tool.name]
|
||||
|
||||
if (-not ([string]::IsNullOrEmpty($toolEnvVars.variableTemplate))) {
|
||||
$toolEnvConfig = $toolEnvConfigs[$tool.name]
|
||||
|
||||
if (-not ([string]::IsNullOrEmpty($toolEnvConfig.envVarTemplate))) {
|
||||
foreach ($version in $tool.versions) {
|
||||
Write-Host "Set $($tool.name) $version environment variable..."
|
||||
|
||||
$foundVersionArchPath = Get-TCToolVersionPath -Name $tool.name -Version $version -Arch $tool.arch
|
||||
$envName = $toolEnvVars.variableTemplate -f $version.Split(".")
|
||||
$envName = $toolEnvConfig.envVarTemplate -f $version.Split(".")
|
||||
|
||||
Write-Host "Set $envName to $foundVersionArchPath"
|
||||
[Environment]::SetEnvironmentVariable($envName, $foundVersionArchPath, "Machine")
|
||||
}
|
||||
}
|
||||
@@ -67,7 +44,16 @@ foreach ($tool in $tools) {
|
||||
|
||||
$toolVersionPath = Get-TCToolVersionPath -Name $tool.name -Version $tool.default -Arch $tool.arch
|
||||
|
||||
Set-DefaultVariables -ToolVersionPath $toolVersionPath -EnvVars $toolEnvVars
|
||||
foreach ($template in $toolEnvConfig.pathTemplates) {
|
||||
$toolSystemPath = $template -f $toolVersionPath
|
||||
Write-Host "Add $toolSystemPath to system PATH..."
|
||||
Add-MachinePathItem -PathItem $toolSystemPath | Out-Null
|
||||
}
|
||||
|
||||
if (-not ([string]::IsNullOrEmpty($tool.defaultVariable))) {
|
||||
Write-Host "Set $($tool.name) $($tool.default) $($tool.defaultVariable) environment variable..."
|
||||
[Environment]::SetEnvironmentVariable($tool.defaultVariable, $toolVersionPath, "Machine")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user