feature: initial commit for all new image changes
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
function Get-CommandResult {
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $Command,
|
||||
[switch] $Multiline
|
||||
)
|
||||
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
|
||||
$stdout = & bash -c "$Command 2>&1"
|
||||
$exitCode = $LASTEXITCODE
|
||||
|
||||
return @{
|
||||
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout }
|
||||
ExitCode = $exitCode
|
||||
}
|
||||
}
|
||||
|
||||
# Gets path to the tool, analogue of 'which tool'
|
||||
function Get-ToolPath($tool) {
|
||||
return (Get-Command $tool).Path
|
||||
}
|
||||
|
||||
# Returns the object with information about current OS
|
||||
# It can be used for OS-specific tests
|
||||
function Get-OSVersion {
|
||||
$osVersion = [Environment]::OSVersion
|
||||
$processorArchitecture = arch
|
||||
|
||||
return [PSCustomObject]@{
|
||||
Version = $osVersion.Version
|
||||
Platform = $osVersion.Platform
|
||||
IsArm64 = $processorArchitecture -eq "arm64"
|
||||
IsMonterey = $osVersion.Version.Major -eq "12"
|
||||
IsVentura = $($osVersion.Version.Major -eq "13")
|
||||
IsVenturaArm64 = $($osVersion.Version.Major -eq "13" -and $processorArchitecture -eq "arm64")
|
||||
IsVenturaX64 = $($osVersion.Version.Major -eq "13" -and $processorArchitecture -ne "arm64")
|
||||
IsSonoma = $($osVersion.Version.Major -eq "14")
|
||||
IsSonomaArm64 = $($osVersion.Version.Major -eq "14" -and $processorArchitecture -eq "arm64")
|
||||
IsSonomaX64 = $($osVersion.Version.Major -eq "14" -and $processorArchitecture -ne "arm64")
|
||||
IsSequoia = $($osVersion.Version.Major -eq "15")
|
||||
IsSequoiaArm64 = $($osVersion.Version.Major -eq "15" -and $processorArchitecture -eq "arm64")
|
||||
IsSequoiaX64 = $($osVersion.Version.Major -eq "15" -and $processorArchitecture -ne "arm64")
|
||||
}
|
||||
}
|
||||
|
||||
function Get-ToolsetContent {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Retrieves the content of the toolset.json file.
|
||||
|
||||
.DESCRIPTION
|
||||
This function reads the toolset.json in path provided by IMAGE_FOLDER
|
||||
environment variable and returns the content as a PowerShell object.
|
||||
#>
|
||||
|
||||
$toolsetPath = Join-Path $env:IMAGE_FOLDER "toolset.json"
|
||||
$toolsetJson = Get-Content -Path $toolsetPath -Raw
|
||||
ConvertFrom-Json -InputObject $toolsetJson
|
||||
}
|
||||
|
||||
function Invoke-DownloadWithRetry {
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Url,
|
||||
[Alias("Destination")]
|
||||
[string] $Path
|
||||
)
|
||||
|
||||
if (-not $Path) {
|
||||
$invalidChars = [IO.Path]::GetInvalidFileNameChars() -join ''
|
||||
$re = "[{0}]" -f [RegEx]::Escape($invalidChars)
|
||||
$fileName = [IO.Path]::GetFileName($Url) -replace $re
|
||||
|
||||
if ([String]::IsNullOrEmpty($fileName)) {
|
||||
$fileName = [System.IO.Path]::GetRandomFileName()
|
||||
}
|
||||
$Path = Join-Path -Path "/tmp" -ChildPath $fileName
|
||||
}
|
||||
|
||||
Write-Host "Downloading package from $Url to $Path..."
|
||||
|
||||
$interval = 30
|
||||
$downloadStartTime = Get-Date
|
||||
for ($retries = 20; $retries -gt 0; $retries--) {
|
||||
try {
|
||||
$attemptStartTime = Get-Date
|
||||
(New-Object System.Net.WebClient).DownloadFile($Url, $Path)
|
||||
$attemptSeconds = [math]::Round(($(Get-Date) - $attemptStartTime).TotalSeconds, 2)
|
||||
Write-Host "Package downloaded in $attemptSeconds seconds"
|
||||
break
|
||||
} catch {
|
||||
$attemptSeconds = [math]::Round(($(Get-Date) - $attemptStartTime).TotalSeconds, 2)
|
||||
Write-Warning "Package download failed in $attemptSeconds seconds"
|
||||
Write-Warning $_.Exception.Message
|
||||
}
|
||||
|
||||
if ($retries -eq 0) {
|
||||
$totalSeconds = [math]::Round(($(Get-Date) - $downloadStartTime).TotalSeconds, 2)
|
||||
throw "Package download failed after $totalSeconds seconds"
|
||||
}
|
||||
|
||||
Write-Warning "Waiting $interval seconds before retrying (retries left: $retries)..."
|
||||
Start-Sleep -Seconds $interval
|
||||
}
|
||||
|
||||
return $Path
|
||||
}
|
||||
|
||||
function Get-Architecture {
|
||||
$arch = arch
|
||||
if ($arch -ne "arm64") {
|
||||
$arch = "x64"
|
||||
}
|
||||
|
||||
return $arch
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
function Get-XcodeRootPath {
|
||||
Param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
return "/Applications/Xcode_$Version.app"
|
||||
}
|
||||
|
||||
function Get-DefaultXcodeRootPath {
|
||||
return (Get-Item -Path "/Applications/Xcode.app").Target
|
||||
}
|
||||
|
||||
function Get-XcodeToolPath {
|
||||
param (
|
||||
[Parameter(ParameterSetName = 'Version')]
|
||||
[string] $Version,
|
||||
[Parameter(ParameterSetName = 'Path')]
|
||||
[string] $XcodeRootPath,
|
||||
[string] $ToolName
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ParameterSetName -eq "Version") {
|
||||
$XcodeRootPath = Get-XcodeRootPath $Version
|
||||
}
|
||||
|
||||
return Join-Path $XcodeRootPath "Contents/Developer/usr/bin" $ToolName
|
||||
}
|
||||
|
||||
function Get-XcodeVersionInfo {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $XcodeRootPath
|
||||
)
|
||||
|
||||
$xcodebuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild"
|
||||
[string]$output = Invoke-Expression "$xcodebuildPath -version"
|
||||
$versionOutputParts = $output.Split(" ")
|
||||
|
||||
return @{
|
||||
Version = [System.Version]::Parse($versionOutputParts[1])
|
||||
Build = $versionOutputParts[4]
|
||||
}
|
||||
}
|
||||
|
||||
function Switch-Xcode {
|
||||
param (
|
||||
[Parameter(ParameterSetName = 'Version')]
|
||||
[string] $Version,
|
||||
[Parameter(ParameterSetName = 'Path')]
|
||||
[string] $XcodeRootPath
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ParameterSetName -eq "Version") {
|
||||
$XcodeRootPath = Get-XcodeRootPath $Version
|
||||
}
|
||||
|
||||
Write-Verbose "Switching Xcode to '${XcodeRootPath}'"
|
||||
Invoke-Expression "sudo xcode-select --switch ${XcodeRootPath}"
|
||||
}
|
||||
|
||||
function Test-XcodeStableRelease {
|
||||
param (
|
||||
[Parameter(ParameterSetName = 'Version')]
|
||||
[string] $Version,
|
||||
[Parameter(ParameterSetName = 'Path')]
|
||||
[string] $XcodeRootPath
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ParameterSetName -eq "Version") {
|
||||
$XcodeRootPath = Get-XcodeRootPath $Version
|
||||
}
|
||||
|
||||
$licenseInfoPlistPath = Join-Path $XcodeRootPath "Contents" "Resources" "LicenseInfo.plist"
|
||||
$releaseType = & defaults read $licenseInfoPlistPath "licenseType"
|
||||
|
||||
return -not ($releaseType -match "beta")
|
||||
}
|
||||
|
||||
function Get-XcodeSimulatorsInfo {
|
||||
param (
|
||||
[string] $Filter
|
||||
)
|
||||
|
||||
[string]$rawSimulatorsInfo = Invoke-Expression "xcrun simctl list --json"
|
||||
$jsonSimulatorsInfo = $rawSimulatorsInfo | ConvertFrom-Json
|
||||
|
||||
if ($Filter) {
|
||||
return $jsonSimulatorsInfo | Select-Object -ExpandProperty $Filter
|
||||
}
|
||||
|
||||
return $jsonSimulatorsInfo
|
||||
}
|
||||
|
||||
function Get-XcodeDevicesList {
|
||||
$result = @()
|
||||
|
||||
$runtimes = Get-XcodeSimulatorsInfo -Filter "devices"
|
||||
$runtimes.PSObject.Properties | ForEach-Object {
|
||||
$runtimeName = $_.Name
|
||||
$devices = $_.Value
|
||||
$devices | Where-Object {
|
||||
$availability = $_.availability
|
||||
$isAvailable = $_.isAvailable
|
||||
return (($availability -eq "(available)") -or ($isAvailable -eq "YES") -or ($isAvailable -eq $true))
|
||||
} | ForEach-Object {
|
||||
$deviceName = $_.name
|
||||
$result += "$runtimeName $deviceName"
|
||||
}
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
function Get-XcodePairsList {
|
||||
$result = @()
|
||||
|
||||
$runtimes = Get-XcodeSimulatorsInfo -Filter "pairs"
|
||||
$runtimes.PSObject.Properties | Where-Object {
|
||||
return $_.Value.state -match "active"
|
||||
} | ForEach-Object {
|
||||
$watchName = $_.Value.watch.name
|
||||
$phoneName = $_.Value.phone.name
|
||||
$result += "$watchName $phoneName"
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
#Helper function for execution of xcversion due to: https://github.com/fastlane/fastlane/issues/18161
|
||||
function Invoke-XCVersion {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Arguments,
|
||||
[Parameter()]
|
||||
[int] $RetryAttempts = 7,
|
||||
[Parameter()]
|
||||
[int] $PauseDurationSecs = 1
|
||||
)
|
||||
|
||||
$Command = "xcversion $Arguments"
|
||||
Write-Host "Execute [$Command]"
|
||||
for ($Attempt=1; $Attempt -le $RetryAttempts; $Attempt++) {
|
||||
Write-Host "Current attempt: [$Attempt]"
|
||||
$result = Get-CommandResult -Command $Command -Multiline
|
||||
Write-Host "Exit code: [$($result.ExitCode)]"
|
||||
Write-Host "Output message: "
|
||||
$result.Output | ForEach-Object { Write-Host $_ }
|
||||
if ($result.ExitCode -ne 0) {
|
||||
Start-Sleep -Seconds $PauseDurationSecs
|
||||
} else {
|
||||
return $result.Output
|
||||
}
|
||||
}
|
||||
if ($result.ExitCode -ne 0) {
|
||||
throw "Command [$Command] has finished with non-zero exit code."
|
||||
}
|
||||
}
|
||||
|
||||
function Get-BrokenXcodeSimulatorsList {
|
||||
return @(
|
||||
# tvOS Simulators
|
||||
@{
|
||||
SimulatorName = "Apple TV 4K (at 1080p) (2nd generation)"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-2nd-generation-1080p";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.tvOS-15-0";
|
||||
XcodeVersion = "13.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple TV 4K (at 1080p) (2nd generation)"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-2nd-generation-1080p";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.tvOS-15-2";
|
||||
XcodeVersion = "13.2.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple TV 4K (at 1080p) (2nd generation)"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-2nd-generation-1080p";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.tvOS-15-4";
|
||||
XcodeVersion = "13.4.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple TV 4K (at 1080p) (2nd generation)"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-2nd-generation-1080p";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.tvOS-16-0";
|
||||
XcodeVersion = "14.2"
|
||||
},
|
||||
# watchOS-8-0 Simulators
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 5 - 40mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-40mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-0";
|
||||
XcodeVersion = "13.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 5 - 44mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-44mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-0";
|
||||
XcodeVersion = "13.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 6 - 40mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-6-40mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-0";
|
||||
XcodeVersion = "13.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 6 - 44mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-6-44mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-0";
|
||||
XcodeVersion = "13.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 7 - 41mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-7-41mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-0";
|
||||
XcodeVersion = "13.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 7 - 45mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-7-45mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-0";
|
||||
XcodeVersion = "13.1"
|
||||
},
|
||||
# watchOS-8-3 Simulators
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 5 - 40mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-40mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-3";
|
||||
XcodeVersion = "13.2.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 5 - 44mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-44mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-3";
|
||||
XcodeVersion = "13.2.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 6 - 40mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-6-40mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-3";
|
||||
XcodeVersion = "13.2.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 6 - 44mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-6-44mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-3";
|
||||
XcodeVersion = "13.2.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 7 - 41mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-7-41mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-3";
|
||||
XcodeVersion = "13.2.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 7 - 45mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-7-45mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-3";
|
||||
XcodeVersion = "13.2.1"
|
||||
},
|
||||
# watchOS-8-5 Simulators
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 5 - 40mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-40mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-5";
|
||||
XcodeVersion = "13.4.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 5 - 44mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-44mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-5";
|
||||
XcodeVersion = "13.4.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 6 - 40mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-6-40mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-5";
|
||||
XcodeVersion = "13.4.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 6 - 44mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-6-44mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-5";
|
||||
XcodeVersion = "13.4.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 7 - 41mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-7-41mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-5";
|
||||
XcodeVersion = "13.4.1"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch Series 7 - 45mm"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-7-45mm";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-8-5";
|
||||
XcodeVersion = "13.4.1"
|
||||
},
|
||||
# watchOS-9-0 Simulators
|
||||
@{
|
||||
SimulatorName = "Apple Watch SE (40mm) (2nd generation)"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-SE-40mm-2nd-generation";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-9-0";
|
||||
XcodeVersion = "14.2"
|
||||
},
|
||||
@{
|
||||
SimulatorName = "Apple Watch SE (44mm) (2nd generation)"
|
||||
DeviceId = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-SE-44mm-2nd-generation";
|
||||
RuntimeId = "com.apple.CoreSimulator.SimRuntime.watchOS-9-0";
|
||||
XcodeVersion = "14.2"
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
Import-Module "$PSScriptRoot/Common.Helpers.psm1"
|
||||
Import-Module "$PSScriptRoot/Xcode.Helpers.psm1"
|
||||
|
||||
function Install-XcodeVersion {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version,
|
||||
[Parameter(Mandatory)]
|
||||
[string] $LinkTo,
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Sha256Sum
|
||||
)
|
||||
|
||||
$xcodeDownloadDirectory = "$env:HOME/Library/Caches/XcodeInstall"
|
||||
$xcodeTargetPath = Get-XcodeRootPath -Version $LinkTo
|
||||
$xcodeXipDirectory = Invoke-DownloadXcodeArchive -DownloadDirectory $xcodeDownloadDirectory -Version $Version
|
||||
Expand-XcodeXipArchive -DownloadDirectory $xcodeXipDirectory.FullName -TargetPath $xcodeTargetPath
|
||||
Remove-Item -Path $xcodeXipDirectory -Force -Recurse
|
||||
}
|
||||
|
||||
function Invoke-DownloadXcodeArchive {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $DownloadDirectory,
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
Write-Host "Downloading Xcode $Version"
|
||||
$tempXipDirectory = New-Item -Path $DownloadDirectory -Name "Xcode$Version" -ItemType "Directory"
|
||||
$xcodeFileName = 'Xcode-{0}.xip' -f $Version
|
||||
$xcodeUri = '{0}{1}?{2}'-f ${env:XCODE_INSTALL_STORAGE_URL}, $xcodeFileName, ${env:XCODE_INSTALL_SAS}
|
||||
$xcodeFullPath = Join-Path $tempXipDirectory.FullName $xcodeFileName
|
||||
Invoke-DownloadWithRetry -Url $xcodeUri -Path $xcodeFullPath | Out-Null
|
||||
|
||||
# Validating checksum
|
||||
$xcodeSha256 = Get-FileHash -Path $xcodeFullPath -Algorithm SHA256 | Select-Object -ExpandProperty Hash
|
||||
if ($xcodeSha256 -ne $Sha256Sum) {
|
||||
throw "Xcode $Version checksum mismatch. Expected: $Sha256Sum, Actual: $xcodeSha256"
|
||||
}
|
||||
|
||||
return $tempXipDirectory
|
||||
}
|
||||
|
||||
function Resolve-ExactXcodeVersion {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
# if toolset string contains spaces, consider it as a full name of Xcode
|
||||
if ($Version -match "\s") {
|
||||
return $Version
|
||||
}
|
||||
|
||||
$semverVersion = [SemVer]::Parse($Version)
|
||||
$availableVersions = Get-AvailableXcodeVersions
|
||||
$satisfiedVersions = $availableVersions | Where-Object { $semverVersion -eq $_.stableSemver }
|
||||
|
||||
return $satisfiedVersions | Select-Object -Last 1 -ExpandProperty rawVersion
|
||||
}
|
||||
|
||||
function Get-AvailableXcodeVersions {
|
||||
$rawVersionsList = Invoke-XCVersion -Arguments "list" | ForEach-Object { $_.Trim() } | Where-Object { $_ -match "^\d" }
|
||||
$availableVersions = $rawVersionsList | ForEach-Object {
|
||||
$partStable,$partMajor = $_.Split(" ", 2)
|
||||
$semver = $stableSemver = [SemVer]::Parse($partStable)
|
||||
|
||||
if ($partMajor) {
|
||||
# Convert 'beta 3' -> 'beta.3', 'Release Candidate' -> 'releasecandidate', 'GM Seed 2' -> 'gmseed.2'
|
||||
$normalizedLabel = $partMajor.toLower() -replace " (\d)", '.$1' -replace " ([a-z])", '$1'
|
||||
$semver = [SemVer]::new($stableSemver.Major, $stableSemver.Minor, $stableSemver.Patch, $normalizedLabel)
|
||||
}
|
||||
|
||||
return [PSCustomObject]@{
|
||||
semver = $semver
|
||||
rawVersion = $_
|
||||
stableSemver = $stableSemver
|
||||
}
|
||||
}
|
||||
|
||||
return $availableVersions | Sort-Object -Property semver
|
||||
}
|
||||
|
||||
function Expand-XcodeXipArchive {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $DownloadDirectory,
|
||||
[Parameter(Mandatory)]
|
||||
[string] $TargetPath
|
||||
)
|
||||
|
||||
$xcodeXipPath = Get-ChildItem -Path $DownloadDirectory -Filter "Xcode-*.xip" | Select-Object -First 1
|
||||
|
||||
Write-Host "Extracting Xcode from '$xcodeXipPath'"
|
||||
Push-Location $DownloadDirectory
|
||||
if ([boolean] (Get-Command 'unxip' -ErrorAction 'SilentlyContinue')) {
|
||||
Invoke-ValidateCommand "unxip $xcodeXipPath"
|
||||
} else {
|
||||
Invoke-ValidateCommand "xip -x $xcodeXipPath"
|
||||
}
|
||||
Pop-Location
|
||||
|
||||
if (Test-Path "$DownloadDirectory/Xcode-beta.app") {
|
||||
Write-Host "Renaming Xcode-beta.app to Xcode.app"
|
||||
Rename-Item -Path "$DownloadDirectory/Xcode-beta.app" -NewName "Xcode.app"
|
||||
}
|
||||
|
||||
if (-not (Test-Path "$DownloadDirectory/Xcode.app")) {
|
||||
throw "XIP archive '$xcodeXipPath' doesn't contain 'Xcode.app'"
|
||||
}
|
||||
|
||||
Write-Host "Moving '$DownloadDirectory/Xcode.app' to '$TargetPath'"
|
||||
Move-Item -Path "$DownloadDirectory/Xcode.app" -Destination $TargetPath
|
||||
}
|
||||
|
||||
function Confirm-XcodeIntegrity {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
$XcodeRootPath = Get-XcodeRootPath -Version $Version
|
||||
if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) {
|
||||
Write-Host "Validating Xcode integrity for '$XcodeRootPath'..."
|
||||
Invoke-ValidateCommand "spctl --assess --raw $XcodeRootPath"
|
||||
}
|
||||
}
|
||||
|
||||
function Approve-XcodeLicense {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
$os = Get-OSVersion
|
||||
$XcodeRootPath = Get-XcodeRootPath -Version $Version
|
||||
Write-Host "Approving Xcode license for '$XcodeRootPath'..."
|
||||
$xcodeBuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild"
|
||||
|
||||
if ($os.IsVentura -or $os.IsSonoma) {
|
||||
Invoke-ValidateCommand -Command "sudo $xcodeBuildPath -license accept" -Timeout 15
|
||||
} else {
|
||||
Invoke-ValidateCommand -Command "sudo $xcodeBuildPath -license accept"
|
||||
}
|
||||
}
|
||||
|
||||
function Install-XcodeAdditionalPackages {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
Write-Host "Installing additional packages for Xcode $Version..."
|
||||
$xcodeRootPath = Get-XcodeRootPath -Version $Version
|
||||
$packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -File
|
||||
$packages | ForEach-Object {
|
||||
Invoke-ValidateCommand "sudo installer -pkg $($_.FullName) -target / -allowUntrusted"
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-XcodeRunFirstLaunch {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
if ($Version.StartsWith("8") -or $Version.StartsWith("9")) {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "Running 'runFirstLaunch' for Xcode $Version..."
|
||||
$xcodeRootPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild"
|
||||
Invoke-ValidateCommand "sudo $xcodeRootPath -runFirstLaunch"
|
||||
}
|
||||
|
||||
function Install-AdditionalSimulatorRuntimes {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
Write-Host "Installing Simulator Runtimes for Xcode $Version ..."
|
||||
$xcodebuildPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild"
|
||||
Invoke-ValidateCommand "$xcodebuildPath -downloadAllPlatforms" | Out-Null
|
||||
}
|
||||
|
||||
function Build-XcodeSymlinks {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version,
|
||||
[string[]] $Symlinks
|
||||
)
|
||||
|
||||
$sourcePath = Get-XcodeRootPath -Version $Version
|
||||
$Symlinks | Where-Object { $_ } | ForEach-Object {
|
||||
$targetPath = Get-XcodeRootPath -Version $_
|
||||
Write-Host "Creating symlink: '$targetPath' -> '$sourcePath'"
|
||||
New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
function Initialize-XcodeLaunchServicesDb {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
$xcodePath = Get-XcodeRootPath -Version $Version
|
||||
$lsregister = '/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister'
|
||||
Get-ChildItem -Recurse -Filter "*.app" $xcodePath | Foreach-Object { & $lsregister -f $_.FullName}
|
||||
}
|
||||
|
||||
function Build-ProvisionatorSymlink {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Version
|
||||
)
|
||||
|
||||
$sourcePath = Get-XcodeRootPath -Version $Version
|
||||
$versionInfo = Get-XcodeVersionInfo -XcodeRootPath $sourcePath
|
||||
|
||||
$targetVersion = [SemVer]::Parse($versionInfo.Version).ToString()
|
||||
$targetPath = Get-XcodeRootPath -Version $targetVersion
|
||||
if ($sourcePath -ne $targetPath) {
|
||||
Write-Host "Creating symlink: '$targetPath' -> '$sourcePath'"
|
||||
New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
function Set-XcodeDeveloperDirEnvironmentVariables {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string[]] $XcodeList
|
||||
)
|
||||
|
||||
$exactVersionsList = $XcodeList | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object {
|
||||
$xcodeRootPath = Get-XcodeRootPath -Version $_
|
||||
$xcodeVersionInfo = Get-XcodeVersionInfo -XcodeRootPath $xcodeRootPath
|
||||
return @{
|
||||
RootPath = $xcodeRootPath
|
||||
Version = [SemVer]::Parse($xcodeVersionInfo.Version)
|
||||
}
|
||||
} | Sort-Object -Property Version -Descending
|
||||
|
||||
$majorVersions = $exactVersionsList.Version.Major | Select-Object -Unique
|
||||
$majorVersions | ForEach-Object {
|
||||
$majorVersion = $_
|
||||
$latestXcodeVersion = $exactVersionsList | Where-Object { $_.Version.Major -eq $majorVersion } | Select-Object -First 1
|
||||
$variableName = "XCODE_${_}_DEVELOPER_DIR"
|
||||
$variableValue = "$($latestXcodeVersion.RootPath)/Contents/Developer"
|
||||
Write-Host "Set ${variableName}=${variableValue}"
|
||||
"export ${variableName}=${variableValue}" | Out-File "$env:HOME/.bashrc" -Append
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-ValidateCommand {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string] $Command,
|
||||
[Uint] $Timeout = 0
|
||||
)
|
||||
|
||||
if ($Timeout -eq 0) {
|
||||
$output = Invoke-Expression -Command $Command
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Command '$Command' has finished with exit code $LASTEXITCODE"
|
||||
}
|
||||
return $output
|
||||
} else {
|
||||
$job = $command | Start-Job -ScriptBlock {
|
||||
$output = Invoke-Expression -Command $input
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw 'Command failed'
|
||||
}
|
||||
return $output
|
||||
}
|
||||
$waitObject = $job | Wait-Job -Timeout $Timeout
|
||||
|
||||
if (-not $waitObject) {
|
||||
throw "Command '$Command' has timed out"
|
||||
}
|
||||
|
||||
if ($waitObject.State -eq 'Failed') {
|
||||
throw "Command '$Command' has failed"
|
||||
}
|
||||
Receive-Job -Job $job
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# This AppleScript clicks "Allow" for "System Software from developer "Parallels International GmbH"
|
||||
# Steps:
|
||||
# - Open System Settings -> Privacy & Security
|
||||
# - Click 'Allow' for 'System Software from developer "Parallels International GmbH'
|
||||
# - Enter password for runner
|
||||
|
||||
on run argv
|
||||
set userpassword to item 1 of argv
|
||||
|
||||
tell application "System Settings"
|
||||
activate
|
||||
delay 5
|
||||
end tell
|
||||
|
||||
tell application "System Events"
|
||||
tell process "System Settings"
|
||||
set frontmost to true
|
||||
repeat until exists window 1
|
||||
delay 2
|
||||
end repeat
|
||||
|
||||
tell splitter group 1 of group 1 of window 1
|
||||
select row 20 of outline 1 of scroll area 1 of group 1
|
||||
delay 5
|
||||
click UI Element 2 of group 4 of scroll area 1 of group 1 of group 2
|
||||
delay 5
|
||||
keystroke userpassword
|
||||
delay 5
|
||||
keystroke return
|
||||
delay 5
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end run
|
||||
@@ -0,0 +1,34 @@
|
||||
# This AppleScript clicks "Allow" for "System Software from developer "Parallels International GmbH"
|
||||
# Steps:
|
||||
# - Open System Settings -> Privacy & Security
|
||||
# - Click 'Allow' for 'System Software from developer "Parallels International GmbH'
|
||||
# - Enter password for runner
|
||||
|
||||
on run argv
|
||||
set userpassword to item 1 of argv
|
||||
|
||||
tell application "System Settings"
|
||||
activate
|
||||
delay 5
|
||||
end tell
|
||||
|
||||
tell application "System Events"
|
||||
tell process "System Settings"
|
||||
set frontmost to true
|
||||
repeat until exists window 1
|
||||
delay 2
|
||||
end repeat
|
||||
|
||||
tell splitter group 1 of group 1 of window 1
|
||||
select row 18 of outline 1 of scroll area 1 of group 1
|
||||
delay 5
|
||||
click UI Element 2 of group 5 of scroll area 1 of group 1 of group 2
|
||||
delay 5
|
||||
keystroke userpassword
|
||||
delay 5
|
||||
keystroke return
|
||||
delay 5
|
||||
end tell
|
||||
end tell
|
||||
end tell
|
||||
end run
|
||||
@@ -0,0 +1,49 @@
|
||||
# This AppleScript confirms developers in security preferences via macOS UI.
|
||||
# It uses after VirtualBox installation to add 'Oracle Inc' as identified developer.
|
||||
# Steps:
|
||||
# - Close security preferences pop-up (it can be open after VirtualBox installation)
|
||||
# - Open System Preferences -> Security & Privacy -> General
|
||||
# - Unlock security preferences with user password (button 'Click the lock to make changes')
|
||||
# - Click 'Allow' or 'Details…' button to confirm developers
|
||||
# - Click 'Not now' button on restarting pop-up
|
||||
# - Close System Preferences
|
||||
|
||||
on run argv
|
||||
set userpassword to item 1 of argv
|
||||
set secpane to "Security & Privacy"
|
||||
|
||||
activate application "System Preferences"
|
||||
delay 5
|
||||
|
||||
tell application "System Events"
|
||||
tell process "System Preferences"
|
||||
set frontmost to true
|
||||
delay 2
|
||||
click menu item secpane of menu "View" of menu bar 1
|
||||
delay 5
|
||||
click button 1 of window 1
|
||||
delay 5
|
||||
keystroke userpassword
|
||||
delay 5
|
||||
keystroke return
|
||||
delay 5
|
||||
click radio button "General" of tab group 1 of window 1
|
||||
delay 5
|
||||
if exists of UI element "Details…" of tab group 1 of window 1 then
|
||||
click button "Details…" of tab group 1 of window 1
|
||||
delay 5
|
||||
keystroke return
|
||||
delay 5
|
||||
keystroke return
|
||||
delay 5
|
||||
end if
|
||||
if exists of UI element "Allow" of tab group 1 of window 1 then
|
||||
click button "Allow" of tab group 1 of window 1
|
||||
delay 5
|
||||
keystroke return
|
||||
delay 5
|
||||
end if
|
||||
click button 5 of window 1
|
||||
end tell
|
||||
end tell
|
||||
end run
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash -e -o pipefail
|
||||
|
||||
source $HOME/.bashrc
|
||||
pwsh -Command "Import-Module '$HOME/image-generation/tests/Helpers.psm1' -DisableNameChecking
|
||||
Invoke-PesterTests -TestFile \"$1\" -TestName \"$2\""
|
||||
@@ -0,0 +1,218 @@
|
||||
#!/bin/bash -e -o pipefail
|
||||
|
||||
download_with_retry() {
|
||||
url=$1
|
||||
download_path=$2
|
||||
|
||||
if [ -z "$download_path" ]; then
|
||||
download_path="/tmp/$(basename "$url")"
|
||||
fi
|
||||
|
||||
echo "Downloading package from $url to $download_path..." >&2
|
||||
|
||||
interval=30
|
||||
download_start_time=$(date +%s)
|
||||
|
||||
for ((retries=20; retries>0; retries--)); do
|
||||
attempt_start_time=$(date +%s)
|
||||
if http_code=$(curl -4sSLo "$download_path" "$url" -w '%{http_code}'); then
|
||||
attempt_seconds=$(($(date +%s) - attempt_start_time))
|
||||
if [ "$http_code" -eq 200 ]; then
|
||||
echo "Package downloaded in $attempt_seconds seconds" >&2
|
||||
break
|
||||
else
|
||||
echo "Received HTTP status code $http_code after $attempt_seconds seconds" >&2
|
||||
fi
|
||||
else
|
||||
attempt_seconds=$(($(date +%s) - attempt_start_time))
|
||||
echo "Package download failed in $attempt_seconds seconds" >&2
|
||||
fi
|
||||
|
||||
if [ $retries -eq 0 ]; then
|
||||
total_seconds=$(($(date +%s) - download_start_time))
|
||||
echo "Package download failed after $total_seconds seconds" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Waiting $interval seconds before retrying (retries left: $retries)..." >&2
|
||||
sleep $interval
|
||||
done
|
||||
|
||||
echo "$download_path"
|
||||
}
|
||||
|
||||
is_Arm64() {
|
||||
[ "$(arch)" = "arm64" ]
|
||||
}
|
||||
|
||||
is_Sequoia() {
|
||||
[ "$OSTYPE" = "darwin24" ]
|
||||
}
|
||||
|
||||
is_SequoiaArm64() {
|
||||
is_Sequoia && is_Arm64
|
||||
}
|
||||
|
||||
is_SequoiaX64() {
|
||||
is_Sequoia && ! is_Arm64
|
||||
}
|
||||
|
||||
is_Sonoma() {
|
||||
[ "$OSTYPE" = "darwin23" ]
|
||||
}
|
||||
|
||||
is_SonomaArm64() {
|
||||
is_Sonoma && is_Arm64
|
||||
}
|
||||
|
||||
is_SonomaX64() {
|
||||
is_Sonoma && ! is_Arm64
|
||||
}
|
||||
|
||||
is_Ventura() {
|
||||
[ "$OSTYPE" = "darwin22" ]
|
||||
}
|
||||
|
||||
is_VenturaArm64() {
|
||||
is_Ventura && is_Arm64
|
||||
}
|
||||
|
||||
is_VenturaX64() {
|
||||
is_Ventura && ! is_Arm64
|
||||
}
|
||||
|
||||
is_Monterey() {
|
||||
[ "$OSTYPE" = "darwin21" ]
|
||||
}
|
||||
|
||||
get_toolset_value() {
|
||||
local toolset_path=$(echo "$IMAGE_FOLDER/toolset.json")
|
||||
local query=$1
|
||||
echo "$(jq -r "$query" $toolset_path)"
|
||||
}
|
||||
|
||||
# brew provides package bottles for different macOS versions
|
||||
# The 'brew install' command will fail if a package bottle does not exist
|
||||
# Use the '--build-from-source' option to build from source in this case
|
||||
brew_smart_install() {
|
||||
local tool_name=$1
|
||||
|
||||
echo "Downloading $tool_name..."
|
||||
|
||||
# get deps & cache em
|
||||
|
||||
failed=true
|
||||
for i in {1..10}; do
|
||||
brew deps $tool_name > /tmp/$tool_name && failed=false || sleep 60
|
||||
[ "$failed" = false ] && break
|
||||
done
|
||||
|
||||
if [ "$failed" = true ]; then
|
||||
echo "Failed: brew deps $tool_name"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
for dep in $(cat /tmp/$tool_name) $tool_name; do
|
||||
|
||||
failed=true
|
||||
for i in {1..10}; do
|
||||
brew --cache $dep >/dev/null && failed=false || sleep 60
|
||||
[ "$failed" = false ] && break
|
||||
done
|
||||
|
||||
if [ "$failed" = true ]; then
|
||||
echo "Failed: brew --cache $dep"
|
||||
exit 1;
|
||||
fi
|
||||
done
|
||||
|
||||
failed=true
|
||||
for i in {1..10}; do
|
||||
brew install $tool_name && failed=false || sleep 60
|
||||
[ "$failed" = false ] && break
|
||||
done
|
||||
|
||||
if [ "$failed" = true ]; then
|
||||
echo "Failed: brew install $tool_name"
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
configure_system_tccdb () {
|
||||
local values=$1
|
||||
local dbPath="/Library/Application Support/com.apple.TCC/TCC.db"
|
||||
local sqlQuery="INSERT OR IGNORE INTO access VALUES($values);"
|
||||
sudo sqlite3 "$dbPath" "$sqlQuery"
|
||||
}
|
||||
|
||||
configure_user_tccdb () {
|
||||
local values=$1
|
||||
local dbPath="$HOME/Library/Application Support/com.apple.TCC/TCC.db"
|
||||
local sqlQuery="INSERT OR IGNORE INTO access VALUES($values);"
|
||||
sqlite3 "$dbPath" "$sqlQuery"
|
||||
}
|
||||
|
||||
resolve_github_release_asset_url() {
|
||||
local repo=$1
|
||||
local filter=$2
|
||||
local version=${3:-"*"}
|
||||
local api_pat=$4
|
||||
|
||||
page_size="100"
|
||||
|
||||
[ -n "$api_pat" ] && authString=(-H "Authorization: token ${api_pat}")
|
||||
|
||||
json=$(curl "${authString[@]}" -fsSL "https://api.github.com/repos/${repo}/releases?per_page=${page_size}")
|
||||
|
||||
if [[ $version == "latest" ]]; then
|
||||
tag_name=$(echo $json | jq -r '.[].tag_name' | sort --unique --version-sort | egrep -v ".*-[a-z]|beta" | tail -n 1)
|
||||
elif [[ $version == *"*"* ]]; then
|
||||
tag_name=$(echo $json | jq -r '.[].tag_name' | sort --unique --version-sort | egrep -v ".*-[a-z]|beta" | egrep "${version}" | tail -n 1)
|
||||
else
|
||||
tag_name=$(echo $json | jq -r '.[].tag_name' | sort --unique --version-sort | egrep -v ".*-[a-z]|beta" | egrep "${version}")
|
||||
fi
|
||||
|
||||
download_url=$(echo $json | jq -r ".[] | select(.tag_name==\"${tag_name}\").assets[].browser_download_url | select(${filter})" | head -n 1)
|
||||
if [ -z "$download_url" ]; then
|
||||
echo "Failed to parse a download url for the '${tag_name}' tag using '${filter}' filter"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo $download_url
|
||||
}
|
||||
|
||||
# Close all finder windows because they can interfere with UI tests
|
||||
close_finder_window() {
|
||||
osascript -e 'tell application "Finder" to close windows'
|
||||
}
|
||||
|
||||
get_arch() {
|
||||
arch=$(arch)
|
||||
if [[ $arch == "arm64" ]]; then
|
||||
echo "arm64"
|
||||
else
|
||||
echo "x64"
|
||||
fi
|
||||
}
|
||||
|
||||
use_checksum_comparison() {
|
||||
local file_path=$1
|
||||
local checksum=$2
|
||||
local sha_type=${3:-"256"}
|
||||
|
||||
echo "Performing checksum verification"
|
||||
|
||||
if [[ ! -f "$file_path" ]]; then
|
||||
echo "File not found: $file_path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local_file_hash=$(shasum --algorithm "$sha_type" "$file_path" | awk '{print $1}')
|
||||
|
||||
if [[ "$local_file_hash" != "$checksum" ]]; then
|
||||
echo "Checksum verification failed. Expected hash: $checksum; Actual hash: $local_file_hash."
|
||||
exit 1
|
||||
else
|
||||
echo "Checksum verification passed"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
#!/bin/bash -e -o pipefail
|
||||
|
||||
source ~/utils/utils.sh
|
||||
|
||||
# Xamarin can clean their SDKs while updating to newer versions,
|
||||
# so we should be able to detect it during image generation
|
||||
|
||||
buildVSMacDownloadUrl() {
|
||||
echo "https://dl.xamarin.com/VsMac/VisualStudioForMac-${1}.dmg"
|
||||
}
|
||||
|
||||
buildMonoDownloadUrl() {
|
||||
echo "https://dl.xamarin.com/MonoFrameworkMDK/Macx86/MonoFramework-MDK-${1}.macos10.xamarin.universal.pkg"
|
||||
}
|
||||
|
||||
buildXamariniIOSDownloadUrl() {
|
||||
echo "https://dl.xamarin.com/MonoTouch/Mac/xamarin.ios-${1}.pkg"
|
||||
}
|
||||
|
||||
buildXamarinMacDownloadUrl() {
|
||||
echo "https://dl.xamarin.com/XamarinforMac/Mac/xamarin.mac-${1}.pkg"
|
||||
}
|
||||
|
||||
buildXamarinAndroidDownloadUrl() {
|
||||
echo "https://dl.xamarin.com/MonoforAndroid/Mac/xamarin.android-${1}.pkg"
|
||||
}
|
||||
|
||||
installMono() {
|
||||
local VERSION=$1
|
||||
|
||||
echo "Installing Mono ${VERSION}..."
|
||||
local MONO_FOLDER_NAME=$(echo $VERSION | cut -d. -f 1,2,3)
|
||||
local SHORT_VERSION=$(echo $VERSION | cut -d. -f 1,2)
|
||||
local PKG_URL=$(buildMonoDownloadUrl $VERSION)
|
||||
|
||||
sudo installer -pkg "$(download_with_retry "$PKG_URL")" -target /
|
||||
|
||||
echo "Installing nunit3-console for Mono "$VERSION
|
||||
installNunitConsole $MONO_FOLDER_NAME
|
||||
|
||||
echo "Creating short symlink '${SHORT_VERSION}'"
|
||||
sudo ln -s ${MONO_VERSIONS_PATH}/${MONO_FOLDER_NAME} ${MONO_VERSIONS_PATH}/${SHORT_VERSION}
|
||||
|
||||
echo "Move to backup folder"
|
||||
sudo mv -v $MONO_VERSIONS_PATH/* $TMPMOUNT_FRAMEWORKS/mono/
|
||||
}
|
||||
|
||||
installXamarinIOS() {
|
||||
local VERSION=$1
|
||||
|
||||
echo "Installing Xamarin.iOS ${VERSION}..."
|
||||
local SHORT_VERSION=$(echo $VERSION | cut -d. -f 1,2)
|
||||
local PKG_URL=$(buildXamariniIOSDownloadUrl $VERSION)
|
||||
|
||||
sudo installer -pkg "$(download_with_retry "$PKG_URL")" -target /
|
||||
|
||||
echo "Creating short symlink '${SHORT_VERSION}'"
|
||||
sudo ln -s ${IOS_VERSIONS_PATH}/${VERSION} ${IOS_VERSIONS_PATH}/${SHORT_VERSION}
|
||||
|
||||
echo "Move to backup folder"
|
||||
sudo mv -v $IOS_VERSIONS_PATH/* $TMPMOUNT_FRAMEWORKS/ios/
|
||||
}
|
||||
|
||||
installXamarinMac() {
|
||||
local VERSION=$1
|
||||
|
||||
echo "Installing Xamarin.Mac ${VERSION}..."
|
||||
local SHORT_VERSION=$(echo $VERSION | cut -d. -f 1,2)
|
||||
local PKG_URL=$(buildXamarinMacDownloadUrl $VERSION)
|
||||
|
||||
sudo installer -pkg "$(download_with_retry "$PKG_URL")" -target /
|
||||
|
||||
echo "Creating short symlink '${SHORT_VERSION}'"
|
||||
sudo ln -s ${MAC_VERSIONS_PATH}/${VERSION} ${MAC_VERSIONS_PATH}/${SHORT_VERSION}
|
||||
|
||||
echo "Move to backup folder"
|
||||
sudo mv -v $MAC_VERSIONS_PATH/* $TMPMOUNT_FRAMEWORKS/mac/
|
||||
}
|
||||
|
||||
installXamarinAndroid() {
|
||||
local VERSION=$1
|
||||
|
||||
echo "Installing Xamarin.Android ${VERSION}..."
|
||||
local SHORT_VERSION=$(echo $VERSION | cut -d. -f 1,2)
|
||||
local PKG_URL=$(buildXamarinAndroidDownloadUrl $VERSION)
|
||||
|
||||
sudo installer -pkg "$(download_with_retry "$PKG_URL")" -target /
|
||||
|
||||
if [ "$VERSION" == "9.4.1.0" ]; then
|
||||
# Fix symlinks for broken Xamarin.Android
|
||||
fixXamarinAndroidSymlinksInLibDir $VERSION
|
||||
fi
|
||||
|
||||
echo "Creating short symlink '${SHORT_VERSION}'"
|
||||
sudo ln -s ${ANDROID_VERSIONS_PATH}/${VERSION} ${ANDROID_VERSIONS_PATH}/${SHORT_VERSION}
|
||||
|
||||
echo "Move to backup folder"
|
||||
sudo mv -v $ANDROID_VERSIONS_PATH/* $TMPMOUNT_FRAMEWORKS/android/
|
||||
}
|
||||
|
||||
createBundle() {
|
||||
local SYMLINK=$1
|
||||
local MONO_SDK=$2
|
||||
local IOS_SDK=$3
|
||||
local MAC_SDK=$4
|
||||
local ANDROID_SDK=$5
|
||||
|
||||
echo "Creating bundle '$SYMLINK' (Mono $MONO_SDK; iOS $IOS_SDK; Mac $MAC_SDK; Android $ANDROID_SDK"
|
||||
deleteSymlink ${SYMLINK}
|
||||
sudo ln -s ${MONO_VERSIONS_PATH}/${MONO_SDK} ${MONO_VERSIONS_PATH}/${SYMLINK}
|
||||
sudo ln -s ${IOS_VERSIONS_PATH}/${IOS_SDK} ${IOS_VERSIONS_PATH}/${SYMLINK}
|
||||
sudo ln -s ${MAC_VERSIONS_PATH}/${MAC_SDK} ${MAC_VERSIONS_PATH}/${SYMLINK}
|
||||
sudo ln -s ${ANDROID_VERSIONS_PATH}/${ANDROID_SDK} ${ANDROID_VERSIONS_PATH}/${SYMLINK}
|
||||
}
|
||||
|
||||
createBundleLink() {
|
||||
local SOURCE=$1
|
||||
local TARGET=$2
|
||||
echo "Creating bundle symlink '$SOURCE' -> '$TARGET'"
|
||||
deleteSymlink ${TARGET}
|
||||
sudo ln -s ${MONO_VERSIONS_PATH}/$SOURCE ${MONO_VERSIONS_PATH}/$TARGET
|
||||
sudo ln -s ${IOS_VERSIONS_PATH}/$SOURCE ${IOS_VERSIONS_PATH}/$TARGET
|
||||
sudo ln -s ${MAC_VERSIONS_PATH}/$SOURCE ${MAC_VERSIONS_PATH}/$TARGET
|
||||
sudo ln -s ${ANDROID_VERSIONS_PATH}/$SOURCE ${ANDROID_VERSIONS_PATH}/$TARGET
|
||||
}
|
||||
|
||||
# https://github.com/xamarin/xamarin-android/issues/3457
|
||||
# Recreate missing symlinks in lib for new Xamarin.Android package
|
||||
# Symlink path /Library/Frameworks/Xamarin.Android.framework/Libraries
|
||||
# xbuild -> xamarin.android/xbuild
|
||||
# xbuild-frameworks -> xamarin.android/xbuild-frameworks
|
||||
fixXamarinAndroidSymlinksInLibDir() {
|
||||
local XAMARIN_ANDROID_VERSION=$1
|
||||
local XAMARIN_ANDROID_LIB_PATH="${ANDROID_VERSIONS_PATH}/${XAMARIN_ANDROID_VERSION}/lib"
|
||||
|
||||
if [ -d "${XAMARIN_ANDROID_LIB_PATH}" ]; then
|
||||
pushd "${XAMARIN_ANDROID_LIB_PATH}" > /dev/null
|
||||
|
||||
local XAMARIN_ANDROID_XBUILD_DIR="${XAMARIN_ANDROID_LIB_PATH}/xbuild"
|
||||
if [ ! -d "${XAMARIN_ANDROID_XBUILD_DIR}" ]; then
|
||||
echo "${XAMARIN_ANDROID_XBUILD_DIR}"
|
||||
sudo ln -sf xamarin.android/xbuild xbuild
|
||||
fi
|
||||
|
||||
local XAMARIN_ANDROID_XBUILD_FRAMEWORKS_DIR="${XAMARIN_ANDROID_LIB_PATH}/xbuild-frameworks"
|
||||
if [ ! -d "${XAMARIN_ANDROID_XBUILD_FRAMEWORKS_DIR}" ]; then
|
||||
echo "${XAMARIN_ANDROID_XBUILD_FRAMEWORKS_DIR}"
|
||||
sudo ln -sf xamarin.android/xbuild-frameworks xbuild-frameworks
|
||||
fi
|
||||
|
||||
popd > /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
installNunitConsole() {
|
||||
local MONO_VERSION=$1
|
||||
local TMP_WRAPPER_PATH=$(mktemp)
|
||||
|
||||
cat <<EOF > "$TMP_WRAPPER_PATH"
|
||||
#!/bin/bash -e -o pipefail
|
||||
exec /Library/Frameworks/Mono.framework/Versions/${MONO_VERSION}/bin/mono --debug \$MONO_OPTIONS $NUNIT3_PATH/nunit3-console.exe "\$@"
|
||||
EOF
|
||||
sudo chmod +x $TMP_WRAPPER_PATH
|
||||
sudo mv "$TMP_WRAPPER_PATH" "${MONO_VERSIONS_PATH}/${MONO_VERSION}/Commands/nunit3-console"
|
||||
}
|
||||
|
||||
downloadNUnitConsole() {
|
||||
echo "Downloading NUnit 3..."
|
||||
local NUNIT3_VERSION='3.6.1'
|
||||
local NUNIT3_LOCATION="https://github.com/nunit/nunit-console/releases/download/${NUNIT3_VERSION}/NUnit.Console-${NUNIT3_VERSION}.zip"
|
||||
local NUNIT3_PATH="/Library/Developer/nunit/${NUNIT3_VERSION}"
|
||||
|
||||
NUNIT3_ARCHIVE=$(download_with_retry $NUNIT3_LOCATION)
|
||||
|
||||
echo "Installing NUnit 3..."
|
||||
sudo mkdir -p $NUNIT3_PATH
|
||||
sudo unzip "$NUNIT3_ARCHIVE" -d $NUNIT3_PATH
|
||||
}
|
||||
|
||||
createUWPShim() {
|
||||
echo "Creating UWP Shim to hack UWP build failure..."
|
||||
cat <<EOF > ${TMPMOUNT}/Microsoft.Windows.UI.Xaml.CSharp.Targets
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Target Name = "Build"/>
|
||||
<Target Name = "Rebuild"/>
|
||||
</Project>
|
||||
EOF
|
||||
|
||||
local UWPTARGET_PATH=/Library/Frameworks/Mono.framework/External/xbuild/Microsoft/WindowsXaml
|
||||
|
||||
sudo mkdir -p $UWPTARGET_PATH/v11.0/
|
||||
sudo cp ${TMPMOUNT}/Microsoft.Windows.UI.Xaml.CSharp.Targets $UWPTARGET_PATH/v11.0/
|
||||
sudo mkdir -p $UWPTARGET_PATH/v12.0/
|
||||
sudo cp ${TMPMOUNT}/Microsoft.Windows.UI.Xaml.CSharp.Targets $UWPTARGET_PATH/v12.0/
|
||||
sudo mkdir -p $UWPTARGET_PATH/v14.0/
|
||||
sudo cp ${TMPMOUNT}/Microsoft.Windows.UI.Xaml.CSharp.Targets $UWPTARGET_PATH/v14.0/
|
||||
sudo mkdir -p $UWPTARGET_PATH/v15.0/
|
||||
sudo cp ${TMPMOUNT}/Microsoft.Windows.UI.Xaml.CSharp.Targets $UWPTARGET_PATH/v15.0/
|
||||
sudo mkdir -p $UWPTARGET_PATH/v16.0/
|
||||
sudo cp ${TMPMOUNT}/Microsoft.Windows.UI.Xaml.CSharp.Targets $UWPTARGET_PATH/v16.0/
|
||||
}
|
||||
|
||||
createBackupFolders() {
|
||||
mkdir -p $TMPMOUNT_FRAMEWORKS/mono
|
||||
mkdir -p $TMPMOUNT_FRAMEWORKS/ios
|
||||
mkdir -p $TMPMOUNT_FRAMEWORKS/mac
|
||||
mkdir -p $TMPMOUNT_FRAMEWORKS/android
|
||||
}
|
||||
|
||||
deleteSymlink() {
|
||||
sudo rm -f ${MONO_VERSIONS_PATH}/${1}
|
||||
sudo rm -f ${IOS_VERSIONS_PATH}/${1}
|
||||
sudo rm -f ${MAC_VERSIONS_PATH}/${1}
|
||||
sudo rm -f ${ANDROID_VERSIONS_PATH}/${1}
|
||||
}
|
||||
Reference in New Issue
Block a user