-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
73 lines (59 loc) · 2.56 KB
/
Makefile
File metadata and controls
73 lines (59 loc) · 2.56 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
BINARY_NAME := things3-cli
BIN_DIR := bin
BIN_PATH := $(BIN_DIR)/$(BINARY_NAME)
OUT_DIR := dist
CMD := ./cmd/things3-cli
GOFLAGS ?= -buildvcs=false
# Version embedding configuration
# Standard location: pkg/version.Version or similar
# Set to the full package path of the Version variable
# We extract it from release-naming.env later if possible
VERSION_VAR := $(shell grep VERSION_VAR_PATH release-naming.env 2>/dev/null | cut -d= -f2)
ifeq ($(VERSION_VAR),)
VERSION_VAR := github.com/Leechael/things3--cli/pkg/version.Version
endif
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
export GOFLAGS
.PHONY: tidy fmt test bdd-test ci build run install clean cross-build help
help:
@echo "Targets:"
@echo " make tidy - go mod tidy"
@echo " make fmt - gofmt ./cmd ./internal ./tests"
@echo " make test - run unit tests"
@echo " make bdd-test - run BDD tests"
@echo " make ci - fmt check + vet + tests + build"
@echo " make build - build local binary to ./$(BIN_PATH)"
@echo " make run - run CLI (pass ARGS='...')"
@echo " make install - install binary to GOPATH/bin"
@echo " make clean - remove build artifacts"
@echo " make cross-build - build darwin/linux amd64/arm64 binaries"
tidy:
go mod tidy
fmt:
gofmt -w ./cmd ./internal ./tests
test:
go test ./... -count=1
bdd-test:
go test -tags=bdd ./tests/bdd/... -count=1
ci:
@unformatted=$$(gofmt -l ./cmd ./internal ./tests); \
if [ -n "$$unformatted" ]; then echo "Unformatted files:"; echo "$$unformatted"; exit 1; fi
go vet ./...
go test ./... -count=1
go test -tags=bdd ./tests/bdd/... -count=1
go build -v -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" -o $(BIN_PATH) $(CMD)
build:
mkdir -p $(BIN_DIR)
go build -o $(BIN_PATH) -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" $(CMD)
run:
go run -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" $(CMD) $(ARGS)
install:
go install -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" $(CMD)
clean:
rm -rf $(OUT_DIR) $(BIN_DIR)
cross-build: clean
mkdir -p $(OUT_DIR)
GOOS=darwin GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-darwin-amd64 -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" $(CMD)
GOOS=darwin GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-darwin-arm64 -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" $(CMD)
GOOS=linux GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-linux-amd64 -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" $(CMD)
GOOS=linux GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-linux-arm64 -ldflags="-s -w -X $(VERSION_VAR)=$(VERSION)" $(CMD)