|
37 | 37 | <!-- Set defaults for the Sentry properties. -->
|
38 | 38 | <SentryUploadSymbols Condition="'$(SentryUploadSymbols)' == ''">false</SentryUploadSymbols>
|
39 | 39 | <SentryUploadSources Condition="'$(SentryUploadSources)' == ''">false</SentryUploadSources>
|
| 40 | + <SentrySetCommits Condition="'$(SentrySetCommits)' == ''">false</SentrySetCommits> |
| 41 | + <!-- SentryCreateRelease is implied if SentrySetCommits==true --> |
| 42 | + <SentryCreateRelease Condition="'$(SentrySetCommits)' == 'true'">true</SentryCreateRelease> |
| 43 | + <SentryCreateRelease Condition="'$(SentryCreateRelease)' == ''">false</SentryCreateRelease> |
40 | 44 |
|
41 | 45 | <!-- This property controls if the Sentry CLI is to be used at all. Setting false will disable all Sentry CLI usage.
|
42 | 46 | We're explicitly skipping uploads for Sentry projects because they interfere with CLI integration test asserts. -->
|
43 | 47 | <UseSentryCLI Condition="
|
44 | 48 | '$(UseSentryCLI)' == ''
|
45 |
| - and ('$(SentryUploadSymbols)' == 'true' or '$(SentryUploadSources)' == 'true' or $(SentryUploadAndroidProguardMapping) == 'true') |
| 49 | + and ('$(SentryUploadSymbols)' == 'true' or '$(SentryUploadSources)' == 'true' or $(SentryUploadAndroidProguardMapping) == 'true' or $(SentryCreateRelease) == 'true' or $(SentrySetCommits) == 'true') |
46 | 50 | and '$(MSBuildProjectName)' != 'Sentry'
|
47 | 51 | and !$(MSBuildProjectName.StartsWith('Sentry.'))">true</UseSentryCLI>
|
48 | 52 | </PropertyGroup>
|
|
92 | 96 | <SentryCLIBaseCommand>"$(SentryCLI)"</SentryCLIBaseCommand>
|
93 | 97 | <SentryCLIBaseCommand Condition="'$(SentryCLIBaseOptions.Trim())' != ''">$(SentryCLIBaseCommand) $(SentryCLIBaseOptions.Trim())</SentryCLIBaseCommand>
|
94 | 98 |
|
| 99 | + <SentryReleaseOptions Condition="'$(SentryProject)' != ''">$(SentryReleaseOptions) --project $(SentryProject)</SentryReleaseOptions> |
| 100 | + <SentrySetCommitOptions Condition="'$(SentrySetCommitOptions)' == ''">--auto</SentrySetCommitOptions> |
| 101 | + |
95 | 102 | <SentryCLIUploadOptions Condition="'$(SentryOrg)' != ''">$(SentryCLIUploadOptions) --org $(SentryOrg)</SentryCLIUploadOptions>
|
96 | 103 | <SentryCLIUploadOptions Condition="'$(SentryProject)' != ''">$(SentryCLIUploadOptions) --project $(SentryProject)</SentryCLIUploadOptions>
|
97 | 104 | <SentryCLIDebugFilesUploadCommand>$(SentryCLIBaseCommand) debug-files upload</SentryCLIDebugFilesUploadCommand>
|
|
242 | 249 | <Warning Condition="'$(_SentryCLIExitCode)' != '0'" Text="Sentry CLI could not upload proguard mapping." />
|
243 | 250 | </Target>
|
244 | 251 |
|
| 252 | + <UsingTask TaskName="SentryGetApplicationVersion" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 253 | + <ParameterGroup> |
| 254 | + <AssemblyPath Required="true" /> |
| 255 | + <Release Output="true" /> |
| 256 | + </ParameterGroup> |
| 257 | + <Task> |
| 258 | + <Using Namespace="System"/> |
| 259 | + <Using Namespace="System.Reflection"/> |
| 260 | + <Code Type="Fragment" Language="cs"> |
| 261 | + <![CDATA[ |
| 262 | + try |
| 263 | + { |
| 264 | +#nullable enable |
| 265 | + Log.LogMessage($"Loading assembly: {AssemblyPath}"); |
| 266 | + var path = Path.GetFullPath(AssemblyPath); |
| 267 | + var assembly = Assembly.LoadFile(path); |
| 268 | +
|
| 269 | + Log.LogMessage($"Getting assembly name..."); |
| 270 | + var assemblyName = assembly.GetName(); |
| 271 | + var name = assemblyName.Name; |
| 272 | + Log.LogMessage($"Assembly name: {name}"); |
| 273 | +
|
| 274 | + Log.LogMessage($"Reading AssemblyInformationalVersionAttribute..."); |
| 275 | + string? version = null; |
| 276 | + try |
| 277 | + { |
| 278 | + var infoVersionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); |
| 279 | + version = infoVersionAttribute?.InformationalVersion; |
| 280 | + } |
| 281 | + catch |
| 282 | + { |
| 283 | + Log.LogMessage($"Failed to read informational version attribute"); |
| 284 | + } |
| 285 | + version ??= assemblyName.Version?.ToString(); |
| 286 | + Log.LogMessage($"Version: {version}"); |
| 287 | +
|
| 288 | + Log.LogMessage($"Compiling release information..."); |
| 289 | + if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(version)) |
| 290 | + { |
| 291 | + Release = version.Contains('@') |
| 292 | + ? version // Don't add name prefix if it's already set by the user |
| 293 | + : $"{name}@{version}"; |
| 294 | + } |
| 295 | +#nullable disable |
| 296 | + } |
| 297 | + catch |
| 298 | + { |
| 299 | + Log.LogWarning($"Failed to get version from {AssemblyPath}"); |
| 300 | + } |
| 301 | + ]]> |
| 302 | + </Code> |
| 303 | + </Task> |
| 304 | + </UsingTask> |
| 305 | + |
| 306 | + <PropertyGroup> |
| 307 | + <!-- Check if the release has been provided as an environment variable --> |
| 308 | + <_SentryRelease Condition="'$(_SentryRelease)' == '' And '$(SENTRY_RELEASE)' != ''">$(SENTRY_RELEASE)</_SentryRelease> |
| 309 | + </PropertyGroup> |
| 310 | + |
| 311 | + <Target Name="_GetSentryRelease" AfterTargets="DispatchToInnerBuilds;AfterBuild" Condition="'$(SentryCreateRelease)' == 'true' And '$(UseSentryCLI)' == 'true'"> |
| 312 | + |
| 313 | + <Message Importance="High" Text="Getting Sentry Release..." /> |
| 314 | + |
| 315 | + <SentryGetApplicationVersion Condition="'$(_SentryRelease)' == ''" AssemblyPath="$(IntermediateOutputPath)$(TargetName)$(TargetExt)"> |
| 316 | + <Output TaskParameter="Release" PropertyName="_SentryRelease" /> |
| 317 | + </SentryGetApplicationVersion> |
| 318 | + |
| 319 | + <Exec ConsoleToMSBuild="true" Condition="'$(_SentryRelease)' == ''" |
| 320 | + Command="sentry-cli releases propose-version"> |
| 321 | + <Output TaskParameter="ConsoleOutput" PropertyName="_SentryRelease"/> |
| 322 | + </Exec> |
| 323 | + |
| 324 | + <Message Importance="High" Text="Sentry Release: $(_SentryRelease)" /> |
| 325 | + </Target> |
| 326 | + |
| 327 | + <!-- Set release information after the build --> |
| 328 | + <Target Name="_CreateSentryRelease" AfterTargets="Build" DependsOnTargets="_GetSentryRelease" |
| 329 | + Condition="'$(SentryCLI)' != '' and '$(SentryCreateRelease)' == 'true'"> |
| 330 | + <Message Importance="High" Text="Creating Sentry Release: $(_SentryRelease)" /> |
| 331 | + <Exec |
| 332 | + Command="$(SentryCLIBaseCommand) releases new '$(_SentryRelease)' $(SentryReleaseOptions)" |
| 333 | + IgnoreExitCode="true" ContinueOnError="WarnAndContinue"> |
| 334 | + <Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" /> |
| 335 | + </Exec> |
| 336 | + </Target> |
| 337 | + |
| 338 | + <!-- Send commit details to Sentry --> |
| 339 | + <Target Name="_SentrySetCommits" AfterTargets="Build" DependsOnTargets="_CreateSentryRelease" |
| 340 | + Condition="'$(SentryCLI)' != '' and '$(SentrySetCommits)' == 'true'"> |
| 341 | + <Message Importance="High" Text="Setting Sentry commits" /> |
| 342 | + <Exec |
| 343 | + Command="$(SentryCLIBaseCommand) releases set-commits $(SentrySetCommitOptions) '$(_SentryRelease)' $(SentryReleaseOptions)" |
| 344 | + IgnoreExitCode="true" ContinueOnError="WarnAndContinue"> |
| 345 | + <Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" /> |
| 346 | + </Exec> |
| 347 | + </Target> |
| 348 | + |
245 | 349 | <Import Condition="'$(MSBuildProjectName)' != 'Sentry' and !$(MSBuildProjectName.StartsWith('Sentry.')) and '$(IsSentryTestProject)' == ''" Project="$(MSBuildThisFileDirectory)Sentry.Native.targets"/>
|
246 | 350 | </Project>
|
0 commit comments