-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
130 lines (101 loc) · 3.4 KB
/
Makefile
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
PROJECT_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
GOTESTSUM_VERSION := v1.11.0
GOFUMPT_VERSION := v0.6.0
GOLANGCI_LINT_VERSION := v1.57.2
RESPONSES_FILE ?= examples/example.json
BINARY_NAME := pretender
BINARY_VERSION := v1.8.0
OS_LIST := darwin linux
ARCH_LIST := arm64 amd64
BUILD_TARGETS := $(foreach os,$(OS_LIST),$(foreach arch,$(ARCH_LIST),bin/$(BINARY_NAME)-$(os)-$(arch)))
RELEASE_TARGETS := $(foreach os,$(OS_LIST),$(foreach arch,$(ARCH_LIST),bin/$(BINARY_NAME)-$(os)-$(arch).tar.gz))
# - install binary dependencies
bin/golangci-lint:
@mkdir -p $(@D)
GOBIN=$(PROJECT_DIR)/$(@D) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
bin/gofumpt:
@mkdir -p $(@D)
GOBIN=$(PROJECT_DIR)/$(@D) go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
bin/gotestsum:
@mkdir -p $(@D)
GOBIN=$(PROJECT_DIR)/$(@D) go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
bin/git-chglog:
@mkdir -p $(@D)
GOBIN=$(PROJECT_DIR)/$(@D) go install github.com/git-chglog/git-chglog/cmd/git-chglog@latest
# - run, test, lint, format etc.
.PHONY: run
run:
go run cmd/$(BINARY_NAME)/main.go --responses $(RESPONSES_FILE)
.PHONY: lint
lint: bin/golangci-lint
@bin/golangci-lint run
.PHONY: format
format: bin/gofumpt
@bin/gofumpt -w .
.PHONY: test
test: bin/gotestsum lint
@echo ""
@cd $(PROJECT_DIR) && $(PROJECT_DIR)/bin/gotestsum --format testdox -- -coverprofile=cover.out -coverpkg=./... $(shell go list ./... | grep -v /tools/ | grep -v /cmd/)
cover.out:
@if [ ! -f cover.out ]; then $(MAKE) test; fi
cover.txt: cover.out
@cd $(PROJECT_DIR) && go tool cover -func=cover.out -o cover.txt
cover.html: cover.out
@cd $(PROJECT_DIR) && go tool cover -html=cover.out -o cover.html
.PHONY: open-cover
open-cover: cover.out
@cd $(PROJECT_DIR) && go tool cover -html=cover.out
# - build and release
.PHONY: build
build: $(BUILD_TARGETS)
.PHONY: $(BUILD_TARGETS)
$(BUILD_TARGETS):
@$(eval os = $(word 2, $(subst -, ,$@)))
@$(eval arch = $(word 3, $(subst -, ,$@)))
GOOS=$(os) GOARCH=$(arch) CGO_ENABLED=0 go build -ldflags "-s -w" -o $@ cmd/$(BINARY_NAME)/main.go
.PHONY: release
release: VERSION = $(shell go run cmd/$(BINARY_NAME)/main.go --responses $(RESPONSES_FILE) --version)
release: $(RELEASE_TARGETS)
.PHONY: $(RELEASE_TARGETS)
$(RELEASE_TARGETS): clean build
@cp $(shell echo $@ | sed s/.tar.gz//) bin/$(BINARY_NAME)
cd bin && tar -czf $(shell basename $@) $(BINARY_NAME)
@rm bin/$(BINARY_NAME)
.PHONY: docker-build
docker-build:
docker build $(PROJECT_DIR) -t $(BINARY_NAME):latest
.PHONY: docker-run
docker-run: docker-build
docker run --rm -v $(PROJECT_DIR)/$(RESPONSES_FILE):/$(RESPONSES_FILE) -p 8080:8080 $(BINARY_NAME):latest --responses /$(RESPONSES_FILE)
# - tools
.PHONY: changelog
changelog: bin/git-chglog
@git tag -l | xargs git tag -d > /dev/null 2>&1
@git fetch --tags > /dev/null 2>&1
@bin/git-chglog --no-emoji -o CHANGELOG.md --next-tag $(tag)
version-bump:
@echo ""
@echo "bumping version to $(version)"
@find . \
-path ./.git -prune -o \
-type f \
-exec ex -sc '%s/$(BINARY_VERSION)/$(version)/g' -c 'x' {} \;
@git status
.PHONY: version-check
version-check:
@echo ""
@go run tools/versioncheck/main.go $(tag)
.PHONY: cover-check
cover-check: cover.txt
@echo ""
@cat cover.txt
@go run tools/covercheck/main.go
.PHONY: commit-check
commit-check:
@echo ""
@go run tools/commitcheck/main.go '$(message)'
# - clean
.PHONY: clean
clean:
rm -rf bin/*
rm -rf cover.*