Files
runner-images/images/macos/provision/core/xcode.ps1
T

62 lines
2.3 KiB
PowerShell
Raw Normal View History

2020-10-31 18:41:04 +03:00
# The script currently requires 2 external variables to be set: XCODE_INSTALL_USER
# and XCODE_INSTALL_PASSWORD, in order to access the Apple Developer Center
$ErrorActionPreference = "Stop"
2020-11-01 15:55:02 +03:00
Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1"
Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1"
2020-10-31 18:41:04 +03:00
if ([string]::IsNullOrEmpty($env:XCODE_INSTALL_USER) -or [string]::IsNullOrEmpty($env:XCODE_INSTALL_PASSWORD)) {
throw "Required environment variables XCODE_INSTALL_USER and XCODE_INSTALL_PASSWORD are not set"
}
# Spaceship Apple ID login fails due to Apple ID prompting to be upgraded to 2FA.
# https://github.com/fastlane/fastlane/pull/18116
$env:SPACESHIP_SKIP_2FA_UPGRADE = 1
2020-10-31 18:41:04 +03:00
$os = Get-OSVersion
[Array]$xcodeVersions = Get-ToolsetValue "xcode.versions"
2020-10-31 18:41:04 +03:00
$defaultXcode = Get-ToolsetValue "xcode.default"
2020-11-09 17:46:21 +03:00
[Array]::Reverse($xcodeVersions)
2021-02-18 15:08:41 +03:00
$threadCount = "5"
2020-10-31 18:41:04 +03:00
Write-Host "Installing Xcode versions..."
2021-02-18 15:08:41 +03:00
$xcodeVersions | ForEach-Object -ThrottleLimit $threadCount -Parallel {
$ErrorActionPreference = "Stop"
Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1"
Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1"
2020-11-01 11:13:45 +03:00
Install-XcodeVersion -Version $_.version -LinkTo $_.link
Confirm-XcodeIntegrity -Version $_.link
Approve-XcodeLicense -Version $_.link
2020-10-31 18:41:04 +03:00
}
Write-Host "Configuring Xcode versions..."
$xcodeVersions | ForEach-Object {
Invoke-XcodeRunFirstLaunch -Version $_.link
2021-02-18 15:08:41 +03:00
}
2020-10-31 18:41:04 +03:00
Invoke-XcodeRunFirstLaunch -Version $defaultXcode
2020-11-01 11:13:45 +03:00
Write-Host "Configuring Xcode symlinks..."
$xcodeVersions | ForEach-Object {
Build-XcodeSymlinks -Version $_.link -Symlinks $_.symlinks
# Skip creating symlink to install multiple releases of the same Xcode version side-by-side
if ($_."skip-symlink" -ne "true") {
Build-ProvisionatorSymlink -Version $_.link
}
2020-11-01 11:13:45 +03:00
}
Write-Host "Rebuilding Launch Services database ..."
$xcodeVersions | ForEach-Object {
Rebuild-XcodeLaunchServicesDb -Version $_.link
}
2020-10-31 18:41:04 +03:00
Write-Host "Setting default Xcode to $defaultXcode"
Switch-Xcode -Version $defaultXcode
2020-11-02 21:35:36 +03:00
New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode) | Out-Null
2020-10-31 18:41:04 +03:00
Write-Host "Setting environment variables 'XCODE_<VERSION>_DEVELOPER_DIR'"
Set-XcodeDeveloperDirEnvironmentVariables -XcodeList $xcodeVersions.link