Skip to content

Commit fce5c82

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

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

.github/workflows/lib_run.yml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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,43 @@ 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+
$proc = Start-Process -FilePath ".\testbin.exe" -NoNewWindow -PassThru -RedirectStandardOutput "$logFile" -RedirectStandardError (Join-Path $PWD "stderr.log")
8087
$found = $false
8188
for ($i = 0; $i -lt 60; $i++) {
8289
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+
try {
91+
$content = ""
92+
foreach ($f in @($logFile, (Join-Path $PWD "stderr.log"))) {
93+
if (Test-Path $f) {
94+
$fs = [System.IO.FileStream]::new($f, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
95+
$sr = [System.IO.StreamReader]::new($fs)
96+
$content += $sr.ReadToEnd()
97+
$sr.Close()
98+
$fs.Close()
99+
}
100+
}
101+
if ($content -match '\[ws\] 连接到Websocket服务器') {
102+
$found = $true
103+
break
104+
}
105+
} catch {}
90106
}
91-
taskkill /F /T /PID $proc.Id 2>$null
107+
try { Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue } catch {}
108+
try { taskkill /F /T /PID $proc.Id 2>$null } catch {}
92109
Write-Host ""
93110
Write-Host "Run log:"
94-
if (Test-Path "stdout.log") { Get-Content "stdout.log" }
95-
if (Test-Path "stderr.log") { Get-Content "stderr.log" }
111+
foreach ($f in @($logFile, (Join-Path $PWD "stderr.log"))) {
112+
if (Test-Path $f) {
113+
try {
114+
$fs = [System.IO.FileStream]::new($f, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
115+
$sr = [System.IO.StreamReader]::new($fs)
116+
Write-Host $sr.ReadToEnd()
117+
$sr.Close()
118+
$fs.Close()
119+
} catch {}
120+
}
121+
}
96122
Write-Host ""
97123
if ($found) {
98124
Write-Host "Success: Found target output"

0 commit comments

Comments
 (0)