Skip to content

Commit bde8b9e

Browse files
authored
chore: Automate setting Apple Team ID for sample (#2124)
1 parent e3e75a9 commit bde8b9e

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

Directory.Build.targets

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,19 @@ void PrintFailedTests(XElement element)
571571
<!-- Checks if the environment variable 'SENTRY_AUTH_TOKEN' has been set and creates the SentryCliOptions.asset for the sample project
572572
This is meant for developers - so they don't have to configure the CLI options after each clean checkout (or git clean).
573573
Gets automatically run after 'DownloadNativeSDKs'
574-
dotnet msbuild /t:SetupSampleSentryCliOptions src/Sentry.Unity -->
575-
<Target Name="SetupSampleSentryCliOptions" AfterTargets="DownloadNativeSDKs" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity' AND '$(SENTRY_AUTH_TOKEN)' != ''">
574+
dotnet msbuild /t:SamplesSetupCliOptions src/Sentry.Unity -->
575+
<Target Name="SamplesSetupCliOptions" AfterTargets="DownloadNativeSDKs" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity' AND '$(SENTRY_AUTH_TOKEN)' != ''">
576576
<Message Importance="High" Text="Found environment variable 'SENTRY_AUTH_TOKEN'. Creating Sentry CLI options for sample project. " />
577-
<Exec Command="pwsh &quot;$(RepoRoot)scripts/create-sentry-cli-options.ps1&quot;"/>
577+
<Exec Command="pwsh &quot;$(RepoRoot)scripts/samples-setup-cli-options.ps1&quot;"/>
578+
</Target>
579+
580+
<!-- Checks if the environment variable 'APPLE_ID' has been set and modifies the ProjectSettings.asset for the sample project
581+
This is meant for developers - so they don't have to configure the playersettings after each clean checkout (or git clean).
582+
Gets automatically run after 'SamplesSetupCliOptions'
583+
dotnet msbuild /t:SamplesSetupAppleId src/Sentry.Unity -->
584+
<Target Name="SamplesSetupAppleId" AfterTargets="SetupSampleSentryCliOptions" Condition="'$(MSBuildProjectName)' == 'Sentry.Unity' AND '$(APPLE_ID)' != ''">
585+
<Message Importance="High" Text="Found environment variable 'APPLE_ID'. Setting Apple ID for sample project. " />
586+
<Exec Command="pwsh &quot;$(RepoRoot)scripts/samples-setup-apple-id.ps1&quot;"/>
578587
</Target>
579588

580589
<!-- Downloads native SDKs from the latest successful GitHub Actions workflow run.

scripts/samples-setup-apple-id.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Set-StrictMode -Version latest
2+
$ErrorActionPreference = "Stop"
3+
4+
Write-Output "Setting up Apple Developer Team ID from environment variable"
5+
6+
if (-not $Env:APPLE_ID)
7+
{
8+
Write-Error "APPLE_ID environment variable is not set. Skipping..."
9+
exit
10+
}
11+
12+
$appleId = $Env:APPLE_ID
13+
$projectSettingsPath = "$PSScriptRoot/../samples/unity-of-bugs/ProjectSettings/ProjectSettings.asset"
14+
if (-not (Test-Path -Path $projectSettingsPath))
15+
{
16+
Write-Error "ProjectSettings.asset not found at path: $projectSettingsPath"
17+
exit
18+
}
19+
20+
$content = Get-Content -Path $projectSettingsPath -Raw
21+
if ($content -match '(\s*)appleDeveloperTeamID:.*')
22+
{
23+
$updatedContent = $content -replace '(\s*)appleDeveloperTeamID:.*', "`${1}appleDeveloperTeamID: $appleId"
24+
Set-Content -Path $projectSettingsPath -Value $updatedContent
25+
Write-Output "Successfully updated appleDeveloperTeamID in ProjectSettings.asset"
26+
}
27+
else
28+
{
29+
Write-Error "Could not find appleDeveloperTeamID property in ProjectSettings.asset"
30+
exit
31+
}

0 commit comments

Comments
 (0)