Skip to content

Commit 8b07e93

Browse files
committed
Test Windows-only CI
1 parent 68736b3 commit 8b07e93

1 file changed

Lines changed: 126 additions & 104 deletions

File tree

.github/workflows/test-scripts.yml

Lines changed: 126 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
jobs:
1515
test-mac:
1616
name: Test mac/run.sh on macOS
17+
if: false
1718
runs-on: macos-latest
1819
timeout-minutes: 15
1920
environment: BrowserStack
@@ -91,15 +92,15 @@ jobs:
9192
TURL: https://bstackdemo.com
9293
run: |
9394
echo "Running integration tests in silent mode..."
94-
95+
9596
# Set default values if secrets are not provided
9697
BROWSERSTACK_USERNAME="${BROWSERSTACK_USERNAME:-test_user}"
9798
BROWSERSTACK_ACCESS_KEY="${BROWSERSTACK_ACCESS_KEY:-test_key}"
98-
99+
99100
export BROWSERSTACK_USERNAME
100101
export BROWSERSTACK_ACCESS_KEY
101102
export TURL
102-
103+
103104
# Test configurations
104105
test_configs=(
105106
"web java"
@@ -109,7 +110,7 @@ jobs:
109110
"web nodejs"
110111
"app nodejs"
111112
)
112-
113+
113114
for config in "${test_configs[@]}"; do
114115
read -r test_type tech_stack <<< "$config"
115116
echo "================================"
@@ -148,9 +149,9 @@ jobs:
148149
fi
149150
unset exit_code
150151
done
151-
152+
152153
echo "✅ All integration tests completed"
153-
154+
154155
- name: Sync BrowserStack logs to workspace
155156
if: always()
156157
run: |
@@ -166,67 +167,93 @@ jobs:
166167
with:
167168
name: browserstack-logs-macos
168169
path: |
169-
${{ github.workspace }}/bs-logs
170-
/tmp/run_test_*.log
170+
${{ github.workspace }}/bs-logs
171+
/tmp/run_test_*.log
171172
retention-days: 30
172173
if-no-files-found: ignore
173174

174175
test-windows:
175176
name: Test win/run.ps1 on Windows
176177
runs-on: windows-latest
177-
timeout-minutes: 15
178+
timeout-minutes: 20
178179
environment: BrowserStack
180+
defaults:
181+
run:
182+
shell: powershell
183+
179184
steps:
180185
- name: Checkout code
181186
uses: actions/checkout@v4
187+
182188
- name: Set up Python 3.12
183189
uses: actions/setup-python@v5
184190
with:
185191
python-version: '3.12'
192+
186193
- name: Check PowerShell version
187194
run: |
188195
$PSVersionTable.PSVersion
189196
Write-Host "✅ PowerShell version check complete"
190-
197+
191198
- name: Validate PowerShell script syntax
192199
run: |
193200
Write-Host "Validating win/run.ps1 syntax..."
194201
$ScriptPath = "win/run.ps1"
195-
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content $ScriptPath), [ref]$null)
202+
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Raw $ScriptPath), [ref]$null)
196203
Write-Host "✅ win/run.ps1 syntax is valid"
197204
198205
- name: Validate supporting PowerShell scripts syntax
199206
run: |
200207
Write-Host "Validating supporting PowerShell scripts..."
201-
$Scripts = @("win/common-utils.ps1", "win/logging-utils.ps1", "win/env-prequisite-checks.ps1", "win/user-interaction.ps1", "win/env-setup-run.ps1")
208+
$Scripts = @(
209+
"win/common-utils.ps1",
210+
"win/logging-utils.ps1",
211+
"win/env-prequisite-checks.ps1",
212+
"win/user-interaction.ps1",
213+
"win/env-setup-run.ps1",
214+
"win/device-machine-allocation.ps1"
215+
)
202216
foreach ($Script in $Scripts) {
203-
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content $Script), [ref]$null)
217+
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Raw $Script), [ref]$null)
204218
Write-Host "✅ $Script syntax is valid"
205219
}
206-
220+
207221
- name: Run PSScriptAnalyzer
208222
run: |
209-
Write-Host "Installing PSScriptAnalyzer..."
210-
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -ErrorAction SilentlyContinue
223+
Write-Host "Installing PSScriptAnalyzer if needed..."
224+
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
225+
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser
226+
}
227+
211228
Write-Host "Running PSScriptAnalyzer..."
212-
Invoke-ScriptAnalyzer -Path "win/run.ps1" -Recurse -ReportSummary || $true
213-
Write-Host "✅ PSScriptAnalyzer analysis complete"
214-
229+
Invoke-ScriptAnalyzer -Path "win" -Recurse -ReportSummary -ErrorAction Continue
230+
Write-Host "✅ PSScriptAnalyzer analysis complete (continuing even if issues are found)"
231+
215232
- name: Check script file encoding
216233
run: |
217234
Write-Host "Checking PowerShell script encoding..."
218235
$ScriptPath = "win/run.ps1"
219-
$Encoding = (Get-Item $ScriptPath).EncodingInfo
220-
Write-Host "File encoding: $Encoding"
236+
$bytes = [System.IO.File]::ReadAllBytes($ScriptPath)
237+
238+
$encoding = "Unknown / ASCII / UTF-8 without BOM"
239+
if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
240+
$encoding = "UTF-8 with BOM"
241+
} elseif ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFF -and $bytes[1] -eq 0xFE) {
242+
$encoding = "UTF-16 LE"
243+
} elseif ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFE -and $bytes[1] -eq 0xFF) {
244+
$encoding = "UTF-16 BE"
245+
}
246+
247+
Write-Host "Detected encoding (heuristic): $encoding"
221248
Write-Host "✅ Encoding check complete"
222-
249+
223250
- name: Verify required dependencies
224251
run: |
225252
Write-Host "Checking required dependencies..."
226-
if (Get-Command curl.exe -ErrorAction SilentlyContinue) { Write-Host "✅ curl found" }
227-
if (Get-Command git.exe -ErrorAction SilentlyContinue) { Write-Host "✅ git found" }
253+
if (Get-Command curl.exe -ErrorAction SilentlyContinue) { Write-Host "✅ curl found" } else { Write-Host "⚠️ curl not found" }
254+
if (Get-Command git.exe -ErrorAction SilentlyContinue) { Write-Host "✅ git found" } else { Write-Host "⚠️ git not found" }
228255
Write-Host "✅ PowerShell dependencies verified"
229-
256+
230257
- name: Integration Test - Silent Mode Execution
231258
if: success()
232259
env:
@@ -235,103 +262,98 @@ jobs:
235262
TURL: https://bstackdemo.com
236263
run: |
237264
Write-Host "Running integration tests in silent mode..."
238-
239-
# Set default values if secrets are not provided
265+
266+
# Use defaults if secrets are missing (for local / dry runs)
240267
$BrowserStackUsername = if ($env:BROWSERSTACK_USERNAME) { $env:BROWSERSTACK_USERNAME } else { "test_user" }
241268
$BrowserStackAccessKey = if ($env:BROWSERSTACK_ACCESS_KEY) { $env:BROWSERSTACK_ACCESS_KEY } else { "test_key" }
242269
$TestUrl = $env:TURL
243-
244-
# Export environment variables
270+
245271
$env:BROWSERSTACK_USERNAME = $BrowserStackUsername
246272
$env:BROWSERSTACK_ACCESS_KEY = $BrowserStackAccessKey
247273
$env:TURL = $TestUrl
248-
249-
# Test configurations
274+
275+
# Absolute path is safer in CI
276+
$scriptPath = Join-Path $env:GITHUB_WORKSPACE "win\run.ps1"
277+
250278
$testConfigs = @(
251-
@("web", "java"),
252-
@("app", "java"),
253-
@("web", "python"),
254-
@("app", "python"),
255-
@("web", "nodejs"),
256-
@("app", "nodejs")
279+
@("web", "java"),
280+
@("app", "java"),
281+
@("web", "python"),
282+
@("app", "python"),
283+
@("web", "nodejs"),
284+
@("app", "nodejs")
257285
)
258-
286+
287+
$overallFailed = $false
288+
$logRoot = Join-Path $env:TEMP "now-tests"
289+
New-Item -ItemType Directory -Force -Path $logRoot | Out-Null
290+
259291
foreach ($config in $testConfigs) {
260-
$testType = $config[0]
261-
$techStack = $config[1]
262-
263-
Write-Host "================================"
264-
Write-Host "Testing: .\win\run.ps1 --silent $testType $techStack"
265-
Write-Host "================================"
266-
267-
# Create log file path
268-
$logPath = "C:\Temp\run_test_${testType}_${techStack}.log"
269-
New-Item -ItemType Directory -Path "C:\Temp" -Force -ErrorAction SilentlyContinue | Out-Null
270-
271-
# Run with timeout (using job for timeout capability)
272-
$job = Start-Job -ScriptBlock {
273-
param($path, $testType, $techStack, $logPath)
274-
& $path --silent $testType $techStack 2>&1 | Tee-Object -FilePath $logPath -Append
275-
} -ArgumentList ".\win\run.ps1", $testType, $techStack, $logPath
276-
277-
# Wait for job with 600 second timeout
278-
$timeout = New-TimeSpan -Seconds 600
279-
$completed = Wait-Job -Job $job -Timeout 600
280-
281-
if ($completed) {
282-
$result = Receive-Job -Job $job
283-
if ($job.State -eq "Completed") {
284-
Write-Host "✅ .\win\run.ps1 --silent $testType $techStack completed successfully"
285-
} else {
286-
Write-Host "⚠️ .\win\run.ps1 --silent $testType $techStack exited with state: $($job.State)"
287-
if (Test-Path $logPath) {
288-
Write-Host "Log output (last 20 lines):"
289-
Get-Content -Path $logPath -Tail 20
290-
}
291-
}
292-
} else {
293-
Write-Host "⚠️ .\win\run.ps1 --silent $testType $techStack timed out after 600 seconds"
294-
Stop-Job -Job $job
295-
if (Test-Path $logPath) {
296-
Write-Host "Log output (last 20 lines):"
297-
Get-Content -Path $logPath -Tail 20
298-
}
292+
$testType = $config[0]
293+
$techStack = $config[1]
294+
295+
Write-Host "================================"
296+
Write-Host "Testing: $scriptPath --silent $testType $techStack"
297+
Write-Host "================================"
298+
299+
$logPath = Join-Path $logRoot "run_test_${testType}_${techStack}.log"
300+
301+
& $scriptPath --silent $testType $techStack 2>&1 | Tee-Object -FilePath $logPath -Append
302+
$exitCode = $LASTEXITCODE
303+
304+
if ($exitCode -eq 0) {
305+
Write-Host "✅ $testType / $techStack completed (exit code: $exitCode)"
306+
} else {
307+
Write-Host "⚠️ $testType / $techStack exited with code: $exitCode"
308+
$overallFailed = $true
309+
310+
if (Test-Path $logPath) {
311+
Write-Host "Log output (last 20 lines):"
312+
Get-Content -Path $logPath -Tail 20
299313
}
300-
301-
Remove-Job -Job $job -Force
314+
}
315+
}
316+
317+
if ($overallFailed) {
318+
Write-Error "One or more configurations failed."
319+
exit 1
302320
}
303-
304-
Write-Host "✅ All integration tests completed"
305-
321+
322+
Write-Host "✅ All integration tests completed successfully"
323+
306324
- name: Sync BrowserStack logs to workspace (Windows)
307325
if: always()
308326
run: |
309-
$dest = "${env:GITHUB_WORKSPACE}\bs-logs"
327+
$dest = Join-Path $env:GITHUB_WORKSPACE "bs-logs"
310328
New-Item -ItemType Directory -Force -Path $dest | Out-Null
311329
312-
$logPath = "$env:USERPROFILE\.browserstack\NOW\logs"
330+
$bsLogPath = Join-Path $env:USERPROFILE ".browserstack\NOW\logs"
331+
$tempLogDir = Join-Path $env:TEMP "now-tests"
313332
314-
if (Test-Path $logPath) {
315-
Write-Host "Copying logs from $logPath"
316-
Copy-Item -Path "$logPath\*" -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
333+
if (Test-Path $bsLogPath) {
334+
Write-Host "Copying logs from $bsLogPath"
335+
Copy-Item -Path (Join-Path $bsLogPath "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
336+
} else {
337+
Write-Host "No logs found at $bsLogPath"
317338
}
318-
else {
319-
Write-Host "No logs found at $logPath"
339+
340+
if (Test-Path $tempLogDir) {
341+
Write-Host "Copying integration logs from $tempLogDir"
342+
Copy-Item -Path (Join-Path $tempLogDir "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
320343
}
321-
344+
322345
- name: Upload BrowserStack Logs as Artifacts
323346
if: always()
324347
uses: actions/upload-artifact@v4
325348
with:
326349
name: browserstack-logs-windows
327-
path: |
328-
${{ github.workspace }}/bs-logs
329-
C:\Temp\run_test_*.log
350+
path: ${{ github.workspace }}/bs-logs
330351
retention-days: 30
331352
if-no-files-found: ignore
332353

333354
test-linux:
334355
name: Test mac/run.sh on Linux
356+
if: false
335357
runs-on: ubuntu-latest
336358
timeout-minutes: 15
337359
environment: BrowserStack
@@ -415,15 +437,15 @@ jobs:
415437
TURL: https://bstackdemo.com
416438
run: |
417439
echo "Running integration tests in silent mode..."
418-
440+
419441
# Set default values if secrets are not provided
420442
BROWSERSTACK_USERNAME="${BROWSERSTACK_USERNAME:-test_user}"
421443
BROWSERSTACK_ACCESS_KEY="${BROWSERSTACK_ACCESS_KEY:-test_key}"
422-
444+
423445
export BROWSERSTACK_USERNAME
424446
export BROWSERSTACK_ACCESS_KEY
425447
export TURL
426-
448+
427449
# Test configurations
428450
test_configs=(
429451
"web java"
@@ -433,7 +455,7 @@ jobs:
433455
"web nodejs"
434456
"app nodejs"
435457
)
436-
458+
437459
for config in "${test_configs[@]}"; do
438460
read -r test_type tech_stack <<< "$config"
439461
echo "================================"
@@ -456,7 +478,7 @@ jobs:
456478
fi
457479
unset exit_code
458480
done
459-
481+
460482
echo "✅ All integration tests completed"
461483
462484
- name: Sync BrowserStack logs to workspace
@@ -483,16 +505,15 @@ jobs:
483505
test-summary:
484506
name: Test Summary
485507
runs-on: ubuntu-latest
486-
needs: [test-mac, test-linux]
508+
needs: [test-windows]
487509
if: always()
488510
steps:
489511
- name: Check test results
490512
run: |
491513
echo "=== Test Results Summary ==="
492-
echo "macOS Tests: ${{ needs.test-mac.result }}"
493-
echo "Linux Tests: ${{ needs.test-linux.result }}"
494-
495-
if [ "${{ needs.test-mac.result }}" = "failure" ] || [ "${{ needs.test-linux.result }}" = "failure" ]; then
514+
echo "Windows Tests: ${{ needs.test-windows.result }}"
515+
516+
if [ "${{ needs.test-windows.result }}" = "failure" ]; then
496517
echo "❌ Some tests failed"
497518
exit 1
498519
fi
@@ -503,4 +524,5 @@ jobs:
503524
run: |
504525
echo "✅ All script validations passed successfully!"
505526
echo "- mac/run.sh and supporting scripts validated on macOS and Linux"
506-
echo "- win/run.ps1 and supporting scripts validated on Windows (temporarily disabled)"
527+
echo "- win/run.ps1 and supporting scripts validated on Windows"
528+
echo "- win/run.ps1 and supporting scripts validated on Windows"

0 commit comments

Comments
 (0)