mirror of
https://github.com/actions/runner-images.git
synced 2025-12-20 06:35:47 +00:00
fix tests
This commit is contained in:
@@ -5,17 +5,14 @@ function Install-XcodeVersion {
|
|||||||
[Parameter(Mandatory)]
|
[Parameter(Mandatory)]
|
||||||
[string]$Version,
|
[string]$Version,
|
||||||
[Parameter(Mandatory)]
|
[Parameter(Mandatory)]
|
||||||
[string]$LocalLink
|
[string]$LinkTo
|
||||||
)
|
)
|
||||||
|
|
||||||
$xcodeDownloadDirectory = "$env:HOME/Library/Caches/XcodeInstall"
|
$xcodeDownloadDirectory = "$env:HOME/Library/Caches/XcodeInstall"
|
||||||
$xcodeTargetPath = Get-XcodeRootPath -Version $LocalLink
|
$xcodeTargetPath = Get-XcodeRootPath -Version $LinkTo
|
||||||
Push-Location $xcodeDownloadDirectory
|
|
||||||
|
|
||||||
Invoke-DownloadXcodeArchive -Version $Version
|
Invoke-DownloadXcodeArchive -Version $Version
|
||||||
Expand-XcodeXipArchive -DownloadDirectory $xcodeDownloadDirectory -TargetPath $xcodeTargetPath
|
Expand-XcodeXipArchive -DownloadDirectory $xcodeDownloadDirectory -TargetPath $xcodeTargetPath
|
||||||
Confirm-XcodeIntegrity -XcodeRootPath $xcodeTargetPath
|
|
||||||
Approve-XcodeLicense -XcodeRootPath $xcodeTargetPath
|
|
||||||
|
|
||||||
Get-ChildItem $xcodeDownloadDirectory | Remove-Item -Force
|
Get-ChildItem $xcodeDownloadDirectory | Remove-Item -Force
|
||||||
}
|
}
|
||||||
@@ -33,6 +30,7 @@ function Invoke-DownloadXcodeArchive {
|
|||||||
|
|
||||||
# TO-DO: Consider replacing of xcversion with own implementation
|
# TO-DO: Consider replacing of xcversion with own implementation
|
||||||
Write-Host "Downloading Xcode $resolvedVersion"
|
Write-Host "Downloading Xcode $resolvedVersion"
|
||||||
|
# TO-DO: handle exit code
|
||||||
xcversion install "$resolvedVersion" --no-install
|
xcversion install "$resolvedVersion" --no-install
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +56,13 @@ function Expand-XcodeXipArchive {
|
|||||||
|
|
||||||
Write-Host "Extracting Xcode from '$xcodeXipPath'"
|
Write-Host "Extracting Xcode from '$xcodeXipPath'"
|
||||||
Push-Location $DownloadDirectory
|
Push-Location $DownloadDirectory
|
||||||
|
# TO-DO: handle exit code
|
||||||
xip -x $xcodeXipPath
|
xip -x $xcodeXipPath
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
|
||||||
if (Test-Path "$DownloadDirectory/Xcode-beta.app") {
|
if (Test-Path "$DownloadDirectory/Xcode-beta.app") {
|
||||||
Write-Host "Renaming Xcode-beta.app to Xcode.app"
|
Write-Host "Renaming Xcode-beta.app to Xcode.app"
|
||||||
Rename-File -Path "$DownloadDirectory/Xcode-beta.app" -NewName "Xcode.app"
|
Rename-Item -Path "$DownloadDirectory/Xcode-beta.app" -NewName "Xcode.app"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Test-Path "$DownloadDirectory/Xcode.app")) {
|
if (-not (Test-Path "$DownloadDirectory/Xcode.app")) {
|
||||||
@@ -77,10 +76,12 @@ function Expand-XcodeXipArchive {
|
|||||||
function Confirm-XcodeIntegrity {
|
function Confirm-XcodeIntegrity {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory)]
|
[Parameter(Mandatory)]
|
||||||
[string]$XcodeRootPath
|
[string]$Version
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$XcodeRootPath = Get-XcodeRootPath -Version $Version
|
||||||
if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) {
|
if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) {
|
||||||
|
# TO-DO: handle exit code
|
||||||
spctl --assess --raw $XcodeRootPath
|
spctl --assess --raw $XcodeRootPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,10 +89,11 @@ function Confirm-XcodeIntegrity {
|
|||||||
function Approve-XcodeLicense {
|
function Approve-XcodeLicense {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory)]
|
[Parameter(Mandatory)]
|
||||||
$XcodeRootPath
|
[string]$Version
|
||||||
)
|
)
|
||||||
|
|
||||||
$xcodeBuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild"
|
$xcodeBuildPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild"
|
||||||
|
# TO-DO: handle exit code
|
||||||
sudo $xcodeBuildPath -license accept
|
sudo $xcodeBuildPath -license accept
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +105,9 @@ function Install-XcodeAdditionalPackages {
|
|||||||
|
|
||||||
Write-Host "Installing additional packages for Xcode $Version..."
|
Write-Host "Installing additional packages for Xcode $Version..."
|
||||||
$xcodeRootPath = Get-XcodeRootPath -Version $Version
|
$xcodeRootPath = Get-XcodeRootPath -Version $Version
|
||||||
$packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -Name -File
|
$packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -File
|
||||||
$packages | ForEach-Object { & sudo installer -pkg $_ -target / -allowUntrusted }
|
# TO-DO: handle exit code
|
||||||
|
$packages | ForEach-Object { & sudo installer -pkg $_.FullName -target / -allowUntrusted }
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-XcodeRunFirstLaunch {
|
function Invoke-XcodeRunFirstLaunch {
|
||||||
@@ -119,6 +122,7 @@ function Invoke-XcodeRunFirstLaunch {
|
|||||||
|
|
||||||
Write-Host "Running 'runFirstLaunch' for Xcode $Version..."
|
Write-Host "Running 'runFirstLaunch' for Xcode $Version..."
|
||||||
$xcodeRootPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild"
|
$xcodeRootPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild"
|
||||||
|
# TO-DO: handle exit code
|
||||||
& sudo $xcodeRootPath -runFirstLaunch
|
& sudo $xcodeRootPath -runFirstLaunch
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,5 +160,26 @@ function Build-ProvisionatorSymlink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Set-XcodeDeveloperDirEnvironmentVariables {
|
function Set-XcodeDeveloperDirEnvironmentVariables {
|
||||||
# TO-DO
|
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 {
|
||||||
|
$latestXcodeVersion = $exactVersionsList | Where-Object { $_.Version.Major -eq $_ } | 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,25 +14,29 @@ $os = Get-OSVersion
|
|||||||
$xcodeVersions = Get-ToolsetValue "xcode.versions"
|
$xcodeVersions = Get-ToolsetValue "xcode.versions"
|
||||||
$defaultXcode = Get-ToolsetValue "xcode.default"
|
$defaultXcode = Get-ToolsetValue "xcode.default"
|
||||||
|
|
||||||
& xcversion update
|
|
||||||
|
|
||||||
Write-Host "Installing Xcode versions..."
|
Write-Host "Installing Xcode versions..."
|
||||||
foreach ($xcode in $xcodeVersions) {
|
$xcodeVersions | ForEach-Object {
|
||||||
Install-XcodeVersion -Version $xcode.version -LocalLink $xcode.localLink
|
Install-XcodeVersion -Version $_.version -LinkTo $_.link
|
||||||
Build-XcodeSymlinks -Version $xcode.localLink -Symlinks $xcode.symlinks
|
Confirm-XcodeIntegrity -Version $_.link
|
||||||
Build-ProvisionatorSymlink -Version $xcode.version
|
Approve-XcodeLicense -Version $_.link
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Configuring Xcode versions..."
|
Write-Host "Configuring Xcode versions..."
|
||||||
if ($os.IsLessThanCatalina) {
|
if ($os.IsLessThanCatalina) {
|
||||||
Install-XcodeAdditionalPackages -Version $xcodeVersions[0].localLink
|
Install-XcodeAdditionalPackages -Version $xcodeVersions[0].link
|
||||||
}
|
}
|
||||||
$xcodeVersions | ForEach-Object { Invoke-XcodeRunFirstLaunch -Version $_.localLink }
|
$xcodeVersions | ForEach-Object { Invoke-XcodeRunFirstLaunch -Version $_.link }
|
||||||
Invoke-XcodeRunFirstLaunch -Version $defaultXcode
|
Invoke-XcodeRunFirstLaunch -Version $defaultXcode
|
||||||
|
|
||||||
|
Write-Host "Configuring Xcode symlinks..."
|
||||||
|
$xcodeVersions | ForEach-Object {
|
||||||
|
Build-XcodeSymlinks -Version $_.link -Symlinks $_.symlinks
|
||||||
|
Build-ProvisionatorSymlink -Version $_.link
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Setting default Xcode to $defaultXcode"
|
Write-Host "Setting default Xcode to $defaultXcode"
|
||||||
Switch-Xcode -Version $defaultXcode
|
Switch-Xcode -Version $defaultXcode
|
||||||
New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode)
|
New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode)
|
||||||
|
|
||||||
Write-Host "Setting environment variables 'XCODE_<VERSION>_DEVELOPER_DIR'"
|
Write-Host "Setting environment variables 'XCODE_<VERSION>_DEVELOPER_DIR'"
|
||||||
Set-XcodeDeveloperDirEnvironmentVariables
|
Set-XcodeDeveloperDirEnvironmentVariables -XcodeList $xcodeVersions.link
|
||||||
@@ -2,39 +2,39 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1"
|
|||||||
Import-Module "$PSScriptRoot/../helpers/Xcode.Helpers.psm1"
|
Import-Module "$PSScriptRoot/../helpers/Xcode.Helpers.psm1"
|
||||||
Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1"
|
Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1"
|
||||||
|
|
||||||
$XCODE_VERSIONS = Get-ToolsetValue "xcode.versions"
|
$xcodeVersions = Get-ToolsetValue "xcode.versions"
|
||||||
$DEFAULT_XCODE = Get-ToolsetValue "xcode.default"
|
$defaultXcode = Get-ToolsetValue "xcode.default"
|
||||||
$LATEST_XCODE_VERSION = $XCODE_VERSIONS | Select-Object -First 1
|
$latestXcodeVersion = $xcodeVersions | Select-Object -First 1
|
||||||
$OS = Get-OSVersion
|
$os = Get-OSVersion
|
||||||
|
|
||||||
Describe "Xcode" {
|
Describe "Xcode" {
|
||||||
It "Default Xcode is $DEFAULT_XCODE" {
|
$defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode }
|
||||||
|
It "Default Xcode is <DefaultXcode>" -TestCases $defaultXcodeTestCase {
|
||||||
"xcodebuild -version" | Should -ReturnZeroExitCode
|
"xcodebuild -version" | Should -ReturnZeroExitCode
|
||||||
(Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode $DEFAULT_XCODE*"
|
(Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Xcode.app points to default Xcode" {
|
It "Xcode.app points to default Xcode" -TestCases $defaultXcodeTestCase {
|
||||||
|
$xcodeApp = "/Applications/Xcode.app"
|
||||||
|
$expectedTarget = Get-XcodeRootPath -Version $DefaultXcode
|
||||||
|
$xcodeApp | Should -Exist
|
||||||
|
$expectedTarget | Should -Exist
|
||||||
|
(Get-Item $xcodeApp).Target | Should -Be $expectedTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
# Cut "_beta" postfix for test cases
|
$testCases = $xcodeVersions | ForEach-Object { @{ XcodeVersion = $_.link; LatestXcodeVersion = $xcodeVersions[0].link; Symlinks = $_.symlinks } }
|
||||||
$testCases = $XCODE_VERSIONS | ForEach-Object { @{XcodeVersion = $_.Split("_")[0] } }
|
|
||||||
|
|
||||||
It "<XcodeVersion>" -TestCases $testCases {
|
It "<XcodeVersion>" -TestCases $testCases {
|
||||||
param ( [string] $XcodeVersion )
|
|
||||||
|
|
||||||
$xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild"
|
$xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild"
|
||||||
"$xcodebuildPath -version" | Should -ReturnZeroExitCode
|
"$xcodebuildPath -version" | Should -ReturnZeroExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Xcode <XcodeVersion> tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) {
|
It "Xcode <XcodeVersion> tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) {
|
||||||
param ( [string] $XcodeVersion )
|
|
||||||
|
|
||||||
$TOOLS_NOT_INSTALLED_EXIT_CODE = 69
|
$TOOLS_NOT_INSTALLED_EXIT_CODE = 69
|
||||||
$xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild"
|
$xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild"
|
||||||
$result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus"
|
$result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus"
|
||||||
|
|
||||||
if ($XcodeVersion -ne $LATEST_XCODE_VERSION) {
|
if ($XcodeVersion -ne $LatestXcodeVersion) {
|
||||||
$result.ExitCode | Should -Not -Be $TOOLS_NOT_INSTALLED_EXIT_CODE
|
$result.ExitCode | Should -Not -Be $TOOLS_NOT_INSTALLED_EXIT_CODE
|
||||||
} else {
|
} else {
|
||||||
$result.ExitCode | Should -BeIn (0, $TOOLS_NOT_INSTALLED_EXIT_CODE)
|
$result.ExitCode | Should -BeIn (0, $TOOLS_NOT_INSTALLED_EXIT_CODE)
|
||||||
@@ -42,13 +42,12 @@ Describe "Xcode" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
It "Xcode <XcodeVersion> has correct beta symlink" -TestCases $testCases {
|
It "Xcode <XcodeVersion> has correct beta symlink" -TestCases $testCases {
|
||||||
param ( [string] $XcodeVersion )
|
$sourcePath = Get-XcodeRootPath -Version $XcodeVersion
|
||||||
|
$Symlinks | ForEach-Object {
|
||||||
$xcodesWithBetaSymlink = @("12", "9.3", "9.4")
|
$targetPath = Get-XcodeRootPath -Version $_
|
||||||
$shouldBetaSymlinkExists = $XcodeVersion.StartsWith("10") -or $XcodeVersion.StartsWith("11") -or ($XcodeVersion -in $xcodesWithBetaSymlink)
|
$targetPath | Should -Exist
|
||||||
|
(Get-Item $targetPath).Target | Should -Be $sourcePath
|
||||||
$betaSymlinkPath = Get-XcodeRootPath -Version "${XcodeVersion}_beta"
|
}
|
||||||
Test-Path $betaSymlinkPath | Should -Be $shouldBetaSymlinkExists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "/Applications/Xcode* symlinks are valid" {
|
It "/Applications/Xcode* symlinks are valid" {
|
||||||
@@ -58,37 +57,32 @@ Describe "Xcode" {
|
|||||||
$_ | Should -Exist
|
$_ | Should -Exist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Context "XCODE_DEVELOPER_DIR" {
|
Describe "XCODE_DEVELOPER_DIR variables" {
|
||||||
$stableXcodeVersions = $XCODE_VERSIONS | ForEach-Object { $_.Split("_")[0] } | Where-Object { Test-XcodeStableRelease -Version $_ }
|
$exactVersionsList = $xcodeVersions.link | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object {
|
||||||
$majorXcodeVersions = $stableXcodeVersions | ForEach-Object { $_.Split(".")[0] } | Select-Object -Unique
|
$xcodeRootPath = Get-XcodeRootPath -Version $_
|
||||||
$testCases = $majorXcodeVersions | ForEach-Object {
|
$xcodeVersionInfo = Get-XcodeVersionInfo -XcodeRootPath $xcodeRootPath
|
||||||
$majorXcodeVersion = $_
|
return @{
|
||||||
$expectedVersion = $stableXcodeVersions | Where-Object { $_.StartsWith("$majorXcodeVersion") } | Select-Object -First 1
|
RootPath = $xcodeRootPath
|
||||||
return @{
|
Version = [SemVer]::Parse($xcodeVersionInfo.Version)
|
||||||
MajorXcodeVersion = $majorXcodeVersion
|
|
||||||
ExpectedVersion = $expectedVersion
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} | Sort-Object -Property Version -Descending
|
||||||
|
$majorVersions = $exactVersionsList.Version.Major | Select-Object -Unique
|
||||||
|
$testCases = $majorVersions | ForEach-Object { @{ MajorVersion = $_; VersionsList = $exactVersionsList } }
|
||||||
|
|
||||||
It "XCODE_<MajorXcodeVersion>_DEVELOPER_DIR" -TestCases $testCases {
|
It "XCODE_<MajorVersion>_DEVELOPER_DIR" -TestCases $testCases {
|
||||||
param (
|
$variableName = "XCODE_${MajorVersion}_DEVELOPER_DIR"
|
||||||
[string] $MajorXcodeVersion,
|
$actualPath = Get-EnvironmentVariable $variableName
|
||||||
[string] $ExpectedVersion
|
$expectedVersion = $VersionsList | Where-Object { $_.Version.Major -eq $MajorVersion } | Select-Object -First 1
|
||||||
)
|
$expectedPath = "$($expectedVersion.RootPath)/Contents/Developer"
|
||||||
|
$actualPath | Should -Exist
|
||||||
$variableName = "XCODE_${MajorXcodeVersion}_DEVELOPER_DIR"
|
$actualPath | Should -Be $expectedPath
|
||||||
$actualPath = Get-EnvironmentVariable $variableName
|
|
||||||
$expectedPath = Join-Path (Get-XcodeRootPath -Version $ExpectedVersion) "Contents/Developer"
|
|
||||||
|
|
||||||
$actualPath | Should -Exist
|
|
||||||
$actualPath | Should -Be $expectedPath
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Describe "Xcode simulators" {
|
Describe "Xcode simulators" {
|
||||||
$XCODE_VERSIONS | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object {
|
$xcodeVersions | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object {
|
||||||
Switch-Xcode -Version $_
|
Switch-Xcode -Version $_
|
||||||
|
|
||||||
Context "$_" {
|
Context "$_" {
|
||||||
@@ -105,7 +99,7 @@ Describe "Xcode simulators" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
$DEFAULT_XCODE = Get-ToolsetValue "xcode.default"
|
$defaultXcode = Get-ToolsetValue "xcode.default"
|
||||||
Switch-Xcode -Version $DEFAULT_XCODE
|
Switch-Xcode -Version $defaultXcode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user