-
-
Notifications
You must be signed in to change notification settings - Fork 43
284 lines (236 loc) · 7.98 KB
/
ci.yml
File metadata and controls
284 lines (236 loc) · 7.98 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
types: [ opened, synchronize, reopened ]
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: meshmonitor_test
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
node-version: [20.x, 22.x, 24.x, 25.x]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
submodules: recursive # Initialize protobufs submodule for tests
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-
${{ runner.os }}-node-
- name: Install dependencies
run: npm install --legacy-peer-deps
- name: Run linter
run: npm run lint
continue-on-error: true # Don't fail on lint errors for now
- name: Run type checking
run: npm run typecheck
- name: Run tests
run: npm run test:run -- --exclude="**/server.test.ts"
- name: Generate coverage report
if: matrix.node-version == '24.x' # Only generate coverage on one version
run: npm run test:coverage -- --exclude="**/server.test.ts"
- name: Upload coverage to Codecov
if: matrix.node-version == '24.x'
uses: codecov/codecov-action@v5
with:
files: ./coverage/coverage-final.json
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false # Don't fail if codecov is down
build:
name: Build Check
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
submodules: recursive # Initialize protobufs submodule
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24.x'
cache: 'npm'
- name: Install dependencies
run: npm install --legacy-peer-deps
- name: Build frontend
run: npm run build
- name: Build server
run: npm run build:server
- name: Check build artifacts
run: |
echo "Checking frontend build..."
ls -la dist/
echo "Checking server build..."
ls -la dist/server/
docker:
name: Docker Build
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image
uses: docker/build-push-action@v7
with:
context: .
push: false
load: true
tags: meshmonitor:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker image
run: |
docker run --rm meshmonitor:test node --version
docker run --rm meshmonitor:test ls -la /app/
security:
name: Security Scan
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Trivy
run: |
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install -y trivy
- name: Run Trivy vulnerability scanner
run: trivy fs --scanners vuln --format sarif --output trivy-results.sarif --severity HIGH,CRITICAL .
- name: Upload Trivy results to GitHub Security
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: 'trivy-results.sarif'
- name: Dependency audit
run: npm audit --audit-level=moderate
continue-on-error: true # Don't fail on audit issues for now
clamav:
name: ClamAV Scan
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install & update ClamAV
run: |
set -e
sudo apt-get update
sudo apt-get install -y clamav clamav-freshclam
sudo systemctl stop clamav-freshclam || true
sudo freshclam --verbose
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
cache: 'npm'
- name: Install dependencies
run: npm install --legacy-peer-deps
- name: Verify ClamAV detects EICAR signature
run: |
set -euo pipefail
printf 'X5O!P%%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > eicar.com
status=0
clamscan eicar.com > eicar.log 2>&1 || status=$?
cat eicar.log
if [ "$status" -ne 1 ]; then
echo "ClamAV failed to detect EICAR test signature" >&2
exit 1
fi
rm -f eicar.com eicar.log
- name: Scan source tree
run: |
set -euo pipefail
clamscan -ri --exclude-dir='^\.git$' . | tee clamav.log
if grep -qE 'Infected files: [1-9][0-9]*' clamav.log; then
echo "ClamAV found infected files!" >&2
grep 'FOUND' clamav.log >&2
exit 1
fi
- name: Upload scan results
if: always()
uses: actions/upload-artifact@v7
with:
name: clamav-scan-results
path: clamav.log
pr-comment:
name: PR Comment
runs-on: ubuntu-latest
needs: [test, build, docker]
if: github.event_name == 'pull_request'
steps:
- name: Comment on PR
uses: actions/github-script@v8
continue-on-error: true # Don't fail if we can't comment
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.payload.pull_request.number;
const { owner, repo } = context.repo;
const comment = `## ✅ CI Checks Passed
All tests and builds completed successfully!
- **Tests**: All unit tests passing
- **Type Check**: No TypeScript errors
- **Build**: Frontend and server built successfully
- **Docker**: Image builds successfully
Ready for review! 🚀`;
// Check if we already commented
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('CI Checks')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: comment
});
}