-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
135 lines (110 loc) · 3.99 KB
/
justfile
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
# Binary name and paths
binary_name := "blobphish"
build_dir := "build"
main_path := "./cmd/blobphish"
# Build information
version := `git describe --tags --always --dirty`
build_time := `date -u '+%Y-%m-%d_%H:%M:%S'`
commit_hash := `git rev-parse --short HEAD`
# Debug output
debug_dir := "debug/"
cpu_prof := " -cpuprofile " + debug_dir + "cpu_" + version + build_time + " "
mem_prof := " -memprofile " + debug_dir + "mem_" + version + build_time + " "
mutex_prof := " -mutexprofile " + debug_dir + "mutex_" + version + build_time + " "
trace_prof := " -traceprofile " + debug_dir + "trace_" + version + build_time + ""
# Build flags
gc_flags := "-gcflags="
ld_flags := "-ldflags="
ld_info := "-X main.Version=" + version + " -X main.BuildTime=" + build_time + " -X main.CommitHash=" + commit_hash
gcflags_release := gc_flags + "'" + "-L -m -race -h" + "'"
ldflags_release := ld_flags + "'" + ld_info + " -h -race -s" + "'"
gcflags_debug := gc_flags + "'" + "-E -K -L -N -W -l -m -j -r -race -w -v" + cpu_prof + mem_prof + mutex_prof + trace_prof + "'"
ldflags_debug := ld_flags + "'" + ld_info + "-n -race -v -c" + "'"
# Default recipe
default: list
# Quality control
audit:
@echo "Running quality control checks..."
just clean
go mod tidy -diff
go mod verify
just test
# Build for development
build:
CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin go build -o {{build_dir}}/{{binary_name}}-darwin {{main_path}}
CGO_ENABLED=1 GOARCH=amd64 GOOS=linux go build -o {{build_dir}}/{{binary_name}}-linux {{main_path}}
CGO_ENABLED=1 GOARCH=amd64 GOOS=windows go build -o {{build_dir}}/{{binary_name}}-windows {{main_path}}
@echo "Building {{binary_name}}..."
mkdir -p {{build_dir}}
go build {{ldflags_release}} {{gcflags_release}} -o {{build_dir}}/{{binary_name}} {{main_path}}
# Build for debugging
debug:
@echo "Building debug binary..."
mkdir -p {{build_dir}}
CGO_ENABLED=1 go build {{ldflags_debug}} {{gcflags_debug}} -o {{build_dir}}/{{binary_name}}-debug {{main_path}}
# Build for release with optimizations
# TODO: Fix this
#release:
# @echo "Building release binary..."
# mkdir -p {{build_dir}}
# # Linux build
# CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
# go build -trimpath -a -ldflags {{ldflags}} \
# -o {{build_dir}}/{{binary_name}}-linux-amd64 {{main_path}}
# # MacOS build
# CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 \
# go build -trimpath -a -ldflags {{ldflags}} \
# -o {{build_dir}}/{{binary_name}}-darwin-amd64 {{main_path}}
# # Windows build
# CGO_ENABLED=0 GOOS=windows GOARCH=amd64 \
# go build -trimpath -a -ldflags {{ldflags}} \
# -o {{build_dir}}/{{binary_name}}-windows-amd64.exe {{main_path}}
# Run tests
test:
@echo "Running tests..."
go test -v -race test/
test-complete:
@echo "Running complete tests..."
go test -v -race -buildcvs -coverprofile=/tmp/coverage.out .
go tool cover -html=/tmp/coverage.out
test-quck:
@echo "Running quick tests.."
go test -v -race -short test/
# Generate test coverage report
coverage:
@echo "Generating coverage report..."
mkdir -p {{build_dir}}
go test -coverprofile={{build_dir}}/coverage.out ./...
go tool cover -html={{build_dir}}/coverage.out -o {{build_dir}}/coverage.html
# Run linter
lint:
@echo "Running linter..."
revive .
# Run go vet
vet:
@echo "Running go vet..."
go vet .
# Format code
fmt:
@echo "Formatting code..."
gofmt -s -e -l -w .
# Clean build directory
clean:
@echo "Cleaning build directory..."
rm -rf {{build_dir}}
# Build Docker image
docker:
@echo "Building Docker image..."
docker build -t {{binary_name}}:{{version}} \
--build-arg VERSION={{version}} \
--build-arg BUILD_TIME={{build_time}} \
--build-arg COMMIT_HASH={{commit_hash}} .
run-debug: debug
@echo "Running DEBUG {{binary_name}}.."
# Run the application
run: build
@echo "Running {{binary_name}}..."
./{{build_dir}}/{{binary_name}}
# List available recipes
list:
@just --list