-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
233 lines (201 loc) · 7.77 KB
/
Copy pathjustfile
File metadata and controls
233 lines (201 loc) · 7.77 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
# 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 PowerShell on Windows, sh on Unix
set windows-shell := ["powershell", "-NoProfile", "-Command"]
set shell := ["sh", "-c"]
# Detect Go binary
GO := "go"
# Variables
BINARY_NAME := if os() == "windows" { "kairo.exe" } else { "kairo" }
DIST_DIR := "dist"
VERSION := `git describe --tags --always --dirty`
COMMIT := `git rev-parse --short HEAD`
DATE := `date -u +%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
# Race detector flag: disabled on Windows (requires cgo/C compiler)
RACE_FLAG := if os() == "windows" { "" } else { "-race" }
# Default recipe: show list of recipes
[default]
_:
@just --list
# Build the binary
build:
@echo "Building {{BINARY_NAME}} {{VERSION}}..."
{{GO}} build -ldflags "{{LDFLAGS}}" -o {{DIST_DIR}}/{{BINARY_NAME}} .
# Run all tests (with race detector on platforms that support it)
test:
@echo "Running tests..."
{{GO}} test -v {{RACE_FLAG}} ./...
# 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..."
{{GO}} test -coverprofile={{DIST_DIR}}/coverage.out {{RACE_FLAG}} ./...
{{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..."
{{GO}} vet ./...
golangci-lint run ./...
# Format code
format:
@echo "Formatting code..."
gofmt -w .
# Run pre-commit hooks
pre-commit:
@echo "Running pre-commit hooks..."
pre-commit run --all-files
# Install pre-commit CLI tool using uv (recommended) or pip (fallback)
install-pre-commit:
@if command -v pre-commit >/dev/null 2>&1; then echo "pre-commit already installed" && pre-commit install; elif command -v uv >/dev/null 2>&1; then uv tool install pre-commit && export PATH="$HOME/.local/bin:$PATH" && pre-commit install; elif command -v pip >/dev/null 2>&1; then pip install --user pre-commit && export PATH="$HOME/.local/bin:$PATH" && pre-commit install; else echo "ERROR: neither uv nor pip found. Install uv or pip to continue." >&2 && exit 1; fi
# Pre-release checks: format, lint, pre-commit, test, goreleaser dry-run
pre-release:
@echo "Running pre-release checks..."
@echo ""
just format
@echo ""
just lint
@echo ""
just pre-commit
@echo ""
just test
@echo ""
@echo "Running goreleaser dry-run..."
goreleaser release --clean --snapshot
@echo ""
@echo "Pre-release checks passed!"
# Clean build artifacts
[unix]
clean:
@echo "Cleaning..."
rm -rf {{DIST_DIR}}
[windows]
clean:
@echo "Cleaning..."
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue {{DIST_DIR}}
# Install binary to GOBIN or GOPATH/bin
install: build
@echo "Installing {{BINARY_NAME}}..."
{{GO}} install {{DIST_DIR}}/{{BINARY_NAME}}
# Uninstall binary
[unix]
uninstall:
@echo "Removing {{BINARY_NAME}}..."
rm -f "$(go env GOPATH)/bin/{{BINARY_NAME}}"
@echo "Uninstalled {{BINARY_NAME}}"
[windows]
uninstall:
@echo "Removing {{BINARY_NAME}}..."
Remove-Item -Force -ErrorAction SilentlyContinue "$(go env GOPATH)\bin\{{BINARY_NAME}}"
@echo "Uninstalled {{BINARY_NAME}}"
# Build and run with arguments
run args="": build
@echo "Running {{BINARY_NAME}}..."
{{DIST_DIR}}/{{BINARY_NAME}} {{args}}
# Download and tidy dependencies + install dev tools
deps:
@echo "Installing dependencies..."
{{GO}} mod download
{{GO}} mod tidy
@echo ""
@echo "Installing development tools..."
{{GO}} install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
{{GO}} install golang.org/x/vuln/cmd/govulncheck@latest
{{GO}} install honnef.co/go/tools/cmd/staticcheck@latest
{{GO}} install github.com/goreleaser/goreleaser/v2@latest
@echo ""
@echo "Installing pre-commit..."
{{just_executable()}} install-pre-commit
@echo ""
@echo "Dependencies installed!"
# Verify dependencies
verify-deps:
@echo "Verifying dependencies..."
{{GO}} mod verify
# Run vulnerability scan
vuln-scan:
@echo "Running vulnerability scan..."
govulncheck ./...
# Run comprehensive security checks (vuln scan + lint)
security: vuln-scan lint
@echo "Security checks passed!"
# Create release builds with goreleaser
release:
@echo "Running goreleaser..."
goreleaser release --clean
# Create local snapshot build
release-local:
@echo "Running goreleaser (snapshot build)..."
goreleaser release --clean --snapshot
# Build without publishing (dry-run)
release-dry-run:
@echo "Running goreleaser (dry-run, no publish)..."
goreleaser release --clean --snapshot --skip=publish
# Generate provider table for README
generate:
@echo "Generating provider table..."
{{GO}} run ./cmd/gen/
@echo "Provider table generated! Update README.md with the output."
# Display help message
help:
@echo "Kairo Justfile"
@echo ""
@echo "Output directory: {{DIST_DIR}}/"
@echo ""
@echo "Recipes:"
@echo " build - Build the binary to {{DIST_DIR}}/"
@echo " test - Run all tests"
@echo " fuzz - Run fuzzing tests (5s per package)"
@echo " test-coverage - Run tests with coverage report"
@echo " lint - Run linters (go vet, golangci-lint)"
@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 GOBIN"
@echo " uninstall - Remove from GOBIN"
@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..."
act -l
# Run GitHub Actions locally
ci-local ci_args="":
@echo "Running GitHub Actions locally with act..."
act {{ci_args}}