diff --git a/images/macos/helpers/Xcode.Helpers.psm1 b/images/macos/helpers/Xcode.Helpers.psm1 index de3b94be..46e5330c 100644 --- a/images/macos/helpers/Xcode.Helpers.psm1 +++ b/images/macos/helpers/Xcode.Helpers.psm1 @@ -121,4 +121,34 @@ function Get-XcodePairsList { $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." + } } \ No newline at end of file diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 64d2381b..6d21a613 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -27,10 +27,8 @@ function Invoke-DownloadXcodeArchive { if (-not $resolvedVersion) { throw "Version '$Version' can't be matched to any available version" } - - # TO-DO: Consider replacing of xcversion with own implementation Write-Host "Downloading Xcode $resolvedVersion" - Invoke-ValidateCommand "xcversion install '$resolvedVersion' --no-install" + Invoke-XCVersion -Arguments "install '$resolvedVersion' --no-install" } function Resolve-ExactXcodeVersion { @@ -51,7 +49,7 @@ function Resolve-ExactXcodeVersion { } function Get-AvailableXcodeVersions { - $rawVersionsList = & xcversion list | ForEach-Object { $_.Trim() } | Where-Object { $_ -match "^\d" } + $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)