Skip to content

Commit 63a2b77

Browse files
committed
env vars + detect os
1 parent 9e5c581 commit 63a2b77

File tree

3 files changed

+193
-149
lines changed

3 files changed

+193
-149
lines changed

.github/workflows/test-scripts.yml

Lines changed: 145 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -161,148 +161,148 @@ jobs:
161161
/tmp/run_test_*.log
162162
retention-days: 30
163163

164-
test-windows:
165-
name: Test win/run.ps1 on Windows
166-
runs-on: windows-latest
167-
timeout-minutes: 15
168-
environment: BrowserStack
169-
steps:
170-
- name: Checkout code
171-
uses: actions/checkout@v4
172-
- name: Set up Python 3.13
173-
uses: actions/setup-python@v5
174-
with:
175-
python-version: '3.13'
176-
- name: Check PowerShell version
177-
run: |
178-
$PSVersionTable.PSVersion
179-
Write-Host "✅ PowerShell version check complete"
180-
181-
- name: Validate PowerShell script syntax
182-
run: |
183-
Write-Host "Validating win/run.ps1 syntax..."
184-
$ScriptPath = "win/run.ps1"
185-
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content $ScriptPath), [ref]$null)
186-
Write-Host "✅ win/run.ps1 syntax is valid"
187-
188-
- name: Validate supporting PowerShell scripts syntax
189-
run: |
190-
Write-Host "Validating supporting PowerShell scripts..."
191-
$Scripts = @("win/proxy-check.ps1")
192-
foreach ($Script in $Scripts) {
193-
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content $Script), [ref]$null)
194-
Write-Host "✅ $Script syntax is valid"
195-
}
196-
197-
- name: Run PSScriptAnalyzer
198-
run: |
199-
Write-Host "Installing PSScriptAnalyzer..."
200-
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -ErrorAction SilentlyContinue
201-
Write-Host "Running PSScriptAnalyzer..."
202-
Invoke-ScriptAnalyzer -Path "win/run.ps1" -Recurse -ReportSummary || $true
203-
Write-Host "✅ PSScriptAnalyzer analysis complete"
204-
205-
- name: Check script file encoding
206-
run: |
207-
Write-Host "Checking PowerShell script encoding..."
208-
$ScriptPath = "win/run.ps1"
209-
$Encoding = (Get-Item $ScriptPath).EncodingInfo
210-
Write-Host "File encoding: $Encoding"
211-
Write-Host "✅ Encoding check complete"
212-
213-
- name: Verify required dependencies
214-
run: |
215-
Write-Host "Checking required dependencies..."
216-
if (Get-Command curl.exe -ErrorAction SilentlyContinue) { Write-Host "✅ curl found" }
217-
if (Get-Command git.exe -ErrorAction SilentlyContinue) { Write-Host "✅ git found" }
218-
Write-Host "✅ PowerShell dependencies verified"
219-
220-
- name: Integration Test - Silent Mode Execution
221-
if: success()
222-
env:
223-
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
224-
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
225-
TURL: https://bstackdemo.com
226-
run: |
227-
Write-Host "Running integration tests in silent mode..."
228-
229-
# Set default values if secrets are not provided
230-
$BrowserStackUsername = if ($env:BROWSERSTACK_USERNAME) { $env:BROWSERSTACK_USERNAME } else { "test_user" }
231-
$BrowserStackAccessKey = if ($env:BROWSERSTACK_ACCESS_KEY) { $env:BROWSERSTACK_ACCESS_KEY } else { "test_key" }
232-
$TestUrl = $env:TURL
233-
234-
# Export environment variables
235-
$env:BROWSERSTACK_USERNAME = $BrowserStackUsername
236-
$env:BROWSERSTACK_ACCESS_KEY = $BrowserStackAccessKey
237-
$env:TURL = $TestUrl
238-
239-
# Test configurations
240-
$testConfigs = @(
241-
@("web", "java"),
242-
@("app", "java"),
243-
@("web", "python"),
244-
@("app", "python"),
245-
@("web", "nodejs"),
246-
@("app", "nodejs")
247-
)
248-
249-
foreach ($config in $testConfigs) {
250-
$testType = $config[0]
251-
$techStack = $config[1]
252-
253-
Write-Host "================================"
254-
Write-Host "Testing: .\win\run.ps1 --silent $testType $techStack"
255-
Write-Host "================================"
256-
257-
# Create log file path
258-
$logPath = "C:\Temp\run_test_${testType}_${techStack}.log"
259-
New-Item -ItemType Directory -Path "C:\Temp" -Force -ErrorAction SilentlyContinue | Out-Null
260-
261-
# Run with timeout (using job for timeout capability)
262-
$job = Start-Job -ScriptBlock {
263-
param($path, $testType, $techStack, $logPath)
264-
& $path --silent $testType $techStack 2>&1 | Tee-Object -FilePath $logPath -Append
265-
} -ArgumentList ".\win\run.ps1", $testType, $techStack, $logPath
266-
267-
# Wait for job with 600 second timeout
268-
$timeout = New-TimeSpan -Seconds 600
269-
$completed = Wait-Job -Job $job -Timeout 600
270-
271-
if ($completed) {
272-
$result = Receive-Job -Job $job
273-
if ($job.State -eq "Completed") {
274-
Write-Host "✅ .\win\run.ps1 --silent $testType $techStack completed successfully"
275-
} else {
276-
Write-Host "⚠️ .\win\run.ps1 --silent $testType $techStack exited with state: $($job.State)"
277-
if (Test-Path $logPath) {
278-
Write-Host "Log output (last 20 lines):"
279-
Get-Content -Path $logPath -Tail 20
280-
}
281-
}
282-
} else {
283-
Write-Host "⚠️ .\win\run.ps1 --silent $testType $techStack timed out after 600 seconds"
284-
Stop-Job -Job $job
285-
if (Test-Path $logPath) {
286-
Write-Host "Log output (last 20 lines):"
287-
Get-Content -Path $logPath -Tail 20
288-
}
289-
}
290-
291-
Remove-Job -Job $job -Force
292-
}
293-
294-
Write-Host "✅ All integration tests completed"
295-
296-
- name: Upload BrowserStack Logs as Artifacts
297-
if: always()
298-
uses: actions/upload-artifact@v4
299-
with:
300-
name: browserstack-logs-windows
301-
path: |
302-
C:\Users\runneradmin\.browserstack\NOW\logs\
303-
C:\Temp\run_test_*.log
304-
retention-days: 30
305-
if-no-files-found: ignore
164+
# test-windows:
165+
# name: Test win/run.ps1 on Windows
166+
# runs-on: windows-latest
167+
# timeout-minutes: 15
168+
# environment: BrowserStack
169+
# steps:
170+
# - name: Checkout code
171+
# uses: actions/checkout@v4
172+
# - name: Set up Python 3.13
173+
# uses: actions/setup-python@v5
174+
# with:
175+
# python-version: '3.13'
176+
# - name: Check PowerShell version
177+
# run: |
178+
# $PSVersionTable.PSVersion
179+
# Write-Host "✅ PowerShell version check complete"
180+
#
181+
# - name: Validate PowerShell script syntax
182+
# run: |
183+
# Write-Host "Validating win/run.ps1 syntax..."
184+
# $ScriptPath = "win/run.ps1"
185+
# $null = [System.Management.Automation.PSParser]::Tokenize((Get-Content $ScriptPath), [ref]$null)
186+
# Write-Host "✅ win/run.ps1 syntax is valid"
187+
#
188+
# - name: Validate supporting PowerShell scripts syntax
189+
# run: |
190+
# Write-Host "Validating supporting PowerShell scripts..."
191+
# $Scripts = @("win/proxy-check.ps1")
192+
# foreach ($Script in $Scripts) {
193+
# $null = [System.Management.Automation.PSParser]::Tokenize((Get-Content $Script), [ref]$null)
194+
# Write-Host "✅ $Script syntax is valid"
195+
# }
196+
#
197+
# - name: Run PSScriptAnalyzer
198+
# run: |
199+
# Write-Host "Installing PSScriptAnalyzer..."
200+
# Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -ErrorAction SilentlyContinue
201+
# Write-Host "Running PSScriptAnalyzer..."
202+
# Invoke-ScriptAnalyzer -Path "win/run.ps1" -Recurse -ReportSummary || $true
203+
# Write-Host "✅ PSScriptAnalyzer analysis complete"
204+
#
205+
# - name: Check script file encoding
206+
# run: |
207+
# Write-Host "Checking PowerShell script encoding..."
208+
# $ScriptPath = "win/run.ps1"
209+
# $Encoding = (Get-Item $ScriptPath).EncodingInfo
210+
# Write-Host "File encoding: $Encoding"
211+
# Write-Host "✅ Encoding check complete"
212+
#
213+
# - name: Verify required dependencies
214+
# run: |
215+
# Write-Host "Checking required dependencies..."
216+
# if (Get-Command curl.exe -ErrorAction SilentlyContinue) { Write-Host "✅ curl found" }
217+
# if (Get-Command git.exe -ErrorAction SilentlyContinue) { Write-Host "✅ git found" }
218+
# Write-Host "✅ PowerShell dependencies verified"
219+
#
220+
# - name: Integration Test - Silent Mode Execution
221+
# if: success()
222+
# env:
223+
# BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
224+
# BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
225+
# TURL: https://bstackdemo.com
226+
# run: |
227+
# Write-Host "Running integration tests in silent mode..."
228+
#
229+
# # Set default values if secrets are not provided
230+
# $BrowserStackUsername = if ($env:BROWSERSTACK_USERNAME) { $env:BROWSERSTACK_USERNAME } else { "test_user" }
231+
# $BrowserStackAccessKey = if ($env:BROWSERSTACK_ACCESS_KEY) { $env:BROWSERSTACK_ACCESS_KEY } else { "test_key" }
232+
# $TestUrl = $env:TURL
233+
#
234+
# # Export environment variables
235+
# $env:BROWSERSTACK_USERNAME = $BrowserStackUsername
236+
# $env:BROWSERSTACK_ACCESS_KEY = $BrowserStackAccessKey
237+
# $env:TURL = $TestUrl
238+
#
239+
# # Test configurations
240+
# $testConfigs = @(
241+
# @("web", "java"),
242+
# @("app", "java"),
243+
# @("web", "python"),
244+
# @("app", "python"),
245+
# @("web", "nodejs"),
246+
# @("app", "nodejs")
247+
# )
248+
#
249+
# foreach ($config in $testConfigs) {
250+
# $testType = $config[0]
251+
# $techStack = $config[1]
252+
#
253+
# Write-Host "================================"
254+
# Write-Host "Testing: .\win\run.ps1 --silent $testType $techStack"
255+
# Write-Host "================================"
256+
#
257+
# # Create log file path
258+
# $logPath = "C:\Temp\run_test_${testType}_${techStack}.log"
259+
# New-Item -ItemType Directory -Path "C:\Temp" -Force -ErrorAction SilentlyContinue | Out-Null
260+
#
261+
# # Run with timeout (using job for timeout capability)
262+
# $job = Start-Job -ScriptBlock {
263+
# param($path, $testType, $techStack, $logPath)
264+
# & $path --silent $testType $techStack 2>&1 | Tee-Object -FilePath $logPath -Append
265+
# } -ArgumentList ".\win\run.ps1", $testType, $techStack, $logPath
266+
#
267+
# # Wait for job with 600 second timeout
268+
# $timeout = New-TimeSpan -Seconds 600
269+
# $completed = Wait-Job -Job $job -Timeout 600
270+
#
271+
# if ($completed) {
272+
# $result = Receive-Job -Job $job
273+
# if ($job.State -eq "Completed") {
274+
# Write-Host "✅ .\win\run.ps1 --silent $testType $techStack completed successfully"
275+
# } else {
276+
# Write-Host "⚠️ .\win\run.ps1 --silent $testType $techStack exited with state: $($job.State)"
277+
# if (Test-Path $logPath) {
278+
# Write-Host "Log output (last 20 lines):"
279+
# Get-Content -Path $logPath -Tail 20
280+
# }
281+
# }
282+
# } else {
283+
# Write-Host "⚠️ .\win\run.ps1 --silent $testType $techStack timed out after 600 seconds"
284+
# Stop-Job -Job $job
285+
# if (Test-Path $logPath) {
286+
# Write-Host "Log output (last 20 lines):"
287+
# Get-Content -Path $logPath -Tail 20
288+
# }
289+
# }
290+
#
291+
# Remove-Job -Job $job -Force
292+
# }
293+
#
294+
# Write-Host "✅ All integration tests completed"
295+
#
296+
# - name: Upload BrowserStack Logs as Artifacts
297+
# if: always()
298+
# uses: actions/upload-artifact@v4
299+
# with:
300+
# name: browserstack-logs-windows
301+
# path: |
302+
# C:\Users\runneradmin\.browserstack\NOW\logs\
303+
# C:\Temp\run_test_*.log
304+
# retention-days: 30
305+
# if-no-files-found: ignore
306306

307307
test-linux:
308308
name: Test mac/run.sh on Linux
@@ -447,17 +447,16 @@ jobs:
447447
test-summary:
448448
name: Test Summary
449449
runs-on: ubuntu-latest
450-
needs: [test-mac, test-windows, test-linux]
450+
needs: [test-mac, test-linux]
451451
if: always()
452452
steps:
453453
- name: Check test results
454454
run: |
455455
echo "=== Test Results Summary ==="
456456
echo "macOS Tests: ${{ needs.test-mac.result }}"
457-
echo "Windows Tests: ${{ needs.test-windows.result }}"
458457
echo "Linux Tests: ${{ needs.test-linux.result }}"
459458
460-
if [ "${{ needs.test-mac.result }}" = "failure" ] || [ "${{ needs.test-windows.result }}" = "failure" ] || [ "${{ needs.test-linux.result }}" = "failure" ]; then
459+
if [ "${{ needs.test-mac.result }}" = "failure" ] || [ "${{ needs.test-linux.result }}" = "failure" ]; then
461460
echo "❌ Some tests failed"
462461
exit 1
463462
fi
@@ -468,4 +467,4 @@ jobs:
468467
run: |
469468
echo "✅ All script validations passed successfully!"
470469
echo "- mac/run.sh and supporting scripts validated on macOS and Linux"
471-
echo "- win/run.ps1 and supporting scripts validated on Windows"
470+
echo "- win/run.ps1 and supporting scripts validated on Windows (temporarily disabled)"

mac/common-utils.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,32 @@ clear_old_logs() {
364364

365365
log_success "Logs cleared and fresh run initiated."
366366
}
367+
368+
369+
detect_os() {
370+
local unameOut=""
371+
unameOut="$(uname -s 2>/dev/null | tr '[:upper:]' '[:lower:]')"
372+
local response=""
373+
case "$unameOut" in
374+
linux*)
375+
# Detect WSL vs normal Linux
376+
if grep -qi "microsoft" /proc/version 2>/dev/null; then
377+
response="wsl"
378+
else
379+
response="linux"
380+
fi
381+
;;
382+
darwin*)
383+
response="macos"
384+
;;
385+
msys*|mingw*|cygwin*)
386+
response="windows"
387+
;;
388+
*)
389+
response="unknown"
390+
;;
391+
esac
392+
393+
export NOW_OS=$response
394+
}
395+

0 commit comments

Comments
 (0)