Skip to content

Commit 4422c5e

Browse files
committed
fix(ci): run on windows
1 parent e3ee5e4 commit 4422c5e

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

.github/workflows/lib_run.yml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ jobs:
4444
go generate main.go
4545
go mod tidy
4646
47-
- name: Run the Program
47+
- name: Run the Program (Unix)
48+
if: runner.os != 'Windows'
4849
shell: bash
4950
run: |
5051
go run main.go > output.log 2>&1 &
@@ -57,12 +58,9 @@ jobs:
5758
fi
5859
sleep 1
5960
done
60-
if [[ "$RUNNER_OS" == "Windows" ]]; then
61-
taskkill //F //T //PID $PID 2>/dev/null || true
62-
else
63-
kill $PID 2>/dev/null || true
64-
wait $PID 2>/dev/null || true
65-
fi
61+
kill $PID 2>/dev/null || true
62+
wait $PID 2>/dev/null || true
63+
echo ""
6664
echo "Run log:"
6765
cat output.log
6866
echo ""
@@ -73,3 +71,33 @@ jobs:
7371
echo "Failure: Timeout after 60s without finding target output"
7472
exit 1
7573
fi
74+
75+
- name: Run the Program (Windows)
76+
if: runner.os == 'Windows'
77+
shell: pwsh
78+
run: |
79+
$proc = Start-Process -FilePath "go" -ArgumentList "run", "main.go" -NoNewWindow -PassThru -RedirectStandardOutput "stdout.log" -RedirectStandardError "stderr.log"
80+
$found = $false
81+
for ($i = 0; $i -lt 60; $i++) {
82+
Start-Sleep -Seconds 1
83+
$content = ""
84+
if (Test-Path "stdout.log") { $content += Get-Content "stdout.log" -Raw -ErrorAction SilentlyContinue }
85+
if (Test-Path "stderr.log") { $content += Get-Content "stderr.log" -Raw -ErrorAction SilentlyContinue }
86+
if ($content -match '\[ws\] 连接到Websocket服务器') {
87+
$found = $true
88+
break
89+
}
90+
}
91+
taskkill /F /T /PID $proc.Id 2>$null
92+
Write-Host ""
93+
Write-Host "Run log:"
94+
if (Test-Path "stdout.log") { Get-Content "stdout.log" }
95+
if (Test-Path "stderr.log") { Get-Content "stderr.log" }
96+
Write-Host ""
97+
if ($found) {
98+
Write-Host "Success: Found target output"
99+
exit 0
100+
} else {
101+
Write-Host "Failure: Timeout after 60s without finding target output"
102+
exit 1
103+
}

0 commit comments

Comments
 (0)