|
| 1 | +#!/usr/bin/env pwsh |
| 2 | + |
| 3 | +param( |
| 4 | + [Parameter()] |
| 5 | + [string]$RepoRoot = "$PSScriptRoot/.." |
| 6 | +) |
| 7 | + |
| 8 | +Set-StrictMode -Version latest |
| 9 | +$ErrorActionPreference = 'Stop' |
| 10 | +$PSNativeCommandUseErrorActionPreference = $true |
| 11 | + |
| 12 | +$ArtifactsDestination = Join-Path $RepoRoot "package-dev/Plugins" |
| 13 | + |
| 14 | +# SDK definitions with their existence checks |
| 15 | +$SDKs = @( |
| 16 | + @{ |
| 17 | + Name = "Windows" |
| 18 | + Destination = Join-Path $ArtifactsDestination "Windows" |
| 19 | + CheckFile = "Sentry/sentry.dll" |
| 20 | + }, |
| 21 | + @{ |
| 22 | + Name = "Linux" |
| 23 | + Destination = Join-Path $ArtifactsDestination "Linux" |
| 24 | + CheckFile = "Sentry/libsentry.so" |
| 25 | + }, |
| 26 | + @{ |
| 27 | + Name = "Android" |
| 28 | + Destination = Join-Path $ArtifactsDestination "Android" |
| 29 | + CheckDir = "Sentry~" |
| 30 | + ExpectedFileCount = 4 |
| 31 | + } |
| 32 | +) |
| 33 | + |
| 34 | +function Test-SDKPresent { |
| 35 | + param($SDK) |
| 36 | + |
| 37 | + if ($SDK.ContainsKey('CheckFile')) { |
| 38 | + $checkPath = Join-Path $SDK.Destination $SDK.CheckFile |
| 39 | + return Test-Path $checkPath |
| 40 | + } |
| 41 | + elseif ($SDK.ContainsKey('CheckDir')) { |
| 42 | + $checkPath = Join-Path $SDK.Destination $SDK.CheckDir |
| 43 | + if (-not (Test-Path $checkPath)) { |
| 44 | + return $false |
| 45 | + } |
| 46 | + $fileCount = (Get-ChildItem -Path $checkPath -File).Count |
| 47 | + return $fileCount -ge $SDK.ExpectedFileCount |
| 48 | + } |
| 49 | + return $false |
| 50 | +} |
| 51 | + |
| 52 | +function Get-LatestSuccessfulRunId { |
| 53 | + Write-Host "Fetching latest successful CI run ID..." -ForegroundColor Yellow |
| 54 | + |
| 55 | + $result = gh run list --branch main --workflow CI --json "conclusion,databaseId" --jq 'first(.[] | select(.conclusion == "success") | .databaseId)' |
| 56 | + |
| 57 | + if (-not $result -or $result -eq "null") { |
| 58 | + Write-Error "Failed to find a successful CI run on main branch" |
| 59 | + exit 1 |
| 60 | + } |
| 61 | + |
| 62 | + Write-Host "Found run ID: $result" -ForegroundColor Green |
| 63 | + return $result |
| 64 | +} |
| 65 | + |
| 66 | +function Download-SDK { |
| 67 | + param( |
| 68 | + [Parameter(Mandatory)] |
| 69 | + [string]$Name, |
| 70 | + [Parameter(Mandatory)] |
| 71 | + [string]$Destination, |
| 72 | + [Parameter(Mandatory)] |
| 73 | + [string]$RunId |
| 74 | + ) |
| 75 | + |
| 76 | + Write-Host "Downloading $Name SDK..." -ForegroundColor Yellow |
| 77 | + |
| 78 | + # Remove existing directory if present (partial download) |
| 79 | + if (Test-Path $Destination) { |
| 80 | + Write-Host " Removing existing directory..." -ForegroundColor Gray |
| 81 | + Remove-Item -Path $Destination -Recurse -Force |
| 82 | + } |
| 83 | + |
| 84 | + $artifactName = "$Name-sdk" |
| 85 | + gh run download $RunId -n $artifactName -D $Destination |
| 86 | + |
| 87 | + if ($LASTEXITCODE -ne 0) { |
| 88 | + Write-Error "Failed to download $Name SDK" |
| 89 | + exit 1 |
| 90 | + } |
| 91 | + |
| 92 | + Write-Host " Downloaded $Name SDK successfully" -ForegroundColor Green |
| 93 | +} |
| 94 | + |
| 95 | +# Main logic |
| 96 | +Write-Host "Checking native SDK status..." -ForegroundColor Cyan |
| 97 | +Write-Host "" |
| 98 | + |
| 99 | +$sdksToDownload = @() |
| 100 | + |
| 101 | +foreach ($sdk in $SDKs) { |
| 102 | + if (Test-SDKPresent $sdk) { |
| 103 | + Write-Host "$($sdk.Name) SDK already present, skipping download." -ForegroundColor Green |
| 104 | + } |
| 105 | + else { |
| 106 | + Write-Host "$($sdk.Name) SDK not found, will download." -ForegroundColor Yellow |
| 107 | + $sdksToDownload += $sdk |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +Write-Host "" |
| 112 | + |
| 113 | +if ($sdksToDownload.Count -eq 0) { |
| 114 | + Write-Host "All native SDKs are already present." -ForegroundColor Green |
| 115 | + exit 0 |
| 116 | +} |
| 117 | + |
| 118 | +# Fetch run ID only if we need to download something |
| 119 | +$runId = Get-LatestSuccessfulRunId |
| 120 | + |
| 121 | +foreach ($sdk in $sdksToDownload) { |
| 122 | + Download-SDK -Name $sdk.Name -Destination $sdk.Destination -RunId $runId |
| 123 | +} |
| 124 | + |
| 125 | +Write-Host "" |
| 126 | +Write-Host "Restoring package-dev/Plugins to latest git commit..." -ForegroundColor Yellow |
| 127 | +Push-Location $RepoRoot |
| 128 | +try { |
| 129 | + git restore package-dev/Plugins |
| 130 | +} |
| 131 | +finally { |
| 132 | + Pop-Location |
| 133 | +} |
| 134 | + |
| 135 | +Write-Host "" |
| 136 | +Write-Host "Native SDK download completed successfully!" -ForegroundColor Green |
0 commit comments