From 95e67f6c67f8d8c089c80138918e9f9671d2f113 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 2 Jan 2026 11:49:06 +0100 Subject: [PATCH 1/3] feat: add InvokeSentryResult::Events() to extract events from envelopes --- sentry-cli/integration-test/action.psm1 | 30 +++++++++++++++++++ .../integration-test/tests/action.Tests.ps1 | 21 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/sentry-cli/integration-test/action.psm1 b/sentry-cli/integration-test/action.psm1 index 73b2fbf..0b67ff4 100644 --- a/sentry-cli/integration-test/action.psm1 +++ b/sentry-cli/integration-test/action.psm1 @@ -39,6 +39,36 @@ class InvokeSentryResult return $envelopes } + # Events are extracted from envelopes, each event body as single item. + # Note: Unlike Envelopes(), this method discards potential duplicates based on event_id. + [string[]]Events() + { + $ids = @() + $events = @() + foreach ($envelope in $this.Envelopes()) + { + $lines = @($envelope -split "\\n") + try + { + $header = $lines[0].Trim() | ConvertFrom-Json + if ($header.event_id -and $ids -notcontains $header.event_id) + { + $body = $lines | Select-Object -Skip 1 | Where-Object { + try { ($_ | ConvertFrom-Json).event_id -eq $header.event_id } + catch { $false } + } | Select-Object -First 1 + if ($body) + { + $ids += $header.event_id + $events += $body + } + } + } + catch { } + } + return $events + } + [bool]HasErrors() { return $this.ServerStdErr.Length -gt 0 diff --git a/sentry-cli/integration-test/tests/action.Tests.ps1 b/sentry-cli/integration-test/tests/action.Tests.ps1 index 0c674bf..fa4de4e 100644 --- a/sentry-cli/integration-test/tests/action.Tests.ps1 +++ b/sentry-cli/integration-test/tests/action.Tests.ps1 @@ -97,4 +97,25 @@ helloworld $result.Envelopes().Length | Should -Be 1 $result.Envelopes()[0].Length | Should -Be 357 } + + It "discards duplicate events" { + $result = Invoke-SentryServer { + param([string]$url) + Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @' +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:38.929Z"} +{"type":"event","length":47,"content_type":"application/json"} +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"} +'@ + Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @' +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:41.505Z"} +{"type":"event","length":47,"content_type":"application/json"} +{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"} +'@ + } + + Should -ActualValue $result.HasErrors() -BeFalse + $result.Envelopes().Length | Should -Be 2 + $result.Events().Length | Should -Be 1 + $result.Events()[0].Length | Should -Be 47 + } } From 31c07ee8dd077cbbce5cc7ae3f76cd5bd5aa4724 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 2 Jan 2026 15:02:11 +0100 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 503181a..c52c4c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Add `extra-install-packages` input to install additional apt packages required by custom dangerfiles - Custom dangerfiles receive full Danger API access (`fail`, `warn`, `message`, `markdown`, `danger`) - Enables repositories to extend Danger checks without overwriting shared workflow comments +- Sentry-CLI integration test action - Add `InvokeSentryResult::Events()` method to extract events from envelopes ([#137](https://github.com/getsentry/github-workflows/pull/137)) ## 3.1.0 From b8b8f54e86b141573b9e932852d46e161d99c7ad Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 5 Jan 2026 13:14:14 +0100 Subject: [PATCH 3/3] Replace try-catch blocks with -ErrorAction SilentlyContinue --- sentry-cli/integration-test/action.psm1 | 22 ++++++++----------- .../integration-test/tests/action.Tests.ps1 | 7 +++++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/sentry-cli/integration-test/action.psm1 b/sentry-cli/integration-test/action.psm1 index 0b67ff4..f385a93 100644 --- a/sentry-cli/integration-test/action.psm1 +++ b/sentry-cli/integration-test/action.psm1 @@ -48,23 +48,19 @@ class InvokeSentryResult foreach ($envelope in $this.Envelopes()) { $lines = @($envelope -split "\\n") - try + $header = $lines[0].Trim() | ConvertFrom-Json + $eventId = $header | Select-Object -ExpandProperty event_id -ErrorAction SilentlyContinue + if ($eventId -and $ids -notcontains $eventId) { - $header = $lines[0].Trim() | ConvertFrom-Json - if ($header.event_id -and $ids -notcontains $header.event_id) + $body = $lines | Select-Object -Skip 1 | Where-Object { + ($_ | ConvertFrom-Json | Select-Object -ExpandProperty event_id -ErrorAction SilentlyContinue) -eq $eventId + } | Select-Object -First 1 + if ($body) { - $body = $lines | Select-Object -Skip 1 | Where-Object { - try { ($_ | ConvertFrom-Json).event_id -eq $header.event_id } - catch { $false } - } | Select-Object -First 1 - if ($body) - { - $ids += $header.event_id - $events += $body - } + $ids += $eventId + $events += $body } } - catch { } } return $events } diff --git a/sentry-cli/integration-test/tests/action.Tests.ps1 b/sentry-cli/integration-test/tests/action.Tests.ps1 index fa4de4e..2bab19a 100644 --- a/sentry-cli/integration-test/tests/action.Tests.ps1 +++ b/sentry-cli/integration-test/tests/action.Tests.ps1 @@ -102,6 +102,11 @@ helloworld $result = Invoke-SentryServer { param([string]$url) Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @' +{"dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:52:42.924Z"} +{"type":"session","length":42} +{"sid":"66356dadc138458a8d5cd9e258065175"} +'@ + Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @' {"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:38.929Z"} {"type":"event","length":47,"content_type":"application/json"} {"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"} @@ -114,7 +119,7 @@ helloworld } Should -ActualValue $result.HasErrors() -BeFalse - $result.Envelopes().Length | Should -Be 2 + $result.Envelopes().Length | Should -Be 3 $result.Events().Length | Should -Be 1 $result.Events()[0].Length | Should -Be 47 }