-
Notifications
You must be signed in to change notification settings - Fork 24
246 lines (201 loc) · 7.36 KB
/
unit-tests.yml
File metadata and controls
246 lines (201 loc) · 7.36 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
name: Unit Tests
on:
push:
branches: ["*"]
pull_request:
branches: ["*"]
jobs:
# Build frontend once and share across all jobs
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install frontend dependencies
run: cd frontend && npm ci
- name: Build frontend
run: cd frontend && npm run build
- name: Upload frontend artifact
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: frontend/dist/
retention-days: 1
verify-oas:
name: Verify OpenAPI Artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
- name: Install swag
run: go install github.com/swaggo/swag/v2/cmd/swag@v2.0.0-rc4
- name: Regenerate and verify OpenAPI spec
run: scripts/verify-oas.sh
test:
name: Unit Tests
needs: [build-frontend, verify-oas]
runs-on: ${{ matrix.os }}
env:
GO111MODULE: "on"
strategy:
matrix:
# On PRs: test only latest Go on ubuntu-latest
# On main/push: test full matrix
os: ${{ github.event_name == 'pull_request' && fromJSON('["ubuntu-latest"]') || fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]') }}
go-version: ${{ github.event_name == 'pull_request' && fromJSON('["1.25"]') || fromJSON('["1.23.10", "1.24.5", "1.25"]') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Download dependencies
run: go mod download
- name: Verify dependencies
run: go mod verify
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- name: Copy frontend dist for embedding
if: matrix.os != 'windows-latest'
run: |
rm -rf web/frontend
mkdir -p web/frontend
cp -r frontend/dist web/frontend/
- name: Copy frontend dist for embedding (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
if (Test-Path web/frontend) { Remove-Item -Recurse -Force web/frontend }
New-Item -ItemType Directory -Force -Path web/frontend
Copy-Item -Recurse frontend/dist web/frontend/
- name: Run unit tests (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: go test -v -race -timeout 5m '-coverprofile=coverage.out' -covermode=atomic '-skip=E2E|Binary|MCPProtocol|TestInfoEndpoint|TestGracefulShutdownNoPanic|TestSocketInfoEndpoint' ./...
- name: Run unit tests (Unix)
if: matrix.os != 'windows-latest'
run: go test -v -race -coverprofile=coverage.out -skip "E2E|Binary|MCPProtocol|TestInfoEndpoint|TestGracefulShutdownNoPanic|TestSocketInfoEndpoint" ./...
- name: Generate coverage report (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: go tool cover '-html=coverage.out' -o coverage.html
- name: Generate coverage report (Unix)
if: matrix.os != 'windows-latest'
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.23.10'
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Upload coverage artifacts
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.23.10'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.out
coverage.html
lint:
name: Lint
needs: [build-frontend, verify-oas]
runs-on: ubuntu-latest
env:
GO111MODULE: "on"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- name: Copy frontend dist for embedding
run: |
rm -rf web/frontend
mkdir -p web/frontend
cp -r frontend/dist web/frontend/
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.6.2
args: --timeout=5m
build:
name: Build
needs: [build-frontend, verify-oas]
runs-on: ${{ matrix.os }}
env:
GO111MODULE: "on"
strategy:
matrix:
# On PRs: build only on ubuntu-latest
# On main/push: build on all platforms
os: ${{ github.event_name == 'pull_request' && fromJSON('["ubuntu-latest"]') || fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"
cache: true
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- name: Copy frontend dist for embedding (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
if (Test-Path web/frontend) { Remove-Item -Recurse -Force web/frontend }
New-Item -ItemType Directory -Force -Path web/frontend
Copy-Item -Recurse frontend/dist web/frontend/
- name: Copy frontend dist for embedding (Unix)
if: matrix.os != 'windows-latest'
run: |
rm -rf web/frontend
mkdir -p web/frontend
cp -r frontend/dist web/frontend/
- name: Build (Windows)
if: matrix.os == 'windows-latest'
run: go build -v -o mcpproxy.exe ./cmd/mcpproxy
- name: Build (Unix)
if: matrix.os != 'windows-latest'
run: go build -v ./cmd/mcpproxy
- name: Build for different architectures (Linux only)
if: matrix.os == 'ubuntu-latest'
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o mcpproxy-linux-amd64 ./cmd/mcpproxy
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o mcpproxy-linux-arm64 ./cmd/mcpproxy
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o mcpproxy-darwin-amd64 ./cmd/mcpproxy || echo "macOS amd64 cross-compilation may fail (expected)"
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o mcpproxy-darwin-arm64 ./cmd/mcpproxy || echo "macOS arm64 cross-compilation may fail (expected)"
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o mcpproxy-windows-amd64.exe ./cmd/mcpproxy
- name: Upload build artifacts
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: binaries
path: mcpproxy-*