-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
72 lines (55 loc) · 1.87 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
BIN_SOURCES = $(shell find cmd/$(subst bin/,,$@) -maxdepth 1 -type f -name "*.go")
ALL_SOURCES := $(shell find . -type f -name '*.go')
MODULE_SOURCES := $(shell find . -type f -name '*.go' ! -path "./cmd/*")
CMDS := $(shell ls cmd/)
BINS := $(CMDS:%=bin/%)
CMD_TARGETS = $(@:%=bin/%)
GIT_VERSION = $(shell git describe --tags)
DOCKER_REPO := "lanrat/czds"
DOCKER_IMAGES = $(shell docker image ls --format "{{.Repository}}:{{.Tag}}" $(DOCKER_REPO))
# creates static binaries
CC = CGO_ENABLED=0 go build -trimpath -ldflags "-w -s -X main.version=$(GIT_VERSION)" -installsuffix cgo
.PHONY: all fmt docker clean install deps update-deps $(CMDS) check release
all: $(BINS)
.SECONDEXPANSION:
$(BINS): $$(BIN_SOURCES) $(MODULE_SOURCES)
$(CC) -o $@ $(BIN_SOURCES)
$(CMDS): $$(CMD_TARGETS)
docker: Dockerfile Makefile $(SOURCES)
docker build -t $(DOCKER_REPO) -t $(DOCKER_REPO):$(GIT_VERSION) .
update-deps: deps
GOPROXY=direct go get -u ./...
go mod tidy
deps: go.mod
GOPROXY=direct go mod download
go mod tidy
fmt:
gofmt -s -w -l .
lint: | lint-staticcheck lint-golangci
lint-staticcheck:
staticcheck -f stylish -checks all ./...
lint-golangci:
golangci-lint run
install: $(SOURCES)
go install $(CMDS)
clean:
rm -rf $(BINS)
ifneq ($(shell which docker),)
ifneq ($(DOCKER_IMAGES),)
docker image rm $(DOCKER_IMAGES)
endif
endif
release: $(BINS)
$(eval v := $(shell git describe --tags --abbrev=0 | sed -Ee 's/^v|-.*//'))
@echo current: $v
ifeq ($(bump), major)
$(eval v := $(shell echo $(v) | awk 'BEGIN{FS=OFS="."} {$$1+=1;$$2=$$3=0} 1'))
else ifeq ($(bump), minor)
$(eval v := $(shell echo $(v) | awk 'BEGIN{FS=OFS="."} {$$2+=1;$$3=0} 1'))
else
$(eval v := $(shell echo $(v) | awk 'BEGIN{FS=OFS="."}{$$3+=1;} 1'))
endif
@echo next: $(v)
@(git diff --exit-code --shortstat && git diff --exit-code --cached --shortstat)
git tag v$(v) -m '"release v$(v)"'
git push && git push --tags