-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (75 loc) · 3.14 KB
/
Copy pathMakefile
File metadata and controls
93 lines (75 loc) · 3.14 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
BINARY := koc
PKG := ./cmd/koc
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)
# Hard air-gap requirement: builds must reproduce offline from vendor/.
export CGO_ENABLED := 0
export GOFLAGS := -mod=vendor
# The six targets .goreleaser.yaml ships. Kept here so `make crossbuild` and the
# CI cross-compile matrix stay in sync with the release matrix.
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64
.PHONY: all build static test race cover crossbuild vet lint fmt tidy vendor completions size clean
all: build
## build: build a static binary for the host platform
build: static
## static: fully static, stripped, trimmed binary
static:
CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o $(BINARY) $(PKG)
## test: run unit tests
test:
go test ./...
## race: run unit tests under the race detector (needs cgo; shipped binaries
## stay CGO_ENABLED=0). Still offline — vendor/ only, no module proxy.
race:
CGO_ENABLED=1 GOPROXY=off go test -race ./...
## cover: write coverage.out for SonarQube (see AGENTS.md "SonarQube").
## -coverpkg=./... is load-bearing: without it each test binary only instruments
## its own package, so the whole command tree that internal/cli's root tests
## build is executed but never attributed. It is worth ~11 points.
cover:
GOPROXY=off go test -coverpkg=./... -coverprofile=coverage.out ./...
@go tool cover -func=coverage.out | tail -1
## crossbuild: compile every release target (build-only, offline) so a build-tag
## or syscall mistake is caught here instead of at release time.
crossbuild:
@set -e; for p in $(PLATFORMS); do \
os=$${p%/*}; arch=$${p#*/}; \
echo "==> $$os/$$arch"; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 GOPROXY=off go build ./...; \
done
## vet: run go vet
vet:
go vet ./...
## lint: run golangci-lint
lint:
golangci-lint run ./...
## fmt: format sources
# Needs gofmt from Go 1.27+. Go 1.27 changed the indentation of a multi-value
# return whose operands are composite literals, and the pinned golangci-lint
# bundles that gofmt, so an older one silently reverts the tree and the lint job
# then fails on files `make fmt` just "fixed".
fmt:
gofmt -w $(shell find . -name '*.go' -not -path './vendor/*')
## tidy: tidy and re-vendor modules
tidy:
GOFLAGS= go mod tidy
GOFLAGS= go mod vendor
## vendor: re-vendor modules
vendor:
GOFLAGS= go mod vendor
## completions: generate the shell completions bundled into release archives and
## the .rpm/.deb. Deliberately NOT a goreleaser `before` hook: that step also
## holds the cross-repo Homebrew PAT, and repository code (including vendor/)
## must not execute with that token in scope. Run this before goreleaser.
completions:
mkdir -p completions
go run $(PKG) completion bash > completions/koc.bash
go run $(PKG) completion zsh > completions/koc.zsh
go run $(PKG) completion fish > completions/koc.fish
## size: print the built binary size in bytes (watch for size regressions)
size: static
@echo "$(BINARY) size: $$(stat -c%s $(BINARY)) bytes"
## clean: remove build artifacts
clean:
rm -f $(BINARY)
rm -rf dist completions