diff --git a/images/macos/helpers/Common.Helpers.psm1 b/images/macos/helpers/Common.Helpers.psm1 index 86bc32470..457793276 100644 --- a/images/macos/helpers/Common.Helpers.psm1 +++ b/images/macos/helpers/Common.Helpers.psm1 @@ -156,3 +156,13 @@ function Add-EnvironmentVariable { function isVeertu { return (Test-Path -Path "/Library/Application Support/Veertu") } + +function Get-Architecture { + $arch = arch + if ($arch -ne "arm64") + { + $arch = "x64" + } + + return $arch +} diff --git a/images/macos/provision/core/configure-toolset.ps1 b/images/macos/provision/core/configure-toolset.ps1 index d569eee69..8450b820d 100644 --- a/images/macos/provision/core/configure-toolset.ps1 +++ b/images/macos/provision/core/configure-toolset.ps1 @@ -22,23 +22,23 @@ function Get-ToolsetToolFullPath return $installationDir } +$arch = Get-Architecture $toolcache = Get-ToolsetValue "toolcache" foreach ($tool in $toolcache) { $toolName = $tool.name - $toolArch = $tool.arch - $toolEnvironment = $tool.variable_template + $toolEnvironment = $tool.arch.$arch.variable_template if (-not $toolEnvironment) { continue } - foreach ($toolVersion in $tool.versions) + foreach ($toolVersion in $tool.arch.$arch.versions) { Write-Host "Set $toolName $toolVersion environment variable..." - $toolPath = Get-ToolsetToolFullPath -ToolName $toolName -ToolVersion $toolVersion -ToolArchitecture $toolArch + $toolPath = Get-ToolsetToolFullPath -ToolName $toolName -ToolVersion $toolVersion -ToolArchitecture $arch $envName = $toolEnvironment -f $toolVersion.split(".") # Add environment variable name=value diff --git a/images/macos/provision/core/pypy.sh b/images/macos/provision/core/pypy.sh index eab316845..95d060a62 100644 --- a/images/macos/provision/core/pypy.sh +++ b/images/macos/provision/core/pypy.sh @@ -75,8 +75,9 @@ function InstallPyPy rm -f $PACKAGE_TAR_TEMP_PATH } +arch=$(get_arch) pypyVersions=$(curl https://downloads.python.org/pypy/versions.json) -toolsetVersions=$(get_toolset_value '.toolcache[] | select(.name | contains("PyPy")) | .versions[]') +toolsetVersions=$(get_toolset_value '.toolcache[] | select(.name | contains("PyPy")) | .arch.'$arch'.versions[]') for toolsetVersion in $toolsetVersions; do latestMajorPyPyVersion=$(echo $pypyVersions | diff --git a/images/macos/provision/core/ruby.sh b/images/macos/provision/core/ruby.sh index 62fb937db..104e4c95d 100755 --- a/images/macos/provision/core/ruby.sh +++ b/images/macos/provision/core/ruby.sh @@ -23,7 +23,7 @@ if ! is_VenturaArm64; then echo "Install Ruby from toolset..." [ -n "$API_PAT" ] && authString=(-H "Authorization: token ${API_PAT}") PACKAGE_TAR_NAMES=$(curl "${authString[@]}" -s "https://api.github.com/repos/ruby/ruby-builder/releases/latest" | jq -r '.assets[].name') - TOOLSET_VERSIONS=$(get_toolset_value '.toolcache[] | select(.name | contains("Ruby")) | .versions[]') + TOOLSET_VERSIONS=$(get_toolset_value '.toolcache[] | select(.name | contains("Ruby")) | .arch.'$arch'.versions[]') RUBY_PATH="$AGENT_TOOLSDIRECTORY/Ruby" echo "Check if Ruby hostedtoolcache folder exists..." diff --git a/images/macos/provision/core/toolset.ps1 b/images/macos/provision/core/toolset.ps1 index e2c4efe8f..8d6869327 100644 --- a/images/macos/provision/core/toolset.ps1 +++ b/images/macos/provision/core/toolset.ps1 @@ -28,6 +28,8 @@ Function Install-Asset { Pop-Location } +$arch = Get-Architecture + # Get toolcache content from toolset $toolsToInstall = @("Python", "Node", "Go") $tools = Get-ToolsetValue "toolcache" | Where-Object {$toolsToInstall -contains $_.Name} @@ -37,10 +39,10 @@ foreach ($tool in $tools) { $assets = Invoke-RestMethodWithRetry -Url $tool.url # Get github release asset for each version - foreach ($version in $tool.versions) { + foreach ($version in $tool.arch.$arch.versions) { $asset = $assets | Where-Object version -like $version ` | Select-Object -ExpandProperty files ` - | Where-Object { ($_.platform -eq $tool.platform) -and ($_.arch -eq $tool.arch) -and ($_.platform_version -eq $tool.platform_version)} ` + | Where-Object { ($_.platform -eq $tool.platform) -and ($_.arch -eq $arch)} ` | Select-Object -First 1 Write-Host "Installing $($tool.name) $version..." diff --git a/images/macos/templates/macOS-13.arm64.anka.pkr.hcl b/images/macos/templates/macOS-13.arm64.anka.pkr.hcl index 562e6d311..ace69c5ad 100644 --- a/images/macos/templates/macOS-13.arm64.anka.pkr.hcl +++ b/images/macos/templates/macOS-13.arm64.anka.pkr.hcl @@ -206,6 +206,13 @@ build { ] execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} {{ .Path }}" } + provisioner "shell" { + scripts = [ + "./provision/core/toolset.ps1", + "./provision/core/configure-toolset.ps1" + ] + execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} pwsh -f {{ .Path }}" + } provisioner "shell" { script = "./provision/core/delete-duplicate-sims.rb" execute_command = "source $HOME/.bash_profile; ruby {{ .Path }}" diff --git a/images/macos/tests/Toolcache.Tests.ps1 b/images/macos/tests/Toolcache.Tests.ps1 index ee2b0fe8f..30c58953b 100644 --- a/images/macos/tests/Toolcache.Tests.ps1 +++ b/images/macos/tests/Toolcache.Tests.ps1 @@ -1,6 +1,7 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" -DisableNameChecking +$arch = Get-Architecture $os = Get-OSVersion Describe "Toolcache" { @@ -8,12 +9,12 @@ Describe "Toolcache" { [array]$packages += Get-ToolsetValue -KeyPath "toolcache" | ForEach-Object { return [PSCustomObject] @{ ToolName = ($_.name).ToLower() - Arch = $_.arch - Versions = $_.versions | ForEach-Object { $_.Replace(".*", "") } + Arch = $arch + Versions = $_.arch.$arch | Where-Object{ $_ } | ForEach-Object { $_.versions.Replace(".*", "") } } } - Context "Python" -Skip:($os.IsVenturaArm64) { + Context "Python" { $pythonDirectory = Join-Path $toolcacheDirectory "Python" $pythonPackage = $packages | Where-Object { $_.ToolName -eq "python" } | Select-Object -First 1 $testCase = @{ PythonDirectory = $pythonDirectory } @@ -142,7 +143,7 @@ Describe "Toolcache" { } } - Context "Node" -Skip:($os.IsVenturaArm64) { + Context "Node" { $nodeDirectory = Join-Path $toolcacheDirectory "node" $nodePackage = $packages | Where-Object { $_.ToolName -eq "node" } | Select-Object -First 1 $testCase = @{ NodeDirectory = $nodeDirectory } @@ -192,7 +193,7 @@ Describe "Toolcache" { } } - Context "Go" -Skip:($os.IsVenturaArm64) { + Context "Go" { $goDirectory = Join-Path $toolcacheDirectory "go" $goPackage = $packages | Where-Object { $_.ToolName -eq "go" } | Select-Object -First 1 $testCase = @{ GoDirectory = $goDirectory } diff --git a/images/macos/toolsets/toolset-11.json b/images/macos/toolsets/toolset-11.json index 9e575c9e2..e796aeee0 100644 --- a/images/macos/toolsets/toolset-11.json +++ b/images/macos/toolsets/toolset-11.json @@ -245,61 +245,76 @@ { "name": "Python", "url" : "https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json", - "arch": "x64", "platform" : "darwin", - "versions": [ - "3.7.*", - "3.8.*", - "3.9.*", - "3.10.*", - "3.11.*" - ] + "arch": { + "x64": { + "versions": [ + "3.7.*", + "3.8.*", + "3.9.*", + "3.10.*", + "3.11.*" + ] + } + } }, { "name": "PyPy", - "arch": "x64", "platform" : "darwin", - "versions": [ - "2.7", - "3.7", - "3.8", - "3.9" - ] + "arch": { + "x64": { + "versions": [ + "2.7", + "3.7", + "3.8", + "3.9" + ] + } + } }, { "name": "Node", "url" : "https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json", "platform" : "darwin", - "arch": "x64", - "versions": [ - "14.*", - "16.*", - "18.*" - ] + "arch": { + "x64": { + "versions": [ + "14.*", + "16.*", + "18.*" + ] + } + } }, { "name": "Go", "url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json", - "arch": "x64", "platform" : "darwin", - "variable_template" : "GOROOT_{0}_{1}_X64", - "versions": [ - "1.18.*", - "1.19.*", - "1.20.*" - ] + "arch": { + "x64": { + "variable_template" : "GOROOT_{0}_{1}_X64", + "versions": [ + "1.18.*", + "1.19.*", + "1.20.*" + ] + } + } }, { "name": "Ruby", - "arch": "x64", - "versions": [ - "2.4.*", - "2.5.*", - "2.6.*", - "2.7.*", - "3.0.*", - "3.1.*" - ] + "arch": { + "x64": { + "versions": [ + "2.4.*", + "2.5.*", + "2.6.*", + "2.7.*", + "3.0.*", + "3.1.*" + ] + } + } } ], "pipx": [ diff --git a/images/macos/toolsets/toolset-12.json b/images/macos/toolsets/toolset-12.json index 24215e4eb..d2e669dad 100644 --- a/images/macos/toolsets/toolset-12.json +++ b/images/macos/toolsets/toolset-12.json @@ -231,58 +231,73 @@ { "name": "Python", "url" : "https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json", - "arch": "x64", "platform" : "darwin", - "versions": [ - "3.7.*", - "3.8.*", - "3.9.*", - "3.10.*", - "3.11.*" - ] + "arch": { + "x64": { + "versions": [ + "3.7.*", + "3.8.*", + "3.9.*", + "3.10.*", + "3.11.*" + ] + } + } }, { "name": "PyPy", - "arch": "x64", "platform" : "darwin", - "versions": [ - "2.7", - "3.7", - "3.8", - "3.9" - ] + "arch": { + "x64": { + "versions": [ + "2.7", + "3.7", + "3.8", + "3.9" + ] + } + } }, { "name": "Node", "url" : "https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json", "platform" : "darwin", - "arch": "x64", - "versions": [ - "14.*", - "16.*", - "18.*" - ] + "arch": { + "x64": { + "versions": [ + "14.*", + "16.*", + "18.*" + ] + } + } }, { "name": "Go", "url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json", - "arch": "x64", "platform" : "darwin", - "variable_template" : "GOROOT_{0}_{1}_X64", - "versions": [ - "1.18.*", - "1.19.*", - "1.20.*" - ] + "arch": { + "x64": { + "variable_template" : "GOROOT_{0}_{1}_X64", + "versions": [ + "1.18.*", + "1.19.*", + "1.20.*" + ] + } + } }, { "name": "Ruby", - "arch": "x64", - "versions": [ - "2.7.*", - "3.0.*", - "3.1.*" - ] + "arch": { + "x64": { + "versions": [ + "2.7.*", + "3.0.*", + "3.1.*" + ] + } + } } ], "pipx": [ diff --git a/images/macos/toolsets/toolset-13.json b/images/macos/toolsets/toolset-13.json index 70a94302f..763953f40 100644 --- a/images/macos/toolsets/toolset-13.json +++ b/images/macos/toolsets/toolset-13.json @@ -121,54 +121,88 @@ { "name": "Python", "url" : "https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json", - "arch": "x64", "platform" : "darwin", - "versions": [ - "3.8.*", - "3.9.*", - "3.10.*", - "3.11.*" - ] + "arch": { + "x64": { + "versions": [ + "3.8.*", + "3.9.*", + "3.10.*", + "3.11.*" + ] + }, + "arm64": { + "versions": [ + "3.10.*", + "3.11.*" + ] + } + } }, { "name": "PyPy", - "arch": "x64", "platform" : "darwin", - "versions": [ - "2.7", - "3.7", - "3.8", - "3.9" - ] + "arch": { + "x64": { + "versions": [ + "2.7", + "3.7", + "3.8", + "3.9" + ] + } + } }, { "name": "Node", "url" : "https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json", "platform" : "darwin", - "arch": "x64", - "versions": [ - "16.*", - "18.*" - ] + "arch": { + "x64": { + "versions": [ + "16.*", + "18.*" + ] + }, + "arm64": { + "versions": [ + "16.*", + "18.*" + ] + } + } }, { "name": "Go", "url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json", - "arch": "x64", "platform" : "darwin", - "variable_template" : "GOROOT_{0}_{1}_X64", - "versions": [ - "1.19.*", - "1.20.*" - ] + "arch": { + "x64": { + "variable_template" : "GOROOT_{0}_{1}_X64", + "versions": [ + "1.19.*", + "1.20.*" + ] + }, + "arm64": { + "variable_template" : "GOROOT_{0}_{1}_ARM64", + "versions": [ + "1.19.*", + "1.20.*" + ] + } + } }, { "name": "Ruby", - "arch": "x64", - "versions": [ - "3.0.*", - "3.1.*" - ] + "arch": { + "x64": { + "versions": [ + "3.0.*", + "3.1.*" + ] + } + } } ], "go": {