Skip to content

Commit 32bcae0

Browse files
authored
chore: Make native SDK download conditional (#2482)
1 parent 6333bbf commit 32bcae0

File tree

3 files changed

+151
-21
lines changed

3 files changed

+151
-21
lines changed

Agents.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,20 @@ Supported platforms: `macOS`, `Windows`, `Linux`, `Android`, `iOS`, `WebGL`
534534

535535
### Development Workflow
536536

537+
**Prerequisites (first-time setup or after clean):**
538+
```bash
539+
# Download native SDKs - REQUIRED before building
540+
dotnet msbuild /t:DownloadNativeSDKs src/Sentry.Unity
541+
```
542+
543+
**Development cycle:**
537544
1. Make changes to source code in `src/`
538545
2. Run `dotnet build` to build and update `package-dev/`
539-
3. Test changes using the sample project or integration tests
540-
4. Run `pwsh scripts/repack.ps1` before creating releases
546+
3. Run `pwsh scripts/run-tests.ps1` to build and run all tests
547+
4. Test changes using the sample project or integration tests
548+
5. Run `pwsh scripts/repack.ps1` before creating releases
549+
550+
> **Note:** The native SDKs in `package-dev/Plugins/` are not committed to the repository. You must run `DownloadNativeSDKs` before the first build or after cleaning the repository.
541551
542552
### Error Handling Patterns
543553

Directory.Build.targets

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -484,27 +484,11 @@ File.WriteAllLines(PackageManifestFile, lines);
484484
</Target>
485485

486486
<!-- Downloads native SDKs from the latest successful GitHub Actions workflow run.
487+
Only downloads SDKs that are not already present.
487488
This is meant for developers - so that they don't have to compile the native SDK after each clean checkout (or git clean).
488-
Depends on your a GH CLI installation - https://cli.github.com/
489+
Depends on a GH CLI installation - https://cli.github.com/
489490
dotnet msbuild /t:DownloadNativeSDKs src/Sentry.Unity -->
490491
<Target Name="DownloadNativeSDKs" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity'">
491-
<Message Importance="High" Text="Downloading pre-compiled native SDKs from GitHub Actions artifacts." />
492-
<Exec ConsoleToMSBuild="true" Command="gh run list --branch main --workflow CI --json &quot;conclusion,databaseId&quot; --jq &quot;first(.[] | select(.conclusion == \&quot;success\&quot;) | .databaseId)&quot;">
493-
<Output TaskParameter="ConsoleOutput" PropertyName="LastSuccessfulRunId" />
494-
</Exec>
495-
<Error Condition="!('$(LastSuccessfulRunId)' > 0)" Text="Failed to find a successful run" />
496-
497-
<ItemGroup>
498-
<SDK Include="Windows"/>
499-
<SDK Include="Android"/>
500-
<SDK Include="Linux"/>
501-
</ItemGroup>
502-
<Message Importance="High" Text="Replacing $(SentryArtifactsDestination)%(SDK.Identity)" />
503-
<RemoveDir Directories="$(SentryArtifactsDestination)%(SDK.Identity)" />
504-
<Exec Command="gh run download $(LastSuccessfulRunId) -n &quot;%(SDK.Identity)-sdk&quot; -D &quot;$(SentryArtifactsDestination)%(SDK.Identity)&quot;" />
505-
506-
<!-- Download overwrites some files that then show up as changed in the IDE, even though there are no changes, e.g. only whitespace -->
507-
<Message Importance="High" Text="Restoring package-dev/Plugins to the latest git commit" />
508-
<Exec WorkingDirectory="$(RepoRoot)" Command="git restore package-dev/Plugins" />
492+
<Exec Command="pwsh &quot;$(RepoRoot)scripts/download-native-sdks.ps1&quot; -RepoRoot &quot;$(RepoRoot)&quot;" />
509493
</Target>
510494
</Project>

scripts/download-native-sdks.ps1

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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

Comments
 (0)