-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
177 lines (152 loc) · 6.23 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
default: ci
ci: lint test fmt-check imports-check integration
GOLANGCILINTVERSION?=1.49.0
GOIMPORTSVERSION?=v0.1.12
GOXVERSION?=v1.0.1
GOTESTSUMVERSION?=v1.8.2
GOREVIVEVERSION?=v1.2.3
GOLANGCILINTLSVERSION?=v0.0.7
CIARTIFACTS?=ci-artifacts
COVERAGEOUT?=coverage.out
COVERAGEHTML?=coverage.html
PACKAGENAME?=ecomm-reporter
CLINAME?=ecomm-rpt
GOFLAGS=-mod=vendor
CGO_ENABLED?=1
GO_LDFLAGS="-X github.com/lacework-demo/ecommercre-reporter/cli/cmd.Version=$(shell cat VERSION) \
-X github.com/lacework-demo/ecommercre-reporter/cli/cmd.GitSHA=$(shell git rev-parse HEAD) \
-X github.com/lacework-demo/ecommercre-reporter/cli/cmd.BuildTime=$(shell date +%Y%m%d%H%M%S)"
export GOFLAGS GO_LDFLAGS CGO_ENABLED GOX_LINUX_AMD64_LDFLAGS
.PHONY: help
help:
@echo "-------------------------------------------------------------------"
@echo "Makefile helper:"
@echo ""
@grep -Fh "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\\$$//' | sed -E 's/^([^:]*):.*##(.*)/ \1 -\2/'
@echo "-------------------------------------------------------------------"
.PHONY: prepare
prepare: install-tools go-vendor ## Initialize the go environment
.PHONY: test
test: prepare ## Run all tests
CI=true gotestsum -f testname -- -v -cover -coverprofile=$(COVERAGEOUT) $(shell go list ./... | grep -v integration)
.PHONY: coverage
coverage: test ## Output coverage profile information for each function
go tool cover -func=$(COVERAGEOUT)
.PHONY: coverage-html
coverage-html: test ## Generate HTML representation of coverage profile
go tool cover -html=$(COVERAGEOUT)
.PHONY: go-vendor
go-vendor: ## Runs go mod tidy, vendor and verify to cleanup, copy and verify dependencies
go mod tidy
go mod vendor
go mod verify
.PHONY: lint
lint: ## Runs go linter
golangci-lint run
.PHONY: fmt
fmt: ## Runs and applies go formatting changes
@gofmt -w -l $(shell go list -f {{.Dir}} ./...)
@goimports -w -l $(shell go list -f {{.Dir}} ./...)
.PHONY: fmt-check
fmt-check: ## Lists formatting issues
@test -z $(shell gofmt -l $(shell go list -f {{.Dir}} ./...))
.PHONY: imports-check
imports-check: ## Lists imports issues
@test -z $(shell goimports -l $(shell go list -f {{.Dir}} ./...))
.PHONY: build-cli-cross-platform
build-cli-cross-platform:
gox -output="bin/$(PACKAGENAME)-backend-{{.OS}}-{{.Arch}}" \
-os="linux" \
-arch="amd64 386" \
-osarch="darwin/amd64 darwin/arm64 linux/arm linux/arm64" \
-ldflags=$(GO_LDFLAGS) \
github.com/lacework-demo/ecommercre-reporter/cli/backend
gox -output="bin/$(PACKAGENAME)-frontend-{{.OS}}-{{.Arch}}" \
-os="linux" \
-arch="amd64 386" \
-osarch="darwin/amd64 darwin/arm64 linux/arm linux/arm64" \
-ldflags=$(GO_LDFLAGS) \
github.com/lacework-demo/ecommercre-reporter/cli/frontend
.PHONY: build-cli-dev
build-cli-dev:
ifeq (x86_64, $(shell uname -m))
gox -output="bin/$(PACKAGENAME)-backend-{{.OS}}-{{.Arch}}" \
-os=$(shell uname -s | tr '[:upper:]' '[:lower:]') \
-arch="amd64" \
-gcflags="all=-N -l" \
-ldflags=$(GO_LDFLAGS) \
github.com/lacework-demo/ecommercre-reporter/cli/backend
else
gox -output="bin/$(PACKAGENAME)-backend-{{.OS}}-{{.Arch}}" \
-os=$(shell uname -s | tr '[:upper:]' '[:lower:]') \
-arch="386" \
-gcflags="all=-N -l" \
-osarch="$(shell uname -s | tr '[:upper:]' '[:lower:]')/amd $(shell uname -s | tr '[:upper:]' '[:lower:]')/arm" \
-ldflags=$(GO_LDFLAGS) \
github.com/lacework-demo/ecommercre-reporter/cli/backend
endif
ifeq (x86_64, $(shell uname -m))
gox -output="bin/$(PACKAGENAME)-frontend-{{.OS}}-{{.Arch}}" \
-os=$(shell uname -s | tr '[:upper:]' '[:lower:]') \
-arch="amd64" \
-gcflags="all=-N -l" \
-ldflags=$(GO_LDFLAGS) \
github.com/lacework-demo/ecommercre-reporter/cli/frontend
else
gox -output="bin/$(PACKAGENAME)-backend-{{.OS}}-{{.Arch}}" \
-os=$(shell uname -s | tr '[:upper:]' '[:lower:]') \
-arch="386" \
-gcflags="all=-N -l" \
-osarch="$(shell uname -s | tr '[:upper:]' '[:lower:]')/amd $(shell uname -s | tr '[:upper:]' '[:lower:]')/arm" \
-ldflags=$(GO_LDFLAGS) \
github.com/lacework-demo/ecommercre-reporter/cli/frontend
endif
.PHONY: copy-bins
copy-bins:
ifeq (x86_64, $(shell uname -m))
cp bin/$(PACKAGENAME)-backend-$(shell uname -s | tr '[:upper:]' '[:lower:]')-amd64 /usr/local/bin/$(CLINAME)-be
else
cp bin/$(PACKAGENAME)-backend-$(shell uname -s | tr '[:upper:]' '[:lower:]')-386 /usr/local/bin/$(CLINAME)-be
endif
@echo "\nThe backend cli has been installed at /usr/local/bin"
ifeq (x86_64, $(shell uname -m))
cp bin/$(PACKAGENAME)-frontend-$(shell uname -s | tr '[:upper:]' '[:lower:]')-amd64 /usr/local/bin/$(CLINAME)-fe
else
cp bin/$(PACKAGENAME)-frontend-$(shell uname -s | tr '[:upper:]' '[:lower:]')-386 /usr/local/bin/$(CLINAME)-fe
endif
@echo "\nThe frontend cli has been installed at /usr/local/bin"
.PHONY: install-cli-dev
install-cli-dev: build-cli-dev copy-bins
.PHONY: install-cli
install-cli: build-cli-cross-platform copy-bins
.PHONY: build-all-dev
build-all-dev: install-cli-dev
.PHONY: integration-test
integration-test: install-tools ## Run integration tests
PATH=$(PWD)/bin:${PATH} gotestsum -f testname -- -v github.com/lacework-demo/ecommercre-reporter/test/integration
.PHONY: dev-docs
dev-docs:
cd docs && yarn && yarn start
.PHONY: install-tools
install-tools: ## Install go indirect dependencies
ifeq (, $(shell which golangci-lint))
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v$(GOLANGCILINTVERSION)
endif
ifeq (, $(shell which goimports))
GOFLAGS=-mod=readonly go install golang.org/x/tools/cmd/goimports@$(GOIMPORTSVERSION)
endif
ifeq (, $(shell which gox))
GOFLAGS=-mod=readonly go install github.com/mitchellh/gox@$(GOXVERSION)
endif
ifeq (, $(shell which gotestsum))
GOFLAGS=-mod=readonly go install gotest.tools/gotestsum@$(GOTESTSUMVERSION)
endif
ifeq (, $(shell which revive))
GOFLAGS=-mod=readonly go install github.com/mgechev/revive@$(GOREVIVEVERSION)
endif
ifeq (, $(shell which golangci-lint-langserver))
GOFLAGS=-mod=readonly go install github.com/nametake/golangci-lint-langserver@$(GOLANGCILINTLSVERSION)
endif
.PHONY: release
release: prepare
scripts/release.sh prepare