-
Notifications
You must be signed in to change notification settings - Fork 2
556 lines (480 loc) · 20.2 KB
/
test-scripts.yml
File metadata and controls
556 lines (480 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
name: Test Scripts - Mac, Linux and Windows
permissions:
contents: read
on:
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
pull_request:
branches:
- main
workflow_dispatch:
jobs:
test-mac:
name: Test mac/run.sh on macOS
# if: false
runs-on: macos-latest
timeout-minutes: 15
environment: BrowserStack
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set up Bash
run: |
echo "Bash version:"
bash --version
- name: Validate shell script syntax
run: |
echo "Validating mac/run.sh syntax..."
bash -n mac/run.sh
echo "✅ mac/run.sh syntax is valid"
- name: Validate supporting scripts syntax
run: |
echo "Validating supporting scripts..."
bash -n mac/common-utils.sh
bash -n mac/logging-utils.sh
bash -n mac/env-setup-run.sh
bash -n mac/user-interaction.sh
bash -n mac/env-prequisite-checks.sh
echo "✅ All supporting scripts are valid"
- name: Check if scripts are executable
run: |
chmod +x mac/run.sh
chmod +x mac/common-utils.sh
chmod +x mac/logging-utils.sh
chmod +x mac/env-setup-run.sh
chmod +x mac/user-interaction.sh
chmod +x mac/env-prequisite-checks.sh
echo "✅ All scripts are executable"
- name: Run ShellCheck on mac scripts
run: |
brew install shellcheck
echo "Running ShellCheck on mac scripts..."
shellcheck -x mac/run.sh || true
shellcheck -x mac/common-utils.sh || true
shellcheck -x mac/logging-utils.sh || true
shellcheck -x mac/env-setup-run.sh || true
shellcheck -x mac/user-interaction.sh || true
shellcheck -x mac/env-prequisite-checks.sh || true
echo "✅ ShellCheck analysis complete"
- name: Verify required dependencies
run: |
echo "Checking required dependencies..."
command -v bash && echo "✅ bash found"
command -v curl && echo "✅ curl found"
command -v git && echo "✅ git found"
command -v bc && echo "✅ bc found"
echo "All required dependencies are available"
- name: Test script sourcing (dry run)
run: |
set -e
echo "Testing script sourcing..."
bash -c "source mac/common-utils.sh && echo '✅ common-utils.sh sourced successfully'"
echo "✅ Script sourcing successful"
- name: Integration Test - Silent Mode Execution
if: success()
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
TURL: https://bstackdemo.com
run: |
echo "Running integration tests in silent mode..."
# Set default values if secrets are not provided
BROWSERSTACK_USERNAME="${BROWSERSTACK_USERNAME:-test_user}"
BROWSERSTACK_ACCESS_KEY="${BROWSERSTACK_ACCESS_KEY:-test_key}"
export BROWSERSTACK_USERNAME
export BROWSERSTACK_ACCESS_KEY
export TURL
# Test configurations
test_configs=(
"web java"
"app java"
"web python"
"app python"
"web nodejs"
"app nodejs"
)
for config in "${test_configs[@]}"; do
read -r test_type tech_stack <<< "$config"
echo "================================"
echo "Testing: mac/run.sh --silent $test_type $tech_stack"
echo "================================"
# Run with timeout and capture exit code (macOS compatible)
bash mac/run.sh --silent "$test_type" "$tech_stack" >> "/tmp/run_test_${test_type}_${tech_stack}.log" 2>&1 &
job_pid=$!
# Wait with 600 second timeout using sleep loop (macOS compatible)
count=0
max_wait=600
while kill -0 "$job_pid" 2>/dev/null && [ $count -lt $max_wait ]; do
sleep 1
count=$((count + 1))
done
# Check if process is still running after timeout
if kill -0 "$job_pid" 2>/dev/null; then
echo "⚠️ mac/run.sh --silent $test_type $tech_stack timed out after 600 seconds"
kill -9 "$job_pid" 2>/dev/null || true
exit_code=124
else
wait "$job_pid" || exit_code=$?
fi
if [ -z "$exit_code" ] || [ "$exit_code" -eq 0 ] || [ "$exit_code" -eq 124 ]; then
echo "✅ mac/run.sh --silent $test_type $tech_stack completed (exit code: ${exit_code:-0})"
else
echo "⚠️ mac/run.sh --silent $test_type $tech_stack exited with code: $exit_code"
if [ -f "/tmp/run_test_${test_type}_${tech_stack}.log" ]; then
echo "Log output (last 20 lines):"
tail -n 20 "/tmp/run_test_${test_type}_${tech_stack}.log"
fi
fi
unset exit_code
done
echo "✅ All integration tests completed"
- name: Sync BrowserStack logs to workspace
if: always()
run: |
mkdir -p ${{ github.workspace }}/bs-logs
if [ -d ~/.browserstack/NOW/logs ]; then
cp -R ~/.browserstack/NOW/logs/* ${{ github.workspace }}/bs-logs/ || true
else
echo "No logs found in ~/.browserstack/NOW/logs"
fi
- name: Upload BrowserStack Logs as Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: browserstack-logs-macos
path: |
${{ github.workspace }}/bs-logs
/tmp/run_test_*.log
retention-days: 30
if-no-files-found: ignore
test-windows:
name: Test win/run.ps1 on Windows
runs-on: windows-latest
timeout-minutes: 25
environment: BrowserStack
defaults:
run:
shell: powershell
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Check PowerShell version
run: |
$PSVersionTable.PSVersion
Write-Host "✅ PowerShell version check complete"
- name: Validate PowerShell script syntax
run: |
Write-Host "Validating win/run.ps1 syntax..."
$ScriptPath = "win/run.ps1"
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Raw $ScriptPath), [ref]$null)
Write-Host "✅ win/run.ps1 syntax is valid"
- name: Validate supporting PowerShell scripts syntax
run: |
Write-Host "Validating supporting PowerShell scripts..."
$Scripts = @(
"win/common-utils.ps1",
"win/logging-utils.ps1",
"win/env-prequisite-checks.ps1",
"win/user-interaction.ps1",
"win/env-setup-run.ps1",
"win/device-machine-allocation.ps1"
)
foreach ($Script in $Scripts) {
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Raw $Script), [ref]$null)
Write-Host "✅ $Script syntax is valid"
}
- name: Run PSScriptAnalyzer
run: |
Write-Host "Installing PSScriptAnalyzer if needed..."
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser
}
Write-Host "Running PSScriptAnalyzer..."
Invoke-ScriptAnalyzer -Path "win" -Recurse -ReportSummary -ErrorAction Continue
Write-Host "✅ PSScriptAnalyzer analysis complete (continuing even if issues are found)"
- name: Check script file encoding
run: |
Write-Host "Checking PowerShell script encoding..."
$ScriptPath = "win/run.ps1"
$bytes = [System.IO.File]::ReadAllBytes($ScriptPath)
$encoding = "Unknown / ASCII / UTF-8 without BOM"
if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
$encoding = "UTF-8 with BOM"
} elseif ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFF -and $bytes[1] -eq 0xFE) {
$encoding = "UTF-16 LE"
} elseif ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFE -and $bytes[1] -eq 0xFF) {
$encoding = "UTF-16 BE"
}
Write-Host "Detected encoding (heuristic): $encoding"
Write-Host "✅ Encoding check complete"
- name: Verify required dependencies
run: |
Write-Host "Checking required dependencies..."
if (Get-Command curl.exe -ErrorAction SilentlyContinue) { Write-Host "✅ curl found" } else { Write-Host "⚠️ curl not found" }
if (Get-Command git.exe -ErrorAction SilentlyContinue) { Write-Host "✅ git found" } else { Write-Host "⚠️ git not found" }
Write-Host "✅ PowerShell dependencies verified"
- name: Integration Test - Silent Mode Execution
if: success()
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
TURL: https://bstackdemo.com
run: |
Write-Host "Running integration tests in silent mode..."
# Use defaults if secrets are missing (for local / dry runs)
$BrowserStackUsername = if ($env:BROWSERSTACK_USERNAME) { $env:BROWSERSTACK_USERNAME } else { "test_user" }
$BrowserStackAccessKey = if ($env:BROWSERSTACK_ACCESS_KEY) { $env:BROWSERSTACK_ACCESS_KEY } else { "test_key" }
$TestUrl = $env:TURL
$env:BROWSERSTACK_USERNAME = $BrowserStackUsername
$env:BROWSERSTACK_ACCESS_KEY = $BrowserStackAccessKey
$env:TURL = $TestUrl
# Absolute path is safer in CI
$scriptPath = Join-Path $env:GITHUB_WORKSPACE "win\run.ps1"
$testConfigs = @(
@("web", "java"),
@("app", "java"),
@("web", "python"),
@("app", "python"),
@("web", "nodejs"),
@("app", "nodejs")
)
$overallFailed = $false
# $logRoot = Join-Path $env:TEMP "now-tests"
# New-Item -ItemType Directory -Force -Path $logRoot | Out-Null
# $logPath = Join-Path $logRoot "run_test_app_nodejs.log"
# Write-Host "================================"
# Write-Host "Testing: $scriptPath --silent app nodejs"
# Write-Host "================================"
# & $scriptPath --silent app nodejs 2>&1 | Tee-Object -FilePath $logPath -Append
# $exitCode = $LASTEXITCODE
# if ($exitCode -eq 0) {
# Write-Host "✅ app / nodejs completed (exit code: $exitCode)"
# } else {
# Write-Host "⚠️ app / nodejs exited with code: $exitCode"
# if (Test-Path $logPath) {
# Write-Host "Log output (last 20 lines):"
# Get-Content -Path $logPath -Tail 20
# }
# exit 1
# }
$logRoot = Join-Path $env:TEMP "now-tests"
New-Item -ItemType Directory -Force -Path $logRoot | Out-Null
foreach ($config in $testConfigs) {
$testType = $config[0]
$techStack = $config[1]
Write-Host "================================"
Write-Host "Testing: $scriptPath --silent $testType $techStack"
Write-Host "================================"
$logPath = Join-Path $logRoot "run_test_${testType}_${techStack}.log"
& $scriptPath --silent $testType $techStack 2>&1 | Tee-Object -FilePath $logPath -Append
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
Write-Host "✅ $testType / $techStack completed (exit code: $exitCode)"
} else {
Write-Host "⚠️ $testType / $techStack exited with code: $exitCode"
$overallFailed = $true
if (Test-Path $logPath) {
Write-Host "Log output (last 20 lines):"
Get-Content -Path $logPath -Tail 20
}
}
}
if ($overallFailed) {
Write-Error "One or more configurations failed."
exit 1
}
Write-Host "✅ All integration tests completed successfully"
- name: Sync BrowserStack logs to workspace (Windows)
if: always()
run: |
$dest = Join-Path $env:GITHUB_WORKSPACE "bs-logs"
New-Item -ItemType Directory -Force -Path $dest | Out-Null
$bsLogPath = Join-Path $env:USERPROFILE ".browserstack\NOW\logs"
$tempLogDir = Join-Path $env:TEMP "now-tests"
if (Test-Path $bsLogPath) {
Write-Host "Copying logs from $bsLogPath"
Copy-Item -Path (Join-Path $bsLogPath "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
} else {
Write-Host "No logs found at $bsLogPath"
}
if (Test-Path $tempLogDir) {
Write-Host "Copying integration logs from $tempLogDir"
Copy-Item -Path (Join-Path $tempLogDir "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
}
- name: Upload BrowserStack Logs as Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: browserstack-logs-windows
path: ${{ github.workspace }}/bs-logs
retention-days: 30
if-no-files-found: ignore
test-linux:
name: Test mac/run.sh on Linux
# if: false
runs-on: ubuntu-latest
timeout-minutes: 15
environment: BrowserStack
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set up Bash
run: |
echo "Bash version:"
bash --version
- name: Validate shell script syntax
run: |
echo "Validating mac/run.sh syntax..."
bash -n mac/run.sh
echo "✅ mac/run.sh syntax is valid"
- name: Validate supporting scripts syntax
run: |
echo "Validating supporting scripts..."
bash -n mac/common-utils.sh
bash -n mac/logging-utils.sh
bash -n mac/env-setup-run.sh
bash -n mac/user-interaction.sh
bash -n mac/env-prequisite-checks.sh
echo "✅ All supporting scripts are valid"
- name: Check if scripts are executable
run: |
chmod +x mac/run.sh
chmod +x mac/common-utils.sh
chmod +x mac/logging-utils.sh
chmod +x mac/env-setup-run.sh
chmod +x mac/user-interaction.sh
chmod +x mac/env-prequisite-checks.sh
echo "✅ All scripts are executable"
- name: Install ShellCheck
run: |
echo "Installing ShellCheck..."
sudo apt-get update
sudo apt-get install -y shellcheck
shellcheck --version
- name: Run ShellCheck on mac scripts
run: |
echo "Running ShellCheck on mac scripts..."
shellcheck -x mac/run.sh || true
shellcheck -x mac/common-utils.sh || true
shellcheck -x mac/logging-utils.sh || true
shellcheck -x mac/env-setup-run.sh || true
shellcheck -x mac/user-interaction.sh || true
shellcheck -x mac/env-prequisite-checks.sh || true
echo "✅ ShellCheck analysis complete"
- name: Verify required dependencies
run: |
echo "Checking required dependencies..."
command -v bash && echo "✅ bash found"
command -v curl && echo "✅ curl found"
command -v git && echo "✅ git found"
command -v bc && echo "✅ bc found"
echo "All required dependencies are available"
- name: Test script sourcing (dry run)
run: |
set -e
echo "Testing script sourcing..."
bash -c "source mac/common-utils.sh && echo '✅ common-utils.sh sourced successfully'"
echo "✅ Script sourcing successful"
- name: Integration Test - Silent Mode Execution
if: success()
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
TURL: https://bstackdemo.com
run: |
echo "Running integration tests in silent mode..."
# Set default values if secrets are not provided
BROWSERSTACK_USERNAME="${BROWSERSTACK_USERNAME:-test_user}"
BROWSERSTACK_ACCESS_KEY="${BROWSERSTACK_ACCESS_KEY:-test_key}"
export BROWSERSTACK_USERNAME
export BROWSERSTACK_ACCESS_KEY
export TURL
# Test configurations
test_configs=(
"web java"
"app java"
"web python"
"app python"
"web nodejs"
"app nodejs"
)
for config in "${test_configs[@]}"; do
read -r test_type tech_stack <<< "$config"
echo "================================"
echo "Testing: mac/run.sh --silent $test_type $tech_stack"
echo "================================"
# Run with timeout and capture exit code (using timeout command on Linux)
timeout 600 bash mac/run.sh --silent "$test_type" "$tech_stack" >> "/tmp/run_test_${test_type}_${tech_stack}.log" 2>&1 &
job_pid=$!
wait "$job_pid" || exit_code=$?
if [ -z "$exit_code" ] || [ "$exit_code" -eq 0 ] || [ "$exit_code" -eq 124 ]; then
echo "✅ mac/run.sh --silent $test_type $tech_stack completed (exit code: ${exit_code:-0})"
else
echo "⚠️ mac/run.sh --silent $test_type $tech_stack exited with code: $exit_code"
if [ -f "/tmp/run_test_${test_type}_${tech_stack}.log" ]; then
echo "Log output (last 20 lines):"
tail -n 20 "/tmp/run_test_${test_type}_${tech_stack}.log"
fi
fi
unset exit_code
done
echo "✅ All integration tests completed"
- name: Sync BrowserStack logs to workspace
if: always()
run: |
mkdir -p ${{ github.workspace }}/bs-logs
if [ -d ~/.browserstack/NOW/logs ]; then
cp -R ~/.browserstack/NOW/logs/* ${{ github.workspace }}/bs-logs/ || true
else
echo "No logs found in ~/.browserstack/NOW/logs"
fi
- name: Upload BrowserStack Logs as Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: browserstack-logs-linux
path: |
${{ github.workspace }}/bs-logs
/tmp/run_test_*.log
retention-days: 30
if-no-files-found: ignore
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [test-mac, test-linux, test-windows]
if: always()
steps:
- name: Check test results
run: |
echo "=== Test Results Summary ==="
echo "macOS Tests: ${{ needs.test-mac.result }}"
echo "Linux Tests: ${{ needs.test-linux.result }}"
echo "Windows Tests: ${{ needs.test-windows.result }}"
if [ "${{ needs.test-mac.result }}" = "failure" ] || [ "${{ needs.test-linux.result }}" = "failure" ] || [ "${{ needs.test-windows.result }}" = "failure" ]; then
echo "❌ Some tests failed"
exit 1
fi
echo "✅ All tests passed!"
- name: Notify success
if: success()
run: |
echo "✅ All script validations passed successfully!"
echo "- mac/run.sh and supporting scripts validated on macOS and Linux"
echo "- win/run.ps1 and supporting scripts validated on Windows"