forked from josephburnett/jd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
207 lines (179 loc) · 6.97 KB
/
Copy pathMakefile
File metadata and controls
207 lines (179 loc) · 6.97 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
# Enforce strict toolchain usage - matches toolchain directive in go.mod
export GOTOOLCHAIN=go1.24.13
# Toolchain validation target
.PHONY : validate-toolchain
validate-toolchain :
@echo "Validating Go toolchain versions..."
@ROOT_TOOLCHAIN=$$(grep '^toolchain ' go.mod | awk '{print $$2}'); \
V2_TOOLCHAIN=$$(grep '^toolchain ' v2/go.mod | awk '{print $$2}'); \
if [ "$$ROOT_TOOLCHAIN" != "$$V2_TOOLCHAIN" ]; then \
echo "Error: Toolchain mismatch between go.mod files:"; \
echo " Root go.mod: $$ROOT_TOOLCHAIN"; \
echo " v2/go.mod: $$V2_TOOLCHAIN"; \
exit 1; \
fi; \
if [ "$$ROOT_TOOLCHAIN" != "$(GOTOOLCHAIN)" ]; then \
echo "Error: Makefile GOTOOLCHAIN does not match go.mod toolchain:"; \
echo " Makefile GOTOOLCHAIN: $(GOTOOLCHAIN)"; \
echo " go.mod toolchain: $$ROOT_TOOLCHAIN"; \
echo " Please update GOTOOLCHAIN in Makefile to match go.mod"; \
exit 1; \
fi; \
GOMOD_VERSION=$$(grep '^go ' go.mod | awk '{print $$2}' | cut -d. -f1,2); \
DOCKER_VERSION=$$(grep '^FROM golang:' Dockerfile | head -1 | sed 's/FROM golang:\([0-9.]*\).*/\1/'); \
if [ "$$GOMOD_VERSION" != "$$DOCKER_VERSION" ]; then \
echo "Error: Dockerfile Go version does not match go.mod:"; \
echo " Dockerfile: golang:$$DOCKER_VERSION"; \
echo " go.mod go directive: $$GOMOD_VERSION"; \
echo " Please update FROM golang: in Dockerfile to match go.mod"; \
exit 1; \
fi; \
echo "✓ Toolchain validation passed: $$ROOT_TOOLCHAIN"
.PHONY : build
build : test pack-web validate-toolchain
mkdir -p release
cd v2/jd ; CGO_ENABLED=0 go build -tags include_web -o ../../release/jd main.go
.PHONY : test
test : validate-toolchain
go test .
go test ./lib
cd v2 ; go test -run '^Test' .
cd v2 ; go test ./jd
.PHONY : fuzz
fuzz : validate-toolchain
cd v2 ; go test . -fuzz=FuzzJd -fuzztime=5m
.PHONY : fuzz-indef
fuzz-indef: validate-toolchain
cd v2 ; go test . -fuzz=FuzzJd
.PHONY : cover
cover : validate-toolchain
cd v2 ; go test -coverprofile=coverage.out . ./jd
cd v2 ; go run internal/coverfilter/main.go coverage.out > coverage_filtered.out
cd v2 ; go tool cover -func=coverage_filtered.out | tail -1
@echo "For HTML report: cd v2 && go tool cover -html=coverage.out"
@echo "Checking non-trivial code for 100% coverage..."
@cd v2 ; grep -v '^\s*#' cover_exclude.txt | grep -v '^\s*$$' > coverage_exclude_patterns.tmp ; \
lines=$$(go tool cover -func=coverage_filtered.out \
| grep -v '^total:' \
| grep -v '100.0%' \
| grep -vf coverage_exclude_patterns.tmp) ; \
rm -f coverage_exclude_patterns.tmp ; \
if [ -n "$$lines" ]; then \
echo "$$lines" ; \
echo "FAIL: non-trivial functions below 100% coverage" ; \
exit 1 ; \
else \
echo "OK: all non-trivial functions at 100% coverage" ; \
fi
.PHONY : spec-test
spec-test : validate-toolchain
cd v2 ; go build -o ../spec/test/jd ./jd
cd spec/test ; go build -o test-runner .
cd spec/test ; ./test-runner -verbose -binary ./jd
rm -f spec/test/jd spec/test/test-runner
.PHONY : go-fmt
go-fmt :
go fmt ./...
cd v2 ; go fmt ./...
.PHONY : check-fmt
check-fmt : validate-toolchain
@unformatted=$$(gofmt -l . v2); \
if [ -n "$$unformatted" ]; then \
echo "Error: unformatted Go files:"; \
echo "$$unformatted"; \
echo "Run 'make go-fmt' to fix."; \
exit 1; \
fi; \
echo "✓ All Go files formatted"
.PHONY : vet
vet : validate-toolchain
go vet . ./lib
cd v2 ; go vet $$(go list ./... 2>/dev/null | grep -v internal/web/ui)
.PHONY : pack-web
pack-web : build-web validate-toolchain
cd v2 ; go run internal/web/pack/main.go
.PHONY : build-web
build-web : validate-toolchain
cp "$$(go env GOROOT)/lib/wasm/wasm_exec.js" v2/internal/web/assets/wasm_exec.js
cd v2 ; GOOS=js GOARCH=wasm go build -o internal/web/assets/jd.wasm ./internal/web/ui
.PHONY : serve
serve : pack-web validate-toolchain
cd v2 ; go run -tags include_web jd/main.go -port 8080
.PHONY : release-build
release-build : check-env check-version check-dirty build-all build-docker
@echo
@echo "If everything looks good, run 'make release-push'."
@echo
.PHONY : build-all
build-all : test pack-web validate-toolchain
mkdir -p release
cd v2/jd ; GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags include_web -o ../../release/jd-amd64-linux main.go
cd v2/jd ; GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -tags include_web -o ../../release/jd-amd64-darwin main.go
cd v2/jd ; GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -tags include_web -o ../../release/jd-amd64-windows.exe main.go
cd v2/jd ; GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -tags include_web -o ../../release/jd-arm64-linux main.go
cd v2/jd ; GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -tags include_web -o ../../release/jd-arm64-darwin main.go
cd v2/jd ; GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -tags include_web -o ../../release/jd-arm64-windows.exe main.go
cd v2/jd ; GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 go build -tags include_web -o ../../release/jd-riscv64-linux main.go
.PHONY : build-docker
build-docker : check-env test
docker build -t josephburnett/jd:v$(JD_VERSION) .
.PHONY : release-push
release-push : check-env push-github push-docker push-latest deploy release-notes
@echo
@echo "Upload release/jd-* to Github as release $(JD_VERSION) with release notes above."
@echo
.PHONY : push-docker
push-docker : check-env
docker push josephburnett/jd:v$(JD_VERSION)
.PHONY : push-latest
push-latest : check-env
docker tag josephburnett/jd:v$(JD_VERSION) josephburnett/jd:latest
docker push josephburnett/jd:latest
.PHONY : push-github
push-github : check-env
git diff --exit-code
git tag v$(JD_VERSION) --force
git push origin v$(JD_VERSION)
.PHONY : deploy
deploy : test build-web
gsutil -m cp -r v2/internal/web/assets/* gs://play.jd-tool.io
.PHONY : release-notes
release-notes : check-env
@echo
@git log --oneline --no-decorate v$(JD_PREVIOUS_VERSION)..v$(JD_VERSION)
.PHONY : check-dirty
check-dirty : tidy
git diff --quiet --exit-code
.PHONY : tidy
tidy : validate-toolchain
cd v2 ; go mod tidy
go mod tidy
.PHONY : check-version
check-version : check-env
@if ! grep -q $(JD_VERSION) v2/jd/main.go; then \
echo "Set 'const version = $(JD_VERSION)' in main.go." ; \
false ; \
fi
@if ! grep -q v$(JD_VERSION) action.yml; then \
echo "Set 'docker://josephburnett/jd:v$(JD_VERSION)' in action.yml." ; \
false ; \
fi
.PHONY : check-env
check-env :
ifndef JD_VERSION
$(error Set JD_VERSION)
endif
ifndef JD_PREVIOUS_VERSION
$(error Set JD_PREVIOUS_VERSION for release notes)
endif
.PHONY : benchmark
benchmark : validate-toolchain
@echo "Running performance baseline benchmarks..."
@mkdir -p benchmarks
@timestamp=$$(date +%Y%m%d_%H%M%S); \
cd v2 && go test -run=^$$ -bench=^Benchmark -benchmem -count=1 -timeout=3m -benchtime=200ms | tee ../benchmarks/baseline_$$timestamp.txt; \
echo "Results saved to benchmarks/baseline_$$timestamp.txt"
.PHONY : find-issues
find-issues :
-staticcheck ./...
-goreportcard-cli -v ./...