-
Notifications
You must be signed in to change notification settings - Fork 54
508 lines (437 loc) · 19.1 KB
/
lint-test.yml
File metadata and controls
508 lines (437 loc) · 19.1 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Lint and Test
on:
push:
branches:
- main
- "pull-request/[0-9]+"
tags:
- 'v*'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
permissions:
contents: read # Required for checking out code
actions: write # Required for uploading test artifacts
pull-requests: write # Required for coverage report comments
env:
# Go cache settings (specific to this workflow)
GOPATH: /home/runner/go
GOCACHE: /home/runner/.cache/go-build
jobs:
simple-lint:
if: github.repository == 'nvidia/nvsentinel'
runs-on: linux-amd64-cpu16
timeout-minutes: 30
strategy:
matrix:
include:
- component: protos
make_command: 'make protos-lint'
step_name: 'Run protos lint'
- component: license-headers
make_command: 'make license-headers-lint'
step_name: 'Run license headers check'
- component: gomod
make_command: 'make gomod-lint'
step_name: 'Run gomod lint'
- component: log-collector
make_command: 'make -C log-collector lint-log-collector'
step_name: 'Run lint'
replace_imports: 'false'
- component: gpu-reset
make_command: 'make -C gpu-reset lint'
step_name: 'Run lint'
replace_imports: 'false'
- component: file-server-cleanup
make_command: 'make -C log-collector lint-file-server-cleanup'
step_name: 'Run lint'
replace_imports: 'false'
- component: kubernetes-distro
make_command: 'make kubernetes-distro-lint'
step_name: 'Run lint'
- component: helm-charts
make_command: 'make helm-lint'
step_name: 'Validate Helm charts'
- component: postgres-schema
make_command: 'make validate-postgres-schema'
step_name: 'Validate PostgreSQL schema consistency'
- component: scripts
make_command: 'make -C scripts lint'
step_name: 'Run shellcheck on scripts'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup build environment
uses: ./.github/actions/setup-ci-env
- name: ${{ matrix.step_name }}
run: ${{ matrix.make_command }}
- name: Load Helm version from .versions.yaml
if: matrix.component == 'helm-charts'
id: helm-version
run: |
HELM_VERSION=$(yq eval '.testing_tools.helm' .versions.yaml)
echo "helm_version=${HELM_VERSION}" >> $GITHUB_OUTPUT
- name: Setup Helm
if: matrix.component == 'helm-charts'
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
with:
version: ${{ steps.helm-version.outputs.helm_version }}
- name: Validate Helm Charts
if: matrix.component == 'helm-charts'
run: make helm-lint
health-monitors-lint-test:
if: github.repository == 'nvidia/nvsentinel'
runs-on: linux-amd64-cpu16
timeout-minutes: 30
strategy:
matrix:
include:
- component: syslog-health-monitor
- component: csp-health-monitor
- component: kubernetes-object-monitor
- component: gpu-health-monitor
install_dcgm: 'true'
python_required: 'true'
replace_imports: 'false'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup build environment
uses: ./.github/actions/setup-ci-env
- name: Run lint and test
run: make -C health-monitors/${{ matrix.component }} lint-test
- name: Upload artifacts
uses: ./.github/actions/upload-test-artifacts
with:
component-name: ${{ matrix.component }}
file-paths: |
health-monitors/${{ matrix.component }}/coverage.xml
health-monitors/${{ matrix.component }}/coverage.txt
health-monitors/${{ matrix.component }}/report.xml
preflight-checks-lint-test:
if: github.repository == 'nvidia/nvsentinel'
runs-on: linux-amd64-cpu16
timeout-minutes: 30
strategy:
matrix:
component:
- dcgm-diag
- nccl-allreduce
- nccl-loopback
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup build environment
uses: ./.github/actions/setup-ci-env
- name: Run lint and test
run: make -C preflight-checks/${{ matrix.component }} lint-test
modules-lint-test:
if: github.repository == 'nvidia/nvsentinel'
runs-on: linux-amd64-cpu16
timeout-minutes: 30
strategy:
matrix:
component:
- platform-connectors
- event-exporter
- store-client
- commons
- data-models
- health-events-analyzer
- fault-quarantine
- labeler
- metadata-collector
- node-drainer
- fault-remediation
- janitor
- preflight
- tests
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup build environment
uses: ./.github/actions/setup-ci-env
- name: Run lint and test
run: make -C ${{ matrix.component }} lint-test
- name: Upload artifacts
uses: ./.github/actions/upload-test-artifacts
with:
component-name: ${{ matrix.component }}
file-paths: |
${{ matrix.component }}/coverage.xml
${{ matrix.component }}/coverage.txt
${{ matrix.component }}/report.xml
plugins-lint-test:
if: github.repository == 'nvidia/nvsentinel'
runs-on: linux-amd64-cpu16
timeout-minutes: 30
strategy:
matrix:
component:
- plugins/slinky-drainer
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup build environment
uses: ./.github/actions/setup-ci-env
- name: Run lint and test
run: make -C ${{ matrix.component }} lint-test
- name: Upload artifacts
uses: ./.github/actions/upload-test-artifacts
with:
component-name: slinky-drainer
file-paths: |
${{ matrix.component }}/coverage.xml
${{ matrix.component }}/coverage.txt
${{ matrix.component }}/report.xml
tilt-modules-lint-test:
if: github.repository == 'nvidia/nvsentinel'
runs-on: linux-amd64-cpu16
timeout-minutes: 30
strategy:
matrix:
component:
- tilt/simple-health-client
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup build environment
uses: ./.github/actions/setup-ci-env
- name: Run lint and test
run: make -C ${{ matrix.component }} lint-test
- name: Upload artifacts
uses: ./.github/actions/upload-test-artifacts
with:
component-name: simple-health-client
file-paths: |
${{ matrix.component }}/coverage.xml
${{ matrix.component }}/coverage.txt
${{ matrix.component }}/report.xml
consolidated-coverage-report:
if: github.repository == 'nvidia/nvsentinel' && (github.event_name == 'pull_request' || startsWith(github.ref, 'refs/heads/pull-request/'))
runs-on: linux-amd64-cpu16
timeout-minutes: 15
needs: [health-monitors-lint-test, preflight-checks-lint-test, modules-lint-test, plugins-lint-test, tilt-modules-lint-test]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: 'stable'
- name: Download all coverage artifacts
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
pattern: "*-results"
path: coverage-artifacts
merge-multiple: false
- name: Consolidate coverage files
run: |
set -e
echo "Consolidating coverage files from all components..."
mkdir -p consolidated-coverage
# Initialize consolidated coverage with mode line
echo "mode: set" > consolidated-coverage/coverage.txt
# Find all coverage.txt files and merge them properly
find coverage-artifacts -name "coverage.txt" -type f | while read -r file; do
echo "Processing: $file"
# Validate file exists and is not empty
if [[ ! -f "$file" || ! -s "$file" ]]; then
echo "Warning: Skipping empty or missing file: $file"
continue
fi
# Validate coverage file format
if ! head -n 1 "$file" | grep -q "^mode:"; then
echo "Warning: Skipping file with invalid format (no mode line): $file"
continue
fi
# Extract coverage data (skip mode line) and validate each line
tail -n +2 "$file" | while IFS= read -r line; do
# Skip empty lines
[[ -z "$line" ]] && continue
# Validate coverage line format: file.go:start.col,end.col numStmts count
if [[ "$line" =~ ^[^:]+:[0-9]+\.[0-9]+,[0-9]+\.[0-9]+[[:space:]]+[0-9]+[[:space:]]+[0-9]+$ ]]; then
echo "$line" >> consolidated-coverage/coverage.txt
else
echo "Warning: Skipping malformed coverage line: $line"
fi
done
done
echo "✅ Coverage consolidation completed successfully"
- name: Upload consolidated coverage
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: consolidated-code-coverage
path: consolidated-coverage/coverage.txt
retention-days: 30
- name: Extract PR number from branch name
id: pr-number
run: |
if [[ "${{ github.ref }}" =~ pull-request/([0-9]+) ]]; then
echo "pr_number=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
else
echo "pr_number=" >> $GITHUB_OUTPUT
fi
- name: Install go-coverage-report CLI tool
run: go install github.com/fgrosse/go-coverage-report/cmd/go-coverage-report@v1.2.0
- name: Get changed files
uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11
id: changed-files
with:
write_output_files: true
json: true
files: "**.go"
files_ignore: "vendor/**"
output_dir: .github/outputs
- name: Generate Coverage Report with Fixed PR Number
if: steps.changed-files.outputs.any_changed == 'true'
run: |
set -e # Exit on error
# Use the locally consolidated coverage file (no download needed!)
echo "Using locally consolidated coverage..."
mkdir -p .github/outputs
if [[ ! -f consolidated-coverage/coverage.txt || ! -s consolidated-coverage/coverage.txt ]]; then
echo "❌ Consolidated coverage file not found or empty"
exit 1
fi
# Copy (don't move) so the artifact upload still has the original
cp consolidated-coverage/coverage.txt .github/outputs/new-coverage.txt
echo "✅ Current coverage prepared from local file"
# Download baseline coverage from main (failure here is acceptable)
echo "Downloading baseline coverage..."
LAST_SUCCESSFUL_RUN=$(gh run list --status=success --branch=main --workflow=lint-test.yml --event=push --json=databaseId --limit=1 -q '.[] | .databaseId')
if [[ -n "$LAST_SUCCESSFUL_RUN" ]]; then
echo "Found baseline run: $LAST_SUCCESSFUL_RUN"
if gh run download "$LAST_SUCCESSFUL_RUN" --name=consolidated-code-coverage --dir=/tmp/baseline-coverage 2>/dev/null; then
if [[ -f /tmp/baseline-coverage/coverage.txt ]]; then
echo "✅ Baseline coverage found"
mv /tmp/baseline-coverage/coverage.txt .github/outputs/old-coverage.txt
else
echo "⚠️ Baseline coverage file not found in artifact"
touch .github/outputs/old-coverage.txt # Create empty file
fi
else
echo "⚠️ Failed to download baseline coverage (creating empty baseline)"
touch .github/outputs/old-coverage.txt # Create empty file
fi
else
echo "⚠️ No successful baseline run found (creating empty baseline)"
touch .github/outputs/old-coverage.txt # Create empty file
fi
# Generate the report using fgrosse's CLI tool (same format!)
echo "Generating coverage report..."
if ! go-coverage-report -root=github.com/nvidia/nvsentinel \
.github/outputs/old-coverage.txt \
.github/outputs/new-coverage.txt \
.github/outputs/all_modified_files.json > coverage-report.md 2> coverage-report.err; then
echo "❌ Failed to generate coverage report"
exit 1
fi
# Check if report is empty and why
if [[ ! -f coverage-report.md || ! -s coverage-report.md ]]; then
if grep -q "no changed files" coverage-report.err 2>/dev/null; then
echo "ℹ️ No Go files changed - skipping coverage report"
echo "## 📊 Coverage Report" > coverage-report.md
echo "No Go files were modified in this PR, so no coverage analysis is needed." >> coverage-report.md
else
echo "❌ Coverage report is empty or missing for unknown reason"
echo "Error output from go-coverage-report:"
cat coverage-report.err || echo "No error output"
exit 1
fi
fi
echo "✅ Coverage report generated successfully"
# Check if coverage report indicates no change to avoid spam
if grep -q "will \*\*not change\*\* overall coverage" coverage-report.md; then
echo "ℹ️ Coverage report shows no change - skipping PR comment to reduce noise"
exit 0
fi
# Post comment using our correct PR number
if [[ -n "${{ steps.pr-number.outputs.pr_number }}" ]]; then
echo "Posting coverage comment to PR #${{ steps.pr-number.outputs.pr_number }}..."
# Check for existing coverage comment
EXISTING_COMMENT=$(gh api "repos/${{ github.repository }}/issues/${{ steps.pr-number.outputs.pr_number }}/comments" \
--jq '.[] | select(.user.login=="github-actions[bot]" and (.body | test("Coverage Report|Coverage Δ"))) | .id' \
| head -1 2>/dev/null || echo "")
if [[ -n "$EXISTING_COMMENT" ]]; then
echo "Updating existing comment $EXISTING_COMMENT..."
if ! gh api "repos/${{ github.repository }}/issues/${{ steps.pr-number.outputs.pr_number }}/comments/$EXISTING_COMMENT" \
--method PATCH --input coverage-report.md; then
echo "⚠️ Failed to update existing comment (likely permissions), creating new comment instead..."
if ! gh pr comment "${{ steps.pr-number.outputs.pr_number }}" --body-file=coverage-report.md; then
echo "❌ Failed to create new coverage comment"
exit 1
fi
fi
else
echo "Creating new comment..."
if ! gh pr comment "${{ steps.pr-number.outputs.pr_number }}" --body-file=coverage-report.md; then
echo "❌ Failed to create coverage comment"
exit 1
fi
fi
echo "✅ Coverage comment posted successfully"
else
echo "⚠️ No PR number found, skipping comment"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
consolidated-coverage-baseline:
if: github.repository == 'nvidia/nvsentinel' && github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: linux-amd64-cpu16
timeout-minutes: 15
needs: [health-monitors-lint-test, preflight-checks-lint-test, modules-lint-test, plugins-lint-test, tilt-modules-lint-test]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download all coverage artifacts
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
pattern: "*-results"
path: coverage-artifacts
merge-multiple: false
- name: Consolidate coverage files
run: |
set -e
echo "Consolidating coverage files from all components for baseline..."
mkdir -p consolidated-coverage
# Initialize consolidated coverage with mode line
echo "mode: set" > consolidated-coverage/coverage.txt
# Find all coverage.txt files and merge them properly
find coverage-artifacts -name "coverage.txt" -type f | while read -r file; do
echo "Processing: $file"
# Validate file exists and is not empty
if [[ ! -f "$file" || ! -s "$file" ]]; then
echo "Warning: Skipping empty or missing file: $file"
continue
fi
# Validate coverage file format
if ! head -n 1 "$file" | grep -q "^mode:"; then
echo "Warning: Skipping file with invalid format (no mode line): $file"
continue
fi
# Extract coverage data (skip mode line) and validate each line
tail -n +2 "$file" | while IFS= read -r line; do
# Skip empty lines
[[ -z "$line" ]] && continue
# Validate coverage line format: file.go:start.col,end.col numStmts count
if [[ "$line" =~ ^[^:]+:[0-9]+\.[0-9]+,[0-9]+\.[0-9]+[[:space:]]+[0-9]+[[:space:]]+[0-9]+$ ]]; then
echo "$line" >> consolidated-coverage/coverage.txt
else
echo "Warning: Skipping malformed coverage line: $line"
fi
done
done
echo "✅ Coverage consolidation completed successfully"
- name: Upload consolidated coverage baseline
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: consolidated-code-coverage
path: consolidated-coverage/coverage.txt
retention-days: 90 # Keep baseline longer