-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
310 lines (276 loc) · 10.5 KB
/
justfile
File metadata and controls
310 lines (276 loc) · 10.5 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
# Justfile - Command runner for Kairo project
# Converted from Makefile to maintain functional equivalence
#
# Key syntax differences from Make:
# - Variables use {{VARIABLE}} for substitution
# - Shell commands use $() syntax
# - No .PHONY needed (Just is a command runner, not build system)
# - Recipe indentation: 2 spaces (must be consistent)
# - @ prefix suppresses command echoing (same as Make)
# - - prefix ignores errors (same as Make)
# Use bash for consistent shell behavior across platforms
set shell := ["bash", "-c"]
# Detect Go binary - try common paths on Windows and Unix
GO := `which go || which /c/Program\ Files/Go/bin/go.exe || which /usr/local/go/bin/go || echo go`
# Variables
BINARY_NAME := "kairo"
DIST_DIR := "dist"
VERSION := `git describe --tags --always --dirty 2>/dev/null || echo "dev"`
COMMIT := `git rev-parse --short HEAD 2>/dev/null || echo "unknown"`
DATE := `date -u +%Y-%m-%d 2>/dev/null || date +%Y-%m-%d`
LDFLAGS := "-X github.com/dkmnx/kairo/internal/version.Version=" + VERSION + " -X github.com/dkmnx/kairo/internal/version.Commit=" + COMMIT + " -X github.com/dkmnx/kairo/internal/version.Date=" + DATE
LOCAL_BIN := `echo "$HOME/.local/bin" 2>/dev/null || echo "$USERPROFILE/.local/bin"`
# Default recipe: show list of recipes
[default]
_:
@just --list
# Build the binary
build:
@echo "Building {{BINARY_NAME}} {{VERSION}}..."
@mkdir -p {{DIST_DIR}}
{{GO}} build -ldflags "{{LDFLAGS}}" -o {{DIST_DIR}}/{{BINARY_NAME}} .
# Run all tests with race detector
test:
@echo "Running tests..."
{{GO}} test -v -race ./...
# Run fuzzing tests with timeout
fuzz:
@echo "Running fuzzing tests (5s per test)..."
@echo ""
@echo "=== internal/validate ==="
{{GO}} test -fuzz=FuzzValidateAPIKey -fuzztime=5s ./internal/validate/
{{GO}} test -fuzz=FuzzValidateURL -fuzztime=5s ./internal/validate/
{{GO}} test -fuzz=FuzzValidateProviderModel -fuzztime=5s ./internal/validate/
{{GO}} test -fuzz=FuzzValidateCrossProviderConfig -fuzztime=5s ./internal/validate/
@echo ""
@echo "=== cmd ==="
{{GO}} test -fuzz=FuzzValidateCustomProviderName -fuzztime=5s ./cmd/
@echo ""
@echo "Fuzzing tests completed!"
# Run tests with coverage report
test-coverage:
@echo "Running tests with coverage..."
@mkdir -p {{DIST_DIR}}
{{GO}} test -coverprofile={{DIST_DIR}}/coverage.out ./...
{{GO}} tool cover -html={{DIST_DIR}}/coverage.out -o {{DIST_DIR}}/coverage.html
@echo "Coverage report: {{DIST_DIR}}/coverage.html"
# Run linters
lint:
@echo "Running linters..."
@TMPFILE=$(mktemp -t gofmt_issues.XXXXXX) && \
gofmt -l . > "$$TMPFILE" && \
if [ -s "$$TMPFILE" ]; then \
echo "Formatting issues found (cannot be auto-fixed):"; \
cat "$$TMPFILE"; \
rm -f "$$TMPFILE"; \
exit 1; \
fi && \
rm -f "$$TMPFILE"
{{GO}} vet ./...
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed, skipping"; \
fi
# Run pre-commit hooks
pre-commit:
@echo "Running pre-commit hooks..."
@if command -v pre-commit >/dev/null 2>&1; then \
pre-commit run --all-files; \
else \
echo "pre-commit not installed. Install with: pip install pre-commit"; \
fi
# Install pre-commit hooks
pre-commit-install:
@echo "Installing pre-commit hooks..."
@if command -v pre-commit >/dev/null 2>&1; then \
pre-commit install; \
else \
echo "pre-commit not installed. Install with: pip install pre-commit"; \
fi
# Pre-release checks: format, lint, pre-commit, test
pre-release:
@echo "Running pre-release checks..."
@echo ""
just format
@echo ""
just lint
@echo ""
just pre-commit
@echo ""
just test
@echo ""
@echo "Pre-release checks passed!"
# Format code
format:
@echo "Formatting code..."
gofmt -w .
# Clean build artifacts
clean:
@echo "Cleaning..."
rm -rf {{DIST_DIR}}
# Install binary to local bin directory
install: build
@echo "Installing {{BINARY_NAME}} to {{LOCAL_BIN}}..."
@if [ -f scripts/install.sh ]; then \
./scripts/install.sh -b {{LOCAL_BIN}}; \
else \
mkdir -p {{LOCAL_BIN}}; \
install -m 755 {{DIST_DIR}}/{{BINARY_NAME}} {{LOCAL_BIN}}/{{BINARY_NAME}}; \
echo "Installed {{BINARY_NAME}} to {{LOCAL_BIN}}/"; \
fi
# Uninstall binary
uninstall:
@echo "Removing {{BINARY_NAME}} from ~/.local/bin..."
rm -f {{LOCAL_BIN}}/{{BINARY_NAME}}
@echo "Uninstalled {{BINARY_NAME}} from {{LOCAL_BIN}}/"
# Build and run with arguments
run args="": build
@echo "Running {{BINARY_NAME}}..."
{{DIST_DIR}}/{{BINARY_NAME}} {{args}}
# Download and tidy dependencies
deps:
@echo "Installing dependencies..."
{{GO}} mod download
{{GO}} mod tidy
@echo "Installing development tools..."
@if command -v golangci-lint >/dev/null 2>&1; then \
echo "golangci-lint already installed"; \
else \
echo "Installing golangci-lint v1.64.8..."; \
{{GO}} install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8; \
fi
@if command -v pre-commit >/dev/null 2>&1; then \
echo "pre-commit already installed"; \
else \
echo "Installing pre-commit..."; \
pip install pre-commit; \
fi
@if command -v govulncheck >/dev/null 2>&1; then \
echo "govulncheck already installed"; \
else \
echo "Installing govulncheck..."; \
{{GO}} install golang.org/x/vuln/cmd/govulncheck@latest; \
fi
@if command -v goreleaser >/dev/null 2>&1; then \
echo "goreleaser already installed"; \
else \
echo "Installing goreleaser..."; \
{{GO}} install github.com/goreleaser/goreleaser/v2@latest 2>&1 || \
echo "⚠️ goreleaser installation failed (requires Go 1.26+ for full installation)"; \
echo " goreleaser is only needed for releases. Skipping for now."; \
fi
@if command -v act >/dev/null 2>&1; then \
echo "act already installed"; \
else \
echo "Installing act..."; \
curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sh; \
fi
@if command -v staticcheck >/dev/null 2>&1; then \
echo "staticcheck already installed"; \
else \
echo "Installing staticcheck..."; \
{{GO}} install honnef.co/go/tools/cmd/staticcheck@latest; \
fi
@echo "Installing pre-commit hooks..."
pre-commit install
# Verify dependencies
verify-deps:
@echo "Verifying dependencies..."
{{GO}} mod verify
# Run vulnerability scan
vuln-scan:
@echo "Running vulnerability scan..."
@if command -v govulncheck >/dev/null 2>&1; then \
govulncheck ./...; \
else \
echo "govulncheck not installed. Install with:"; \
echo " go install golang.org/x/vuln/cmd/govulncheck@latest"; \
exit 1; \
fi
# Run comprehensive security checks (vuln scan + lint)
security: vuln-scan lint
@echo "Security checks passed!"
# Create release builds with goreleaser
release:
@echo "Running goreleaser..."
@if command -v goreleaser >/dev/null 2>&1; then \
if [ -z "$GITHUB_TOKEN" ]; then \
echo "GITHUB_TOKEN not set."; \
else \
goreleaser release --clean; \
fi; \
else \
echo "goreleaser not installed. Install with: go install github.com/goreleaser/goreleaser/v2@latest"; \
fi
# Create local snapshot build
release-local:
@echo "Running goreleaser (snapshot build)..."
@if command -v goreleaser >/dev/null 2>&1; then \
goreleaser release --clean --snapshot; \
else \
echo "goreleaser not installed. Install with: go install github.com/goreleaser/goreleaser/v2@latest"; \
fi
# Build without publishing (dry-run)
release-dry-run:
@echo "Running goreleaser (dry-run, no publish)..."
@if command -v goreleaser >/dev/null 2>&1; then \
goreleaser release --clean --snapshot --skip=publish; \
else \
echo "goreleaser not installed. Install with: go install github.com/goreleaser/goreleaser/v2@latest"; \
fi
# Display help message
help:
@echo "Kairo Justfile"
@echo ""
@echo "Output directory: {{DIST_DIR}}/"
@echo "Install location: {{LOCAL_BIN}}/"
@echo ""
@echo "Recipes:"
@echo " default - Build the binary (default)"
@echo " build - Build the binary to {{DIST_DIR}}/"
@echo " test - Run all tests"
@echo " fuzz - Run fuzzing tests (10s per package)"
@echo " test-coverage - Run tests with coverage report"
@echo " lint - Run linters (gofmt, govet)"
@echo " format - Format code with gofmt"
@echo " pre-commit - Run pre-commit hooks"
@echo " pre-release - Run all pre-release checks (format, lint, pre-commit, test)"
@echo " clean - Remove {{DIST_DIR}}/ directory"
@echo " install - Install to {{LOCAL_BIN}}/"
@echo " uninstall - Remove from {{LOCAL_BIN}}/"
@echo " run - Build and run with ARGS"
@echo " release - Create release builds with goreleaser"
@echo " release-local - Create local snapshot build"
@echo " release-dry-run - Build without publishing"
@echo " deps - Download and tidy dependencies"
@echo " verify-deps - Verify dependency checksums"
@echo " vuln-scan - Run vulnerability scan with govulncheck"
@echo " security - Run comprehensive security checks (vuln-scan + lint)"
@echo " ci-local - Run GitHub Actions locally with act"
@echo " ci-local-list - List all CI jobs"
@echo " help - Show this help message"
@echo ""
@echo "Recipe arguments:"
@echo " just run 'args --help' - Run with specific arguments"
@echo " just ci-local '-l' - List CI jobs"
# List all CI jobs
ci-local-list:
@echo "Listing GitHub Actions jobs..."
@if command -v act >/dev/null 2>&1; then \
act -l; \
else \
echo "act not installed. Install with:"; \
echo " curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sh"; \
echo " or: brew install act"; \
fi
# Run GitHub Actions locally
ci-local ci_args="":
@echo "Running GitHub Actions locally with act..."
@if command -v act >/dev/null 2>&1; then \
act {{ci_args}}; \
else \
echo "act not installed. Install with:"; \
echo " curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sh"; \
echo " or: brew install act"; \
fi