2121 real_run :
2222 name : Run on ${{ matrix.os }}
2323 runs-on : ${{ matrix.os }}
24- timeout-minutes : 2
24+ timeout-minutes : ${{ matrix.os == 'windows-latest' && 10 || 2 }}
2525 strategy :
2626 matrix :
2727 os : [ubuntu-latest, windows-latest, macos-latest]
@@ -39,16 +39,22 @@ jobs:
3939 fetch-depth : ${{ inputs.fetch-depth }}
4040 submodules : ${{ inputs.submodules }}
4141
42- - name : Prepare Necessary Runtime Files
42+ - name : Prepare and Build
43+ shell : bash
4344 run : |
4445 go generate main.go
4546 go mod tidy
47+ if [[ "$RUNNER_OS" == "Windows" ]]; then
48+ go build -o testbin.exe .
49+ else
50+ go build -o testbin .
51+ fi
4652
4753 - name : Run the Program (Unix)
4854 if : runner.os != 'Windows'
4955 shell : bash
5056 run : |
51- go run main.go > output.log 2>&1 &
57+ ./testbin > output.log 2>&1 &
5258 PID=$!
5359 FOUND=false
5460 for i in $(seq 1 60); do
@@ -76,23 +82,44 @@ jobs:
7682 if : runner.os == 'Windows'
7783 shell : pwsh
7884 run : |
79- $proc = Start-Process -FilePath "go" -ArgumentList "run", "main.go" -NoNewWindow -PassThru -RedirectStandardOutput "stdout.log" -RedirectStandardError "stderr.log"
85+ $logFile = Join-Path $PWD "output.log"
86+ $env:DEBUG_MODE = "1"
87+ $proc = Start-Process -FilePath ".\testbin.exe" -NoNewWindow -PassThru -RedirectStandardOutput "$logFile" -RedirectStandardError (Join-Path $PWD "stderr.log")
8088 $found = $false
8189 for ($i = 0; $i -lt 60; $i++) {
8290 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- }
91+ try {
92+ $content = ""
93+ foreach ($f in @($logFile, (Join-Path $PWD "stderr.log"))) {
94+ if (Test-Path $f) {
95+ $fs = [System.IO.FileStream]::new($f, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
96+ $sr = [System.IO.StreamReader]::new($fs)
97+ $content += $sr.ReadToEnd()
98+ $sr.Close()
99+ $fs.Close()
100+ }
101+ }
102+ if ($content -match '\[ws\] 连接到Websocket服务器') {
103+ $found = $true
104+ break
105+ }
106+ } catch {}
90107 }
91- taskkill /F /T /PID $proc.Id 2>$null
108+ try { Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue } catch {}
109+ try { taskkill /F /T /PID $proc.Id 2>$null } catch {}
92110 Write-Host ""
93111 Write-Host "Run log:"
94- if (Test-Path "stdout.log") { Get-Content "stdout.log" }
95- if (Test-Path "stderr.log") { Get-Content "stderr.log" }
112+ foreach ($f in @($logFile, (Join-Path $PWD "stderr.log"))) {
113+ if (Test-Path $f) {
114+ try {
115+ $fs = [System.IO.FileStream]::new($f, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
116+ $sr = [System.IO.StreamReader]::new($fs)
117+ Write-Host $sr.ReadToEnd()
118+ $sr.Close()
119+ $fs.Close()
120+ } catch {}
121+ }
122+ }
96123 Write-Host ""
97124 if ($found) {
98125 Write-Host "Success: Found target output"
0 commit comments