Skip to content

Commit

Permalink
Use Sentry CLI after build to upload symbols (#2107)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Jan 10, 2023
1 parent 6e1cdd6 commit 6b17e2c
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ docs/docfx.zip
mono_crash.*.json
test_output/
test/**/*.apk
/tools/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Use Sentry CLI after build to upload symbols ([#2107](https://github.com/getsentry/sentry-dotnet/pull/2107))

### Fixes

- Logging info instead of warning when skipping debug images ([#2101](https://github.com/getsentry/sentry-dotnet/pull/2101))
Expand Down
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsings.cs" />
</ItemGroup>

<!-- Set the version and local path for Sentry CLI (downloaded in the restore phase of Sentry.csproj) -->
<PropertyGroup Condition="'$(SolutionName)' != 'Sentry.Unity'">
<SentryCLIVersion>2.11.0</SentryCLIVersion>
<SentryCLIDirectory>$(MSBuildThisFileDirectory)tools\sentry-cli\$(SentryCLIVersion)\</SentryCLIDirectory>
</PropertyGroup>

</Project>
7 changes: 4 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@
</Target>

<!--
This is needed because we use project references in this solution.
In an app that uses our nuget packages, it will come through the nuget package automatically.
These are needed because we use project references in this solution.
In an app that uses our nuget packages, they will come through the nuget packages automatically.
-->
<Import Project="$(MSBuildThisFileDirectory)src\Sentry\buildTransitive\Sentry.props" />
<Import Project="$(MSBuildThisFileDirectory)src\Sentry.Bindings.Cocoa\buildTransitive\Sentry.Bindings.Cocoa.targets"
Condition="'$(OutputType)' == 'Exe' And ('$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst')" />
Condition="'$(OutputType)' == 'Exe' And ('$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst')" />

</Project>
38 changes: 38 additions & 0 deletions src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,42 @@
<None Include="buildTransitive\Sentry.props" Pack="true" PackagePath="build\Sentry.props" />
</ItemGroup>

<!-- Download the Sentry CLI during the restore phase. -->
<Target Name="DownloadSentryCLI" BeforeTargets="CollectPackageReferences" Condition="'$(SentryCLIDirectory)' != ''">

<!--
Hashes are from https://release-registry.services.sentry.io/apps/sentry-cli/latest
Update with each new version.
-->
<ItemGroup>
<SentryCLIDownload Include="sentry-cli-Darwin-arm64" FileHash="fbefb40a8e5ce29f82e0f7195e84f569dbeaaae07cdc1f983f5f3418fd9a376d" />
<SentryCLIDownload Include="sentry-cli-Darwin-x86_64" FileHash="d55ee5636d12bd193a4f526ab426e6af6273bec5bc2dc22e81dc8357d6e039eb" />
<SentryCLIDownload Include="sentry-cli-Linux-aarch64" FileHash="c62c5c1259307611e78af4f24a4c30162cff8adb0f021d363b307c42cded5c70" />
<SentryCLIDownload Include="sentry-cli-Linux-i686" FileHash="25c5e7e6d978d1e66bc26c9e4282633135a318ed0ac36cb73b4fa58f59fcb089" />
<SentryCLIDownload Include="sentry-cli-Linux-x86_64" FileHash="bc8f5f223fa688b3ad963c60a729f02aa8f5b17525de66fb3abf86800977ff6e" />
<SentryCLIDownload Include="sentry-cli-Windows-i686.exe" FileHash="2bb96fc94ea749e24cd607f48750b121572a3fb4b3f9499f63a996f83c56ef2b" />
<SentryCLIDownload Include="sentry-cli-Windows-x86_64.exe" FileHash="7b70536177419dcd2fdb2c823422290abfe25180ffa3beae000fb3c9b1473c1f"/>
</ItemGroup>

<!-- Download the files -->
<DownloadFile
SourceUrl="https://downloads.sentry-cdn.com/sentry-cli/$(SentryCLIVersion)/%(SentryCLIDownload.Identity)"
DestinationFolder="$(SentryCLIDirectory)"
Condition="!Exists('$(SentryCLIDirectory)%(Identity)')"
Retries="3">
<Output TaskParameter="DownloadedFile" ItemName="SentryCLIDownloadedFile" />
</DownloadFile>

<!-- Build will fail if any downloaded files don't match the expected hash. -->
<VerifyFileHash File="$(SentryCLIDirectory)%(SentryCLIDownload.Identity)" Hash="%(FileHash)" />

<!-- Set executable permissions for local usage. -->
<Exec Command="chmod +x $(SentryCLIDirectory)*" Condition="!$([MSBuild]::IsOSPlatform('Windows'))" />
</Target>

<!-- Bundle the Sentry CLI into the Sentry Nuget package. -->
<ItemGroup Condition="'$(SentryCLIDirectory)' != ''">
<None Include="$(SentryCLIDirectory)**" Pack="true" PackagePath="tools\" />
</ItemGroup>

</Project>
72 changes: 72 additions & 0 deletions src/Sentry/buildTransitive/Sentry.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,76 @@
ItemName="FileWrites" />
</WriteCodeFragment>
</Target>

<PropertyGroup>
<!-- Defaults for Sentry CLI are set here. Any of these properties can be set in the application to override the defaults. -->
<SentryUploadSymbols Condition="'$(SentryUploadSymbols)' == '' And '$(Configuration)' == 'Release' And '$(DebugType)' != 'embedded'">true</SentryUploadSymbols>
<!-- Additional properties can go here. For example, SentryCreateNewRelease, etc. -->

<!-- This property controls if the Sentry CLI is to be used at all. Setting false will disable all Sentry CLI usage. -->
<UseSentryCLI Condition="'$(UseSentryCLI)' == '' And ('$(SentryUploadSymbols)' == 'true')">true</UseSentryCLI>

<!--
The Sentry configuration can be set manually in MSBuild properties if desired.
Otherwise the default configuration will be used, as reported by "sentry-cli info".
The defaults can be set either via config file, or environment variables, per: https://docs.sentry.io/product/cli/configuration/
-->
<SentryCLIOptions Condition="'$(SentryApiKey)' != ''">$(SentryCLIOptions) --api-key $(SentryApiKey)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryAuthToken)' != ''">$(SentryCLIOptions) --auth-token $(SentryAuthToken)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryUrl)' != ''">$(SentryCLIOptions) --url $(SentryUrl)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryOrg)' != ''">$(SentryCLIOptions) --org '$(SentryOrg)'</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryProject)' != ''">$(SentryCLIOptions) --project '$(SentryProject)'</SentryCLIOptions>
</PropertyGroup>

<Target Name="_PrepareSentryCLI" AfterTargets="DispatchToInnerBuilds;AfterBuild" Condition="'$(UseSentryCLI)' == 'true'">
<!-- Sentry CLI comes from the Sentry Nuget package when installed. -->
<PropertyGroup Condition="'$(SentryCLIDirectory)' == ''">
<SentryCLIDirectory Condition="'$(PkgSentry)' != ''">$(PkgSentry)\tools\</SentryCLIDirectory>
</PropertyGroup>

<!--
Choose the correct Sentry CLI executable depending on OS platform and architecture.
For Windows on Arm64, we'll use the X64 build for now (which should run via emulation).
Switch to a Windows Arm64 build when available. See https://github.com/getsentry/sentry-cli/issues/1426
-->
<PropertyGroup Condition="'$(SentryCLI)' == '' And '$(SentryCLIDirectory)' != ''">
<_OSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</_OSArchitecture>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('OSX')) And $(_OSArchitecture) == 'Arm64'">$(SentryCLIDirectory)sentry-cli-Darwin-arm64</SentryCLI>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('OSX')) And $(_OSArchitecture) == 'X64'">$(SentryCLIDirectory)sentry-cli-Darwin-x86_64</SentryCLI>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Linux')) And $(_OSArchitecture) == 'Arm64'">$(SentryCLIDirectory)sentry-cli-Linux-aarch64</SentryCLI>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Linux')) And $(_OSArchitecture) == 'X86'">$(SentryCLIDirectory)sentry-cli-Linux-i686</SentryCLI>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Linux')) And $(_OSArchitecture) == 'X64'">$(SentryCLIDirectory)sentry-cli-Linux-x86_64</SentryCLI>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Windows')) And $(_OSArchitecture) == 'Arm64'">$(SentryCLIDirectory)sentry-cli-Windows-x86_64</SentryCLI>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Windows')) And $(_OSArchitecture) == 'X86'">$(SentryCLIDirectory)sentry-cli-Windows-i686</SentryCLI>
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Windows')) And $(_OSArchitecture) == 'X64'">$(SentryCLIDirectory)sentry-cli-Windows-x86_64</SentryCLI>
<SentryCLI Condition="!Exists('$(SentryCLI)')"/>
</PropertyGroup>

<PropertyGroup>
<_SentryCLIInfoOptions Condition="'$(SentryOrg)' != '' And '$(SentryProject)' != ''">--no-defaults</_SentryCLIInfoOptions>
</PropertyGroup>
<Exec Command="'$(SentryCLI)' info $(_SentryCLIInfoOptions)" Condition="'$(SentryCLI)' != ''" IgnoreExitCode="true" ConsoleToMsBuild="true" StandardOutputImportance="Low">
<Output TaskParameter="ExitCode" PropertyName="SentryCLIExitCode" />
<Output TaskParameter="ConsoleOutput" PropertyName="SentryCLIOutput" />
</Exec>

<PropertyGroup Condition="'$(SentryCLIExitCode)' != '0'">
<_SentryCLIRequestFailed Condition="$(SentryCLIOutput.Contains('API request failed'))">true</_SentryCLIRequestFailed>
</PropertyGroup>
<Warning Condition="'$(_SentryCLIRequestFailed)' != ''"
Text="Sentry API request failed. Either the authentication info is invalid, or the Sentry server could not be reached." />

<Message Importance="High" Condition="'$(SentryCLIExitCode)' != '0' And '$(_SentryCLIRequestFailed)' == ''"
Text="The Sentry CLI is not fully configured with authentication, organization, and project." />
<PropertyGroup Condition="'$(SentryCLIExitCode)' != '0'">
<SentryCLI />
</PropertyGroup>
</Target>

<!-- Upload symbols (and any other debug information files) to Sentry after the build. -->
<Target Name="UploadSymbolsToSentry" AfterTargets="AfterBuild" DependsOnTargets="_PrepareSentryCLI" Condition="'$(SentryUploadSymbols)' == 'true' And '$(SentryCLI)' != ''">
<Message Importance="High" Text="Preparing to upload debug symbols to Sentry for $(MSBuildProjectName) ($(Configuration)/$(TargetFramework))" />
<Exec Command="'$(SentryCLI)' upload-dif $(SentryCLIOptions) '$(IntermediateOutputPath)'" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 47,
"colno": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 47,
"colno": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 47,
"colno": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 47,
"colno": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 46,
"colno": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 46,
"colno": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 46,
"colno": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
Stacktrace: {
Frames: [
{,
"filename": ".../IntegrationTests.verify.cs",
"filename": "IntegrationTests.verify.cs",
"function": "Task IntegrationTests.Simple()",
"lineno": 46,
"colno": 17,
Expand Down
21 changes: 13 additions & 8 deletions test/Sentry.Testing/ApiExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !__MOBILE__
using System.Runtime.Versioning;
using PublicApiGenerator;

namespace Sentry.Testing;
Expand All @@ -9,20 +10,24 @@ public static Task CheckApproval(this Assembly assembly, [CallerFilePath] string
{
var generatorOptions = new ApiGeneratorOptions
{
ExcludeAttributes = new []
{
typeof(AssemblyVersionAttribute).FullName,
typeof(AssemblyFileVersionAttribute).FullName,
typeof(AssemblyInformationalVersionAttribute).FullName,
typeof(AssemblyMetadataAttribute).FullName,
typeof(InternalsVisibleToAttribute).FullName,
typeof(TargetFrameworkAttribute).FullName
},
WhitelistedNamespacePrefixes = new[] { "Sentry", "Microsoft" }
};
var apiText = assembly.GeneratePublicApi(generatorOptions);

// ReSharper disable once ExplicitCallerInfoArgument
return Verify(apiText, null, filePath)
.AutoVerify(includeBuildServer: false)
.UniqueForTargetFrameworkAndVersion()
.ScrubEmptyLines()
.ScrubLines(l =>
l.StartsWith("[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(") ||
l.StartsWith("[assembly: AssemblyVersion(") ||
l.StartsWith("[assembly: System.Runtime.Versioning.TargetFramework(") ||
l.StartsWith("[assembly: AssemblyFileVersion(") ||
l.StartsWith("[assembly: AssemblyInformationalVersion(") ||
l.StartsWith("[assembly: System.Reflection.AssemblyMetadata("));
.ScrubEmptyLines();
}
}
#endif
2 changes: 0 additions & 2 deletions test/Sentry.Tests/Sentry.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
<ProjectReference Include="..\Sentry.Testing.CrashableApp\Sentry.Testing.CrashableApp.csproj" />
</ItemGroup>

<Import Project="..\..\src\Sentry\buildTransitive\Sentry.props" />

</Project>

0 comments on commit 6b17e2c

Please sign in to comment.