-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (52 loc) · 1.61 KB
/
Copy pathMakefile
File metadata and controls
67 lines (52 loc) · 1.61 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
# thinkthinking Makefile
#
# 常用目标:build / run / test / lint / fmt / snapshot / release
BINARY := thinkthinking
CMD_PATH := ./cmd/thinkthinking
BIN_DIR := bin
VERSION_PKG := github.com/thinkthinking/cli/internal/version
# 构建期注入的版本信息(本地构建用 git 描述)。
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.1.0-dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X $(VERSION_PKG).Version=$(VERSION) \
-X $(VERSION_PKG).Commit=$(COMMIT) \
-X $(VERSION_PKG).Date=$(DATE)
.PHONY: build run test lint fmt vet snapshot release clean tidy
## build: 编译二进制到 bin/
build:
@mkdir -p $(BIN_DIR)
go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BINARY) $(CMD_PATH)
@echo "built $(BIN_DIR)/$(BINARY) ($(VERSION))"
## run: 直接运行(透传参数,例如 make run ARGS="version --pretty")
run:
go run $(CMD_PATH) $(ARGS)
## test: 运行全部测试
test:
go test ./...
## test-v: 详细测试输出
test-v:
go test -v ./...
## fmt: 格式化代码
fmt:
gofmt -w .
## vet: 静态检查
vet:
go vet ./...
## lint: fmt 检查 + vet(CI 用)
lint:
@test -z "$$(gofmt -l .)" || (echo "gofmt needed:"; gofmt -l .; exit 1)
go vet ./...
## tidy: 整理依赖
tidy:
go mod tidy
## snapshot: 本地试构建跨平台产物(不发布)
snapshot:
goreleaser release --snapshot --clean
## release: 正式发布(需打 tag 并设置 GITHUB_TOKEN)
release:
goreleaser release --clean
## clean: 清理产物
clean:
rm -rf $(BIN_DIR) dist