mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 22:26:56 +00:00
[macOS] Add GOROOT env variables (#4220)
This commit is contained in:
@@ -104,8 +104,7 @@ function Invoke-ValidateCommand {
|
||||
return $output
|
||||
}
|
||||
|
||||
function Start-DownloadWithRetry
|
||||
{
|
||||
function Start-DownloadWithRetry {
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -147,4 +146,16 @@ function Start-DownloadWithRetry
|
||||
}
|
||||
|
||||
return $filePath
|
||||
}
|
||||
}
|
||||
|
||||
function Add-EnvironmentVariable {
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory)] [string] $Name,
|
||||
[Parameter(Mandatory)] [string] $Value,
|
||||
[string] $FilePath = "${env:HOME}/.bashrc"
|
||||
)
|
||||
|
||||
$envVar = "export {0}={1}" -f $Name, $Value
|
||||
Add-Content -Path $FilePath -Value $envVar
|
||||
}
|
||||
|
||||
@@ -59,4 +59,62 @@ function Get-BrewPackageVersion {
|
||||
$packageVersion = $Matches.Version
|
||||
|
||||
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
|
||||
}
|
||||
47
images/macos/provision/core/configure-toolset.ps1
Normal file
47
images/macos/provision/core/configure-toolset.ps1
Normal file
@@ -0,0 +1,47 @@
|
||||
################################################################################
|
||||
## File: Configure-Toolset.ps1
|
||||
## Team: CI-Build
|
||||
## Desc: Configure toolset
|
||||
################################################################################
|
||||
|
||||
Import-Module "~/image-generation/helpers/Common.Helpers.psm1"
|
||||
|
||||
function Get-ToolsetToolFullPath
|
||||
{
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory)] [string] $ToolName,
|
||||
[Parameter(Mandatory)] [string] $ToolVersion,
|
||||
[Parameter(Mandatory)] [string] $ToolArchitecture
|
||||
)
|
||||
|
||||
$toolPath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath $toolName
|
||||
$toolPathVersion = Join-Path -Path $toolPath -ChildPath $toolVersion
|
||||
$foundVersion = Get-Item $toolPathVersion | Sort-Object -Property {[version]$_.name} -Descending | Select-Object -First 1
|
||||
$installationDir = Join-Path -Path $foundVersion -ChildPath $toolArchitecture
|
||||
return $installationDir
|
||||
}
|
||||
|
||||
$toolcache = Get-ToolsetValue "toolcache"
|
||||
|
||||
foreach ($tool in $toolcache)
|
||||
{
|
||||
$toolName = $tool.name
|
||||
$toolArch = $tool.arch
|
||||
$toolEnvironment = $tool.variable_template
|
||||
|
||||
if (-not $toolEnvironment)
|
||||
{
|
||||
continue
|
||||
}
|
||||
|
||||
foreach ($toolVersion in $tool.versions)
|
||||
{
|
||||
Write-Host "Set $toolName $toolVersion environment variable..."
|
||||
$toolPath = Get-ToolsetToolFullPath -ToolName $toolName -ToolVersion $toolVersion -ToolArchitecture $toolArch
|
||||
$envName = $toolEnvironment -f $toolVersion.split(".")
|
||||
|
||||
# Add environment variable name=value
|
||||
Add-EnvironmentVariable -Name $envName -Value $toolPath
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,6 @@
|
||||
Import-Module "~/image-generation/helpers/Tests.Helpers.psm1"
|
||||
Import-Module "~/image-generation/helpers/Common.Helpers.psm1"
|
||||
|
||||
Function Get-ToolcacheFromToolset {
|
||||
$toolsetPath = Join-Path $env:HOME "image-generation" "toolset.json"
|
||||
$toolsetJson = Get-Content -Raw $toolsetPath | ConvertFrom-Json
|
||||
return $toolsetJson.toolcache
|
||||
}
|
||||
|
||||
Function Install-Asset {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
@@ -36,7 +30,7 @@ Function Install-Asset {
|
||||
|
||||
# Get toolcache content from toolset
|
||||
$toolsToInstall = @("Python", "Node", "Go")
|
||||
$tools = Get-ToolcacheFromToolset | Where-Object {$ToolsToInstall -contains $_.Name}
|
||||
$tools = Get-ToolsetValue "toolcache" | Where-Object {$toolsToInstall -contains $_.Name}
|
||||
|
||||
foreach ($tool in $tools) {
|
||||
# Get versions manifest for current tool
|
||||
|
||||
@@ -28,9 +28,20 @@ function Get-ToolcacheNodeVersions {
|
||||
return Get-ChildItem $toolcachePath -Name | Sort-Object { [Version]$_ }
|
||||
}
|
||||
|
||||
function Get-ToolcacheGoVersions {
|
||||
$toolcachePath = Join-Path $env:HOME "hostedtoolcache" "Go"
|
||||
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 | New-MDTable -Columns ([ordered]@{
|
||||
Version = "left";
|
||||
Architecture = "left";
|
||||
"Environment Variable" = "left"
|
||||
})
|
||||
|
||||
return $Content
|
||||
}
|
||||
|
||||
function Build-ToolcacheSection {
|
||||
@@ -47,7 +58,7 @@ function Build-ToolcacheSection {
|
||||
$output += New-MDHeader "Node.js" -Level 4
|
||||
$output += New-MDList -Lines (Get-ToolcacheNodeVersions) -Style Unordered
|
||||
$output += New-MDHeader "Go" -Level 4
|
||||
$output += New-MDList -Lines (Get-ToolcacheGoVersions) -Style Unordered
|
||||
$output += Get-ToolcacheGoTable
|
||||
}
|
||||
|
||||
return $output
|
||||
|
||||
@@ -192,7 +192,10 @@
|
||||
{
|
||||
"type": "shell",
|
||||
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}",
|
||||
"scripts": "./provision/core/toolset.ps1"
|
||||
"scripts": [
|
||||
"./provision/core/toolset.ps1",
|
||||
"./provision/core/configure-toolset.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
|
||||
@@ -195,7 +195,10 @@
|
||||
{
|
||||
"type": "shell",
|
||||
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}",
|
||||
"scripts": "./provision/core/toolset.ps1"
|
||||
"scripts": [
|
||||
"./provision/core/toolset.ps1",
|
||||
"./provision/core/configure-toolset.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
|
||||
@@ -198,7 +198,10 @@
|
||||
{
|
||||
"type": "shell",
|
||||
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}",
|
||||
"scripts": "./provision/core/toolset.ps1"
|
||||
"scripts": [
|
||||
"./provision/core/toolset.ps1",
|
||||
"./provision/core/configure-toolset.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
|
||||
@@ -193,7 +193,10 @@
|
||||
{
|
||||
"type": "shell",
|
||||
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}",
|
||||
"scripts": "./provision/core/toolset.ps1"
|
||||
"scripts": [
|
||||
"./provision/core/toolset.ps1",
|
||||
"./provision/core/configure-toolset.ps1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
|
||||
@@ -331,6 +331,7 @@
|
||||
"url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json",
|
||||
"arch": "x64",
|
||||
"platform" : "darwin",
|
||||
"variable_template" : "GOROOT_{0}_{1}_X64",
|
||||
"versions": [
|
||||
"1.13.*",
|
||||
"1.14.*",
|
||||
|
||||
@@ -283,6 +283,7 @@
|
||||
"url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json",
|
||||
"arch": "x64",
|
||||
"platform" : "darwin",
|
||||
"variable_template" : "GOROOT_{0}_{1}_X64",
|
||||
"versions": [
|
||||
"1.13.*",
|
||||
"1.14.*",
|
||||
|
||||
@@ -227,6 +227,7 @@
|
||||
"url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json",
|
||||
"arch": "x64",
|
||||
"platform" : "darwin",
|
||||
"variable_template" : "GOROOT_{0}_{1}_X64",
|
||||
"versions": [
|
||||
"1.15.*",
|
||||
"1.16.*",
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
"url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json",
|
||||
"arch": "x64",
|
||||
"platform" : "darwin",
|
||||
"variable_template" : "GOROOT_{0}_{1}_X64",
|
||||
"versions": [
|
||||
"1.15.*",
|
||||
"1.16.*",
|
||||
|
||||
Reference in New Issue
Block a user