-
Notifications
You must be signed in to change notification settings - Fork 2k
130 lines (126 loc) · 4.06 KB
/
lib_run.yml
File metadata and controls
130 lines (126 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Run Library
on:
workflow_call:
inputs:
ref:
required: true
type: string
go-version:
required: false
type: string
default: '^1.25'
fetch-depth:
required: false
type: number
default: 0
submodules:
required: false
type: string
default: 'recursive'
jobs:
real_run:
name: Run on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: ${{ matrix.os == 'windows-latest' && 10 || 2 }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: true
steps:
- name: Set up Go
uses: actions/setup-go@master
with:
go-version: "${{ inputs.go-version }}"
- name: Check out code into the Go module directory
uses: actions/checkout@master
with:
ref: ${{ inputs.ref }}
fetch-depth: ${{ inputs.fetch-depth }}
submodules: ${{ inputs.submodules }}
- name: Prepare and Build
shell: bash
run: |
go generate main.go
go mod tidy
if [[ "$RUNNER_OS" == "Windows" ]]; then
go build -o testbin.exe .
else
go build -o testbin .
fi
- name: Run the Program (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
./testbin > output.log 2>&1 &
PID=$!
FOUND=false
for i in $(seq 1 60); do
if grep -q '\[ws\] 连接到Websocket服务器' output.log 2>/dev/null; then
FOUND=true
break
fi
sleep 1
done
kill $PID 2>/dev/null || true
wait $PID 2>/dev/null || true
echo ""
echo "Run log:"
cat output.log
echo ""
if [ "$FOUND" = true ]; then
echo "Success: Found target output"
exit 0
else
echo "Failure: Timeout after 60s without finding target output"
exit 1
fi
- name: Run the Program (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$logFile = Join-Path $PWD "output.log"
$env:DEBUG_MODE = "1"
$proc = Start-Process -FilePath ".\testbin.exe" -NoNewWindow -PassThru -RedirectStandardOutput "$logFile" -RedirectStandardError (Join-Path $PWD "stderr.log")
$found = $false
for ($i = 0; $i -lt 60; $i++) {
Start-Sleep -Seconds 1
try {
$content = ""
foreach ($f in @($logFile, (Join-Path $PWD "stderr.log"))) {
if (Test-Path $f) {
$fs = [System.IO.FileStream]::new($f, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$sr = [System.IO.StreamReader]::new($fs)
$content += $sr.ReadToEnd()
$sr.Close()
$fs.Close()
}
}
if ($content -match '\[ws\] 连接到Websocket服务器') {
$found = $true
break
}
} catch {}
}
try { Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue } catch {}
try { taskkill /F /T /PID $proc.Id 2>$null } catch {}
Write-Host ""
Write-Host "Run log:"
foreach ($f in @($logFile, (Join-Path $PWD "stderr.log"))) {
if (Test-Path $f) {
try {
$fs = [System.IO.FileStream]::new($f, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$sr = [System.IO.StreamReader]::new($fs)
Write-Host $sr.ReadToEnd()
$sr.Close()
$fs.Close()
} catch {}
}
}
Write-Host ""
if ($found) {
Write-Host "Success: Found target output"
exit 0
} else {
Write-Host "Failure: Timeout after 60s without finding target output"
exit 1
}