This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile.gen.go.mk
114 lines (93 loc) · 3.4 KB
/
Makefile.gen.go.mk
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
# DO NOT EDIT. Generated with:
#
#
APPLICATION := $(shell go list -m | cut -d '/' -f 3)
BUILDTIMESTAMP := $(shell date -u '+%FT%TZ')
GITSHA1 := $(shell git rev-parse --verify HEAD)
MODULE := $(shell go list -m)
OS := $(shell go env GOOS)
SOURCES := $(shell find . -name '*.go')
VERSION := $(shell architect project version)
ifeq ($(OS), linux)
EXTLDFLAGS := -static
endif
LDFLAGS ?= -w -linkmode 'auto' -extldflags '$(EXTLDFLAGS)' \
-X '$(shell go list -m)/pkg/project.buildTimestamp=${BUILDTIMESTAMP}' \
-X '$(shell go list -m)/pkg/project.gitSHA=${GITSHA1}'
.DEFAULT_GOAL := build
##@ Go
.PHONY: build build-darwin build-darwin-64 build-linux build-linux-arm64 build-windows-amd64
build: $(APPLICATION) ## Builds a local binary.
@echo "====> $@"
build-darwin: $(APPLICATION)-darwin ## Builds a local binary for darwin/amd64.
@echo "====> $@"
build-darwin-arm64: $(APPLICATION)-darwin-arm64 ## Builds a local binary for darwin/arm64.
@echo "====> $@"
build-linux: $(APPLICATION)-linux ## Builds a local binary for linux/amd64.
@echo "====> $@"
build-linux-arm64: $(APPLICATION)-linux-arm64 ## Builds a local binary for linux/arm64.
@echo "====> $@"
build-windows-amd64: $(APPLICATION)-windows-amd64.exe ## Builds a local binary for windows/amd64.
@echo "====> $@"
$(APPLICATION): $(APPLICATION)-v$(VERSION)-$(OS)-amd64
@echo "====> $@"
cp -a $< $@
$(APPLICATION)-darwin: $(APPLICATION)-v$(VERSION)-darwin-amd64
@echo "====> $@"
cp -a $< $@
$(APPLICATION)-darwin-arm64: $(APPLICATION)-v$(VERSION)-darwin-arm64
@echo "====> $@"
cp -a $< $@
$(APPLICATION)-linux: $(APPLICATION)-v$(VERSION)-linux-amd64
@echo "====> $@"
cp -a $< $@
$(APPLICATION)-linux-arm64: $(APPLICATION)-v$(VERSION)-linux-arm64
@echo "====> $@"
cp -a $< $@
$(APPLICATION)-windows-amd64.exe: $(APPLICATION)-v$(VERSION)-windows-amd64.exe
@echo "====> $@"
cp -a $< $@
$(APPLICATION)-v$(VERSION)-%-amd64: $(SOURCES)
@echo "====> $@"
CGO_ENABLED=0 GOOS=$* GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $@ .
$(APPLICATION)-v$(VERSION)-%-arm64: $(SOURCES)
@echo "====> $@"
CGO_ENABLED=0 GOOS=$* GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $@ .
$(APPLICATION)-v$(VERSION)-windows-amd64.exe: $(SOURCES)
@echo "====> $@"
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $@ .
.PHONY: install
install: ## Install the application.
@echo "====> $@"
go install -ldflags "$(LDFLAGS)" .
.PHONY: run
run: ## Runs go run main.go.
@echo "====> $@"
go run -ldflags "$(LDFLAGS)" -race .
.PHONY: clean
clean: ## Cleans the binary.
@echo "====> $@"
rm -f $(APPLICATION)*
go clean
.PHONY: imports
imports: ## Runs goimports.
@echo "====> $@"
goimports -local $(MODULE) -w .
.PHONY: lint
lint: ## Runs golangci-lint.
@echo "====> $@"
golangci-lint run -E gosec -E goconst --timeout=15m ./...
.PHONY: nancy
nancy: ## Runs nancy (requires v1.0.37 or newer).
@echo "====> $@"
CGO_ENABLED=0 go list -json -deps ./... | nancy sleuth --skip-update-check --quiet --exclude-vulnerability-file ./.nancy-ignore --additional-exclude-vulnerability-files ./.nancy-ignore.generated
.PHONY: test
test: ## Runs go test with default values.
@echo "====> $@"
go test -ldflags "$(LDFLAGS)" -race ./...
.PHONY: build-docker
build-docker: build-linux ## Builds docker image to registry.
@echo "====> $@"
cp -a $(APPLICATION)-linux $(APPLICATION)
docker build -t ${APPLICATION}:${VERSION} .