-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
436 lines (344 loc) · 16.7 KB
/
Copy pathjustfile
File metadata and controls
436 lines (344 loc) · 16.7 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
# opnConfigGenerator Justfile
set shell := ["bash", "-cu"]
set windows-powershell := true
set dotenv-load := true
set ignore-comments := true
# Use mise to manage all dev tools (go, pre-commit, uv, etc.)
# See mise.toml for tool versions
mise_exec := "mise exec --"
# ─────────────────────────────────────────────────────────────────────────────
# Variables
# ─────────────────────────────────────────────────────────────────────────────
project_dir := justfile_directory()
binary_name := "opnconfiggenerator"
# Platform-specific commands
_cmd_exists := if os_family() == "windows" { "where" } else { "command -v" }
_null := if os_family() == "windows" { "nul" } else { "/dev/null" }
# Act configuration
act_arch := "linux/amd64"
act_cmd := mise_exec + " act --container-architecture " + act_arch
# ─────────────────────────────────────────────────────────────────────────────
# Default & Help
# ─────────────────────────────────────────────────────────────────────────────
[private]
default:
@just --list --unsorted
alias h := help
alias l := list
# Show available recipes
[group('help')]
help:
@just --list
# Show recipes in a specific group
[group('help')]
list group="":
@just --list --unsorted {{ if group != "" { "--list-heading='' --list-prefix=' ' | grep -A999 '" + group + "'" } else { "" } }}
# ─────────────────────────────────────────────────────────────────────────────
# Setup & Installation
# ─────────────────────────────────────────────────────────────────────────────
alias i := install
# Install all dependencies and setup environment
[group('setup')]
install:
@mise install
@{{ mise_exec }} pre-commit install --hook-type commit-msg
@{{ mise_exec }} go mod tidy
# Alias for install
[group('setup')]
setup: install
# Update all dependencies
[group('setup')]
update-deps: _update-go _update-precommit
[private]
_update-go:
@{{ mise_exec }} go get -u ./...
@{{ mise_exec }} go mod tidy
@{{ mise_exec }} go mod verify
[private]
_update-precommit:
@{{ mise_exec }} pre-commit autoupdate
# Install security and SBOM tools (cyclonedx-gomod, gosec)
[group('setup')]
install-security-tools:
@{{ mise_exec }} go install github.com/securego/gosec/v2/cmd/gosec@latest
@{{ mise_exec }} go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
# cosign is now handled by mise
# ─────────────────────────────────────────────────────────────────────────────
# Development
# ─────────────────────────────────────────────────────────────────────────────
alias r := run
# Run the application with optional arguments
[group('dev')]
run *args:
@{{ mise_exec }} go run main.go {{ args }}
# Run in development mode (alias for run)
[group('dev')]
dev *args:
@{{ mise_exec }} go run main.go {{ args }}
# ─────────────────────────────────────────────────────────────────────────────
# Code Quality
# ─────────────────────────────────────────────────────────────────────────────
alias f := format
alias fmt := format
# Format code and apply fixes
[group('quality')]
format:
@{{ mise_exec }} golangci-lint run --fix ./...
@just modernize
# Check formatting without making changes
[group('quality')]
format-check:
@{{ mise_exec }} golangci-lint fmt ./...
# Run linter
[group('quality')]
lint:
@{{ mise_exec }} golangci-lint run ./...
@just modernize-check
# Run pre-commit checks on all files
[group('quality')]
check:
@{{ mise_exec }} pre-commit run --all-files
# Apply Go modernization fixes
[group('quality')]
modernize:
@{{ mise_exec }} go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
# Check for modernization opportunities (dry-run)
[group('quality')]
modernize-check:
@{{ mise_exec }} go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
# ─────────────────────────────────────────────────────────────────────────────
# Testing
# ─────────────────────────────────────────────────────────────────────────────
alias t := test
# Run all tests
[group('test')]
test:
@{{ mise_exec }} go test ./...
# Run tests with verbose output
[group('test')]
test-v:
@{{ mise_exec }} go test -v ./...
# Run tests with coverage report
[group('test')]
test-coverage:
@{{ mise_exec }} go test -coverprofile=coverage.txt ./...
@{{ mise_exec }} go tool cover -func=coverage.txt
# Run integration tests (build tag)
[group('test')]
test-integration:
@{{ mise_exec }} go test -tags=integration ./...
# Run tests with race detector
[group('test')]
test-race:
@{{ mise_exec }} go test -race -timeout 10m ./...
# Run stress tests (heavy load testing)
[group('test')]
test-stress:
@{{ mise_exec }} go test -tags=stress -timeout 5m ./...
# Run tests and open coverage in browser
[group('test')]
coverage:
@{{ mise_exec }} go test -coverprofile=coverage.txt ./...
@{{ mise_exec }} go tool cover -html=coverage.txt
# Generate coverage artifact
[group('test')]
cover: test-coverage
# Run benchmarks
[group('test')]
bench:
@{{ mise_exec }} go test -bench=. ./...
# Run memory benchmarks for generators
[group('test')]
bench-mem:
@{{ mise_exec }} go test -bench=. -benchmem ./internal/generator/...
# Run comprehensive performance benchmarks
[group('test')]
bench-perf:
@{{ mise_exec }} go test -bench=. -run=^$ -benchtime=1s -count=3 ./internal/opnsensegen/...
# Save benchmark baseline for comparison
[group('test')]
bench-save:
@{{ mise_exec }} go test -bench=. -run=^$ -benchmem -count=5 ./... 2>/dev/null | tee .benchmark-baseline.txt
# Compare current benchmarks against baseline
[group('test')]
bench-compare:
@if [ ! -f .benchmark-baseline.txt ]; then \
echo "No baseline found. Run 'just bench-save' first."; \
exit 1; \
fi
@{{ mise_exec }} go test -bench=. -run=^$ -benchmem -count=5 ./... 2>/dev/null | tee .benchmark-current.txt
@{{ mise_exec }} go install golang.org/x/perf/cmd/benchstat@latest
@{{ mise_exec }} benchstat .benchmark-baseline.txt .benchmark-current.txt
# Run startup time benchmarks
[group('test')]
bench-startup:
@{{ mise_exec }} go test -bench=BenchmarkStartup -run=^$ -benchmem ./cmd/...
# Run network utility benchmarks
[group('test')]
bench-netutil:
@{{ mise_exec }} go test -bench=. -run=^$ -benchmem ./internal/netutil/...
# Run validation tests with verbose output
[group('test')]
validate-check:
@{{ mise_exec }} go test -v ./internal/validate/...
# ─────────────────────────────────────────────────────────────────────────────
# Build
# ─────────────────────────────────────────────────────────────────────────────
alias b := build
# Build the binary
[group('build')]
build:
@{{ mise_exec }} go build -o {{ binary_name }}{{ if os_family() == "windows" { ".exe" } else { "" } }} main.go
# Build with optimizations for release
[group('build')]
build-release:
@CGO_ENABLED=0 {{ mise_exec }} go build -trimpath -ldflags="-s -w" -o {{ binary_name }}{{ if os_family() == "windows" { ".exe" } else { "" } }} main.go
# Clean build artifacts
[group('build')]
[confirm("This will remove build artifacts. Continue?")]
clean:
@{{ mise_exec }} go clean
@rm -f coverage.txt {{ binary_name }} {{ binary_name }}.exe 2>{{ _null }} || true
# Clean and rebuild
[group('build')]
rebuild: clean build
# ─────────────────────────────────────────────────────────────────────────────
# Release (GoReleaser)
# ─────────────────────────────────────────────────────────────────────────────
# Check GoReleaser configuration
[group('release')]
release-check:
@{{ mise_exec }} goreleaser check --verbose
# Build snapshot (no tag required)
[group('release')]
release-snapshot:
@{{ mise_exec }} goreleaser build --clean --snapshot
# Build for current platform only
[group('release')]
release-local:
@{{ mise_exec }} goreleaser build --clean --snapshot --single-target
# Full release (requires git tag and GITHUB_TOKEN)
[group('release')]
[confirm("This will create a GitHub release. Continue?")]
release: check test
@{{ mise_exec }} goreleaser release --clean
# ─────────────────────────────────────────────────────────────────────────────
# Documentation
# ─────────────────────────────────────────────────────────────────────────────
alias d := docs
# Serve documentation locally
[group('docs')]
docs:
@{{ mise_exec }} uv run mkdocs serve
# Alias for docs
[group('docs')]
site: docs
# Build documentation
[group('docs')]
docs-build:
@{{ mise_exec }} uv run mkdocs build
# Build documentation with verbose output
[group('docs')]
docs-test:
@{{ mise_exec }} uv run mkdocs build --verbose
# Generate CLI documentation
[group('docs')]
generate-docs:
@echo "No docgen tool configured yet — use 'just run --help' to preview CLI docs"
# ─────────────────────────────────────────────────────────────────────────────
# Changelog
# ─────────────────────────────────────────────────────────────────────────────
# Generate changelog
[group('docs')]
changelog: _require-git-cliff
@{{ mise_exec }} git-cliff --output CHANGELOG.md
# Generate changelog for a specific version
[group('docs')]
changelog-version version: _require-git-cliff
@{{ mise_exec }} git-cliff --tag {{ version }} --output CHANGELOG.md
# Generate changelog for unreleased changes only
[group('docs')]
changelog-unreleased: _require-git-cliff
@{{ mise_exec }} git-cliff --unreleased --output CHANGELOG.md
[private]
_require-git-cliff:
#!/usr/bin/env bash
if ! command -v git-cliff >/dev/null 2>&1; then
echo "Error: git-cliff not found. Run 'just install' to install it."
exit 1
fi
# ─────────────────────────────────────────────────────────────────────────────
# Security
# ─────────────────────────────────────────────────────────────────────────────
# Run gosec security scanner
# Excludes: G115 (safe narrowing), G302/G304 (CLI file I/O), G404 (intentional math/rand for fake data)
[group('security')]
scan:
@{{ mise_exec }} gosec -exclude=G115,G302,G304,G404 ./...
# Generate SBOM with cyclonedx-gomod
[group('security')]
sbom: build-release
@{{ mise_exec }} cyclonedx-gomod bin -output sbom-binary.cyclonedx.json ./{{ binary_name }}{{ if os_family() == "windows" { ".exe" } else { "" } }}
@{{ mise_exec }} cyclonedx-gomod app -output sbom-modules.cyclonedx.json -json .
# Run all security checks (SBOM + security scan)
[group('security')]
security-all: sbom scan
# ─────────────────────────────────────────────────────────────────────────────
# Licensing
# ─────────────────────────────────────────────────────────────────────────────
# Generate THIRD_PARTY_NOTICES from dependency licenses
[group('licensing')]
notices:
@{{ mise_exec }} go-licenses report ./... \
--ignore github.com/EvilBit-Labs/opnConfigGenerator \
--template packaging/notices.tpl > THIRD_PARTY_NOTICES
# ─────────────────────────────────────────────────────────────────────────────
# CI
# ─────────────────────────────────────────────────────────────────────────────
# Run full CI checks (pre-commit, format, lint, test)
[group('ci')]
ci-check: check format-check lint test test-integration test-race
# Run smoke tests (fast, minimal validation)
[group('ci')]
ci-smoke:
@{{ mise_exec }} go build -trimpath -ldflags="-s -w -X main.version=dev" -v ./...
@{{ mise_exec }} go test -count=1 -failfast -short -timeout 5m ./cmd/... ./internal/errors/...
# Run full checks including security and release validation
[group('ci')]
ci-full: ci-check security-all release-check docs-test
# ─────────────────────────────────────────────────────────────────────────────
# GitHub Actions (act)
# ─────────────────────────────────────────────────────────────────────────────
[private]
_require-act:
#!/usr/bin/env bash
if ! command -v act >/dev/null 2>&1; then
echo "Error: act not found. Install: brew install act"
exit 1
fi
# List available GitHub Actions workflows
[group('act')]
act-list: _require-act
@{{ act_cmd }} --list
# Run a specific workflow
[group('act')]
act-run workflow: _require-act
@{{ act_cmd }} --workflows .github/workflows/{{ workflow }}.yml --verbose
# Dry-run a workflow (list steps only)
[group('act')]
act-dry workflow: _require-act
@{{ act_cmd }} --workflows .github/workflows/{{ workflow }}.yml --list
# Test PR workflow locally
[group('act')]
act-pr: _require-act
@{{ act_cmd }} pull_request --verbose
# Test push workflow locally
[group('act')]
act-push: _require-act
@{{ act_cmd }} push --verbose
# Test all PR workflows (dry-run)
[group('act')]
act-test-all: _require-act
@{{ mise_exec }} just act-dry ci
@{{ mise_exec }} just act-dry sbom
@{{ mise_exec }} just act-dry scorecard