Skip to content

Commit c21a176

Browse files
authored
feat: sentry-cli integration test scripts (#54)
1 parent 53d3e3f commit c21a176

17 files changed

+610
-50
lines changed

.github/workflows/updater-scripts-tests.yml renamed to .github/workflows/script-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# This isn't a reusable workflow but an actual CI action for this repo itself - to test scripts.
2-
name: Updater Script Tests
1+
# This isn't a reusable workflow but a CI action for this repo itself - testing the contained workflows & scripts.
2+
name: Script Tests
33

44
on:
55
push:
66

77
jobs:
8-
test:
9-
name: ${{ matrix.host }}
8+
updater:
9+
name: Updater @ ${{ matrix.host }}
1010
runs-on: ${{ matrix.host }}-latest
1111
strategy:
1212
fail-fast: false

.github/workflows/updater-workflow-tests.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/workflow-tests.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# This isn't a reusable workflow but an actual CI action for this repo itself - to test the workflows.
2+
name: Workflow Tests
3+
4+
on:
5+
push:
6+
7+
jobs:
8+
updater-create-pr:
9+
uses: ./.github/workflows/updater.yml
10+
with:
11+
path: updater/tests/sentry-cli.properties
12+
name: CLI
13+
pattern: '^2\.0\.'
14+
pr-strategy: update
15+
_workflow_version: ${{ github.sha }}
16+
secrets:
17+
api-token: ${{ github.token }}
18+
19+
updater-test-args:
20+
uses: ./.github/workflows/updater.yml
21+
with:
22+
path: updater/tests/workflow-args.sh
23+
name: Workflow args test script
24+
runs-on: macos-latest
25+
pattern: '.*'
26+
_workflow_version: ${{ github.sha }}
27+
secrets:
28+
api-token: ${{ github.token }}
29+
30+
updater-test-outputs:
31+
runs-on: ubuntu-latest
32+
needs:
33+
- updater-create-pr
34+
- updater-test-args
35+
steps:
36+
- run: "[[ '${{ needs.updater-create-pr.outputs.baseBranch }}' == 'main' ]]"
37+
- run: "[[ '${{ needs.updater-create-pr.outputs.originalTag }}' == '2.0.0' ]]"
38+
- run: "[[ '${{ needs.updater-create-pr.outputs.latestTag }}' =~ ^[0-9.]+$ ]]"
39+
- run: "[[ '${{ needs.updater-create-pr.outputs.prUrl }}' =~ ^https://github.com/getsentry/github-workflows/pull/[0-9]+$ ]]"
40+
- run: "[[ '${{ needs.updater-create-pr.outputs.prBranch }}' == 'deps/updater/tests/sentry-cli.properties' ]]"
41+
42+
- run: "[[ '${{ needs.updater-test-args.outputs.baseBranch }}' == '' ]]"
43+
- run: "[[ '${{ needs.updater-test-args.outputs.originalTag }}' == 'latest' ]]"
44+
- run: "[[ '${{ needs.updater-test-args.outputs.latestTag }}' == 'latest' ]]"
45+
- run: "[[ '${{ needs.updater-test-args.outputs.prUrl }}' == '' ]]"
46+
- run: "[[ '${{ needs.updater-test-args.outputs.prBranch }}' == '' ]]"
47+
48+
cli-integration:
49+
runs-on: ${{ matrix.host }}-latest
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
host:
54+
- ubuntu
55+
- macos
56+
- windows
57+
steps:
58+
- uses: actions/checkout@v3
59+
60+
- uses: ./sentry-cli/integration-test/
61+
with:
62+
path: sentry-cli/integration-test/tests/

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Sentry-CLI integration test action ([#54](https://github.com/getsentry/github-workflows/pull/54))
8+
39
## 2.6.0
410

511
### Features
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*-output.txt
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Executes the given block starting a dummy Sentry server that collects and logs requests.
2+
# The block is given the server URL as a first argument.
3+
# Returns the dummy server logs.
4+
5+
$ServerUri = "http://127.0.0.1:8000"
6+
7+
class InvokeSentryResult
8+
{
9+
[string[]]$ServerStdOut
10+
[string[]]$ServerStdErr
11+
[string[]]$ScriptOutput
12+
13+
# It is common to test debug files uploaded to the server so this function gives you a list.
14+
[string[]]UploadedDebugFiles()
15+
{
16+
$prefix = "upload-dif:"
17+
return @($this.ServerStdOut | Where-Object { $_.StartsWith($prefix) } | ForEach-Object { $_.Substring($prefix.Length).Trim() })
18+
}
19+
20+
[bool]HasErrors()
21+
{
22+
return $this.ServerStdErr.Length -gt 0
23+
}
24+
}
25+
26+
function IsNullOrEmpty([string] $value)
27+
{
28+
"$value".Trim().Length -eq 0
29+
}
30+
31+
function OutputToArray($output, [string] $uri = $null)
32+
{
33+
if ($output -isnot [system.array])
34+
{
35+
$output = ("$output".Trim() -replace "`r`n", "`n") -split "`n"
36+
}
37+
38+
if (!(IsNullOrEmpty $uri))
39+
{
40+
$output = $output -replace $uri, "<ServerUri>"
41+
}
42+
$output | ForEach-Object { "$_".Trim() }
43+
}
44+
45+
function RunApiServer([string] $ServerScript, [string] $Uri = $ServerUri)
46+
{
47+
$result = "" | Select-Object -Property process, outFile, errFile, stop, output, dispose
48+
Write-Host "Starting the $ServerScript on $Uri" -ForegroundColor DarkYellow
49+
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
50+
51+
$result.outFile = New-TemporaryFile
52+
$result.errFile = New-TemporaryFile
53+
54+
$result.process = Start-Process "python3" -ArgumentList @("$PSScriptRoot/$ServerScript.py", $Uri) `
55+
-NoNewWindow -PassThru -RedirectStandardOutput $result.outFile -RedirectStandardError $result.errFile
56+
57+
$out = New-Object InvokeSentryResult
58+
$out.ServerStdOut = @()
59+
$out.ServerStdErr = @()
60+
61+
# We must reassign functions as variables to make them available in a block scope together with GetNewClosure().
62+
$OutputToArray = { OutputToArray $args[0] $args[1] }
63+
$IsNullOrEmpty = { IsNullOrEmpty $args[0] }
64+
65+
$result.dispose = {
66+
$result.stop.Invoke()
67+
68+
$stdout = Get-Content $result.outFile -Raw
69+
Write-Host "Server stdout:" -ForegroundColor Yellow
70+
Write-Host $stdout
71+
72+
$out.ServerStdOut += & $OutputToArray $stdout $Uri
73+
74+
$stderr = Get-Content $result.errFile -Raw
75+
if (!(& $IsNullOrEmpty $stderr))
76+
{
77+
Write-Host "Server stderr:" -ForegroundColor Yellow
78+
Write-Host $stderr
79+
$out.ServerStdErr += & $OutputToArray $stderr $Uri
80+
}
81+
82+
Remove-Item $result.outFile -ErrorAction Continue
83+
Remove-Item $result.errFile -ErrorAction Continue
84+
return $out
85+
}.GetNewClosure()
86+
87+
$result.stop = {
88+
# Stop the HTTP server
89+
Write-Host "Stopping the $ServerScript ... " -NoNewline
90+
try
91+
{
92+
Write-Host (Invoke-WebRequest -Uri "$Uri/STOP").StatusDescription
93+
}
94+
catch
95+
{
96+
Write-Host "/STOP request failed: $_ - killing the server process instead"
97+
$result.process | Stop-Process -Force -ErrorAction SilentlyContinue
98+
}
99+
$result.process | Wait-Process -Timeout 10 -ErrorAction Continue
100+
$result.stop = {}
101+
}.GetNewClosure()
102+
103+
$startupFailed = $false
104+
while ($true)
105+
{
106+
Start-Sleep -Milliseconds 100
107+
try
108+
{
109+
if ((Invoke-WebRequest -Uri "$Uri/_check" -SkipHttpErrorCheck -Method Head).StatusCode -eq 999)
110+
{
111+
$msg = "Server started successfully in $($stopwatch.ElapsedMilliseconds) ms."
112+
Write-Host $additionalOutput -ForegroundColor Green
113+
$out.ServerStdOut += $msg
114+
break;
115+
}
116+
}
117+
catch
118+
{}
119+
if ($stopwatch.ElapsedMilliseconds -gt 60000)
120+
{
121+
$msg = "Server startup timed out."
122+
Write-Warning $msg
123+
$out.ServerStdErr += $msg
124+
$startupFailed = $true;
125+
break;
126+
}
127+
else
128+
{
129+
Write-Host "Waiting for server to become available..."
130+
}
131+
}
132+
133+
if ($result.process.HasExited -or $startupFailed)
134+
{
135+
$result.stop.Invoke()
136+
$result.dispose.Invoke()
137+
throw Write-Host "Couldn't start the $ServerScript"
138+
}
139+
140+
return $result
141+
}
142+
143+
function Invoke-SentryServer([ScriptBlock] $Callback)
144+
{
145+
# start the server
146+
$httpServer = RunApiServer "sentry-server"
147+
148+
$result = $null
149+
$output = $null
150+
try
151+
{
152+
# run the test
153+
$output = & $Callback $ServerUri
154+
}
155+
finally
156+
{
157+
$result = $httpServer.dispose.Invoke()[0]
158+
}
159+
160+
if ($null -ne $result)
161+
{
162+
$result.ScriptOutput = OutputToArray $output
163+
}
164+
return $result
165+
}
166+
167+
Export-ModuleMember -Function Invoke-SentryServer
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Sentry CLI integration test
2+
3+
description: |
4+
Action to test Sentry CLI integration & symbol upload. This action simply runs all the https://github.com/pester/Pester
5+
tests in the given directory. The tests can make use of a dummy Sentry server that collects uploaded symbols.
6+
This server is made available as a PowerShell module to your tests.
7+
8+
inputs:
9+
path:
10+
description: The directory containing all the tests.
11+
required: true
12+
13+
runs:
14+
using: composite
15+
16+
steps:
17+
- name: Run tests
18+
shell: pwsh
19+
run: |
20+
Import-Module -Name ${{ github.action_path }}/action.psm1 -Force
21+
Invoke-Pester -Output Detailed '${{ inputs.path }}'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "fixture-id",
3+
"sha1": "fixture-sha1",
4+
"name": "fixture-name",
5+
"size": 1,
6+
"dist": null,
7+
"headers": {
8+
"fixture-header-key": "fixture-header-value"
9+
}
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"id": "6796495645",
4+
"name": "~/dist/bundle.min.js",
5+
"dist": "foo",
6+
"headers": {
7+
"Sourcemap": "dist/bundle.min.js.map"
8+
},
9+
"size": 497,
10+
"sha1": "2fb719956748ab7ec5ae9bcb47606733f5589b72",
11+
"dateCreated": "2022-05-12T11:08:01.520199Z"
12+
},
13+
{
14+
"id": "6796495646",
15+
"name": "~/dist/bundle.min.js.map",
16+
"dist": "foo",
17+
"headers": {},
18+
"size": 1522,
19+
"sha1": "f818059cbf617a8fae9b4e46d08f6c0246bb1624",
20+
"dateCreated": "2022-05-12T11:08:01.496220Z"
21+
}
22+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"associatedDsymFiles": [
3+
{
4+
"uuid": null,
5+
"debugId": null,
6+
"objectName": "fixture-objectName",
7+
"cpuName": "fixture-cpuName",
8+
"sha1": "fixture-sha1",
9+
"data": {
10+
"type": null,
11+
"features": [
12+
"fixture-feature"
13+
]
14+
}
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)