forked from Dicklesworthstone/ntm
-
Notifications
You must be signed in to change notification settings - Fork 0
472 lines (410 loc) · 15.2 KB
/
ci.yml
File metadata and controls
472 lines (410 loc) · 15.2 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
name: CI
on:
push:
branches: ["main", "develop"]
pull_request:
branches: ["main"]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Restrict permissions to minimum required for CI
permissions:
contents: read
security-events: write # For SARIF upload
env:
GO_VERSION: "1.25"
jobs:
# ============================================================================
# LINT - Static analysis and code quality
# ============================================================================
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install golangci-lint from source
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: Run golangci-lint
run: golangci-lint run --timeout=5m
- name: Check go mod tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum
- name: Check formatting
run: |
gofmt -l .
test -z "$(gofmt -l .)"
- name: Run go vet
run: go vet ./...
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "latest"
- name: OpenAPI drift check (TypeScript)
run: |
bun run gen:openapi
# Strip generated_at timestamp before comparing (changes on every run)
jq 'del(.generated_at)' docs/parity_matrix.json > /tmp/parity_new.json
git show HEAD:docs/parity_matrix.json | jq 'del(.generated_at)' > /tmp/parity_old.json
diff /tmp/parity_old.json /tmp/parity_new.json
git diff --exit-code docs/openapi.json
- name: Validate OpenAPI
run: bun run lint:openapi
- name: OpenAPI drift check (Go Kernel)
run: |
# Build ntm and generate kernel-based OpenAPI spec
go build -o ntm ./cmd/ntm
./ntm openapi generate -o /tmp/openapi-kernel-new.json
# Compare against checked-in spec if it exists
if [ -f docs/openapi-kernel.json ]; then
echo "Comparing generated spec against checked-in docs/openapi-kernel.json"
diff docs/openapi-kernel.json /tmp/openapi-kernel-new.json || {
echo ""
echo "========================================================================"
echo " ERROR: OpenAPI kernel spec drift detected!"
echo ""
echo " The generated OpenAPI spec differs from the checked-in version."
echo " Run: ntm openapi generate -o docs/openapi-kernel.json"
echo " Then commit the updated spec."
echo "========================================================================"
exit 1
}
echo "OpenAPI kernel spec is up to date"
else
echo "Warning: docs/openapi-kernel.json not found, skipping drift check"
fi
# ============================================================================
# TEST - Unit tests with coverage on multiple platforms
# ============================================================================
test:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
# Note: Windows excluded since ntm requires tmux which is Unix-only
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install tmux (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y tmux
- name: Install tmux (macOS)
if: runner.os == 'macOS'
run: brew install tmux
- name: Build
run: go build -v ./...
- name: Test with Coverage
run: |
go test -v -race -covermode=atomic -coverprofile=coverage.out ./...
- name: Upload Coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v5
with:
files: coverage.out
flags: unittests
name: codecov-ntm
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload Coverage Artifact
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
retention-days: 7
# ============================================================================
# COVERAGE - Enforce coverage thresholds
# ============================================================================
coverage:
name: Coverage Thresholds
runs-on: ubuntu-latest
timeout-minutes: 15
needs: test
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install tmux
run: sudo apt-get update && sudo apt-get install -y tmux
- name: Run tests with coverage
run: go test -covermode=atomic -coverprofile=coverage.out ./...
- name: Enforce Project Coverage Threshold
run: |
total=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | tr -d '%')
echo "Total coverage: ${total}%"
threshold=35
echo "Threshold: ${threshold}%"
awk -v c="$total" -v t="$threshold" 'BEGIN {
if (c < t) {
printf("Coverage %.2f%% is below threshold %.2f%%\n", c, t);
exit 1
} else {
printf("Coverage %.2f%% meets threshold %.2f%%\n", c, t);
}
}'
- name: Generate HTML Coverage Report
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload HTML Coverage Report
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: coverage.html
retention-days: 14
# ============================================================================
# BUILD - Cross-platform build verification
# ============================================================================
build:
name: Build (${{ matrix.goos }}/${{ matrix.goarch }})
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: linux
goarch: arm
goarm: "7"
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: freebsd
goarch: amd64
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
CGO_ENABLED: "0"
run: |
output="ntm-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
output="${output}.exe"
fi
if [ -n "${{ matrix.goarm }}" ]; then
output="ntm-${{ matrix.goos }}-${{ matrix.goarch }}v${{ matrix.goarm }}"
fi
go build -trimpath -ldflags="-s -w" -o "${output}" ./cmd/ntm
ls -la "${output}"
- name: Upload Binary
uses: actions/upload-artifact@v4
with:
name: ntm-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm && format('v{0}', matrix.goarm) || '' }}
path: ntm-*
retention-days: 7
# ============================================================================
# SECURITY - Vulnerability scanning
# ============================================================================
security:
name: Security Scan
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run Govulncheck
continue-on-error: true # Don't fail CI on stdlib vulnerabilities
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: Run Gosec
uses: securego/gosec@master
with:
args: "-no-fail -fmt sarif -out results.sarif ./..."
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
if: always() && hashFiles('results.sarif') != ''
continue-on-error: true # Don't fail CI if SARIF upload fails (permissions/GHAS not enabled)
with:
sarif_file: results.sarif
# ============================================================================
# GORELEASER - Verify release configuration
# ============================================================================
goreleaser-check:
name: GoReleaser Check
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Check GoReleaser config
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: check
- name: GoReleaser Dry Run
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
# Skip SBOM and signing in dry run (they require external tools)
args: release --snapshot --skip=publish,sbom,sign --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ============================================================================
# DEPENDENCY - Check for dependency issues
# ============================================================================
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: high
deny-licenses: GPL-3.0, AGPL-3.0
# ============================================================================
# INTEGRATION - Run integration tests (if tmux available)
# ============================================================================
integration:
name: Integration Tests
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install tmux
run: sudo apt-get update && sudo apt-get install -y tmux
- name: Build ntm
run: go build -o ntm ./cmd/ntm
- name: Verify ntm binary
run: |
./ntm version
./ntm --help
- name: Test shell init output
run: |
./ntm init bash | head -20
./ntm init zsh | head -20
# ============================================================================
# UPGRADE-CHECK - Verify upgrade command works against current releases
# This catches asset naming drift between upgrade.go and GoReleaser BEFORE release
# ============================================================================
upgrade-check:
name: Upgrade Check (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build ntm
run: go build -o ntm ./cmd/ntm
- name: Verify upgrade --check works
run: |
echo "Testing upgrade --check against latest release..."
# Run upgrade --check - it should either:
# 1. Find the latest release and show version info, OR
# 2. Report "no releases found" for dev/new forks (acceptable)
# It should NOT report "no suitable release asset found" (naming mismatch)
if ./ntm upgrade --check 2>&1 | tee upgrade_output.txt; then
echo "Upgrade check succeeded"
else
# Check if it's a "no releases" error (acceptable for forks/new repos)
if grep -qi "no releases found\|development version" upgrade_output.txt; then
echo "No releases found (expected for dev builds)"
exit 0
fi
echo "Upgrade check failed"
cat upgrade_output.txt
exit 1
fi
# Critical check: "no suitable release asset found" means naming mismatch
if grep -q "no suitable release asset" upgrade_output.txt; then
echo ""
echo "========================================================================"
echo " ERROR: Asset naming mismatch detected!"
echo ""
echo " upgrade.go cannot find assets from the latest release."
echo " This likely means:"
echo " 1. upgrade.go naming logic was changed, OR"
echo " 2. .goreleaser.yaml naming template was changed"
echo ""
echo " Review: TestUpgradeAssetNamingContract in cli_test.go"
echo "========================================================================"
echo ""
exit 1
fi
echo "Upgrade asset naming contract verified"
# ============================================================================
# SUMMARY - Final status check
# ============================================================================
ci-success:
name: CI Success
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [lint, test, coverage, build, security, goreleaser-check, integration, upgrade-check]
if: always()
steps:
- name: Check all jobs passed
run: |
if [ "${{ needs.lint.result }}" != "success" ] || \
[ "${{ needs.test.result }}" != "success" ] || \
[ "${{ needs.coverage.result }}" != "success" ] || \
[ "${{ needs.build.result }}" != "success" ] || \
[ "${{ needs.security.result }}" != "success" ] || \
[ "${{ needs.goreleaser-check.result }}" != "success" ] || \
[ "${{ needs.integration.result }}" != "success" ] || \
[ "${{ needs.upgrade-check.result }}" != "success" ]; then
echo "One or more jobs failed"
exit 1
fi
echo "All CI checks passed!"