-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
94 lines (73 loc) · 2.75 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
PROJECT_NAME := $(shell basename $(CURDIR))
GIT_TAG := $(shell git describe --dirty --tags --always)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -extldflags "-static" -s -w
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
.PHONY: all
all: vendor build
.PHONY: clean
clean:
git clean -Xfd .
#######################################
# builds
#######################################
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
go mod verify
.PHONY: build-all
build-all:
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME)' .
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).darwin' .
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).exe' .
.PHONY: build
build:
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
.PHONY: image
image: image
docker build -t $(PROJECT_NAME):$(GIT_TAG) .
.PHONY: build-push-development
build-push-development:
docker buildx create --use
docker buildx build -t webdevops/$(PROJECT_NAME):development --platform linux/amd64,linux/arm,linux/arm64 --push .
#######################################
# quality checks
#######################################
.PHONY: check
check: vendor lint test
.PHONY: test
test:
time go test ./...
.PHONY: lint
lint: $(GOLANGCI_LINT_BIN)
time $(GOLANGCI_LINT_BIN) run --verbose --print-resources-usage
$(GOLANGCI_LINT_BIN):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(FIRST_GOPATH)/bin
#######################################
# release assets
#######################################
RELEASE_ASSETS = \
$(foreach GOARCH,amd64 arm64,\
$(foreach GOOS,linux darwin windows,\
release-assets/$(GOOS).$(GOARCH))) \
word-dot = $(word $2,$(subst ., ,$1))
.PHONY: release-assets
release-assets: clean-release-assets vendor $(RELEASE_ASSETS)
.PHONY: clean-release-assets
clean-release-assets:
rm -rf ./release-assets
mkdir -p ./release-assets
release-assets/windows.%: $(SOURCE)
echo 'build release-assets for windows/$(call word-dot,$*,2)'
GOOS=windows \
GOARCH=$(call word-dot,$*,1) \
CGO_ENABLED=0 \
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).windows.$(call word-dot,$*,1).exe' .
release-assets/%: $(SOURCE)
echo 'build release-assets for $(call word-dot,$*,1)/$(call word-dot,$*,2)'
GOOS=$(call word-dot,$*,1) \
GOARCH=$(call word-dot,$*,2) \
CGO_ENABLED=0 \
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).$(call word-dot,$*,1).$(call word-dot,$*,2)' .