Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions integration-test/cli.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,40 @@ Describe 'Console apps (<framework>) - release creation' -ForEach @(
chmod +x $cliStub
}

function BuildWithSentryCLIStub([string[]] $properties, [string] $extraSource)
function NewSentryCLIStubFailingInfo([string] $cliError)
{
if ($IsWindows)
{
$stub = Join-Path $PSScriptRoot 'release-app' 'sentry-cli-failing.cmd'
"@echo %* >> `"$cliLog`"`n@if `"%1`"==`"info`" (echo $cliError 1>&2 & exit 1)" | Set-Content $stub
}
else
{
$stub = Join-Path $PSScriptRoot 'release-app' 'sentry-cli-failing.sh'
"#!/bin/sh`necho `"`$*`" >> `"$cliLog`"`nif [ `"`$1`" = info ]; then echo '$cliError' >&2; exit 1; fi" | Set-Content $stub
chmod +x $stub
}
$stub
}

function BuildWithSentryCLIStub([string[]] $properties, [string] $extraSource, [string] $stub = $cliStub)
{
Remove-Item $cliLog -ErrorAction SilentlyContinue
$extraSourcePath = Join-Path $PSScriptRoot 'release-app' 'Extra.cs'
if ($extraSource)
{
$extraSource | Set-Content $extraSourcePath
}
# Not /p:SentryCLI, because the targets can't clear a global property when the CLI isn't configured
$env:SentryCLI = $stub
try
{
$output = dotnet build release-app -c Release --nologo --framework $framework /p:SentryCLI=$cliStub @properties | ForEach-Object { Write-Host " $_"; $_ }
$output = dotnet build release-app -c Release --nologo --framework $framework @properties | ForEach-Object { Write-Host " $_"; $_ }
$LASTEXITCODE | Should -Be 0
}
finally
{
Remove-Item env:SentryCLI
Remove-Item $extraSourcePath -ErrorAction SilentlyContinue
}
[pscustomobject]@{
Expand Down Expand Up @@ -145,6 +164,16 @@ Describe 'Console apps (<framework>) - release creation' -ForEach @(
$calls | Should -AnyElementMatch '^releases new release-app@1\.2\.3\+abcdef\s*$'
$calls | Should -AnyElementMatch '^releases set-commits --auto release-app@1\.2\.3\+abcdef\s*$'
}

It "skips uploads and release creation without failing the build when <reason>" -ForEach @(
@{ reason = 'there is no auth token'; cliError = 'error: Auth token is required for this request.'; expected = 'The Sentry CLI is not fully configured' }
@{ reason = 'the Sentry API request fails'; cliError = 'error: API request failed'; expected = 'warning : Sentry API request failed' }
) {
$result = BuildWithSentryCLIStub '/p:SentryCreateRelease=true', '/p:SentryUploadSymbols=true' -stub (NewSentryCLIStubFailingInfo $cliError)
$result.Output | Should -AnyElementMatch $expected
$result.CliCalls | Should -HaveCount 1
$result.CliCalls | Should -AnyElementMatch '^info\b'
}
}

Describe 'Console apps (<framework>) - native AOT publish' -ForEach @(
Expand Down
7 changes: 4 additions & 3 deletions src/Sentry/buildTransitive/Sentry.targets
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
<_SentryCLICommand>$(SentryCLIBaseCommand) info</_SentryCLICommand>
<_SentryCLICommand Condition="'$(SentryOrg)' != '' And '$(SentryProject)' != ''">$(_SentryCLICommand) --no-defaults</_SentryCLICommand>
</PropertyGroup>
<Exec Condition="'$(SentryCLI)' != ''" Command="$(_SentryCLICommand)" IgnoreExitCode="true" ConsoleToMsBuild="true" StandardOutputImportance="Low">
<Exec Condition="'$(SentryCLI)' != ''" Command="$(_SentryCLICommand)" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true"
ConsoleToMsBuild="true" StandardOutputImportance="Low" StandardErrorImportance="Normal">
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
<Output TaskParameter="ConsoleOutput" PropertyName="_SentryCLIOutput" />
</Exec>
Expand All @@ -146,10 +147,10 @@
<_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." />
Text="Sentry API request failed. Either the authentication info is invalid, or the Sentry server could not be reached. Skipping Sentry uploads and release creation." />

<Message Importance="High" Condition="'$(_SentryCLIExitCode)' != '0' And '$(_SentryCLIRequestFailed)' == ''"
Text="The Sentry CLI is not fully configured with authentication, organization, and project." />
Text="The Sentry CLI is not fully configured with authentication, organization, and project. Skipping Sentry uploads and release creation." />
<PropertyGroup Condition="'$(_SentryCLIExitCode)' != '0'">
<SentryCLI />
</PropertyGroup>
Expand Down
Loading