-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
161 lines (131 loc) · 5.16 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
# CONSTANT ENVS
FILES ?= $(shell find . -type f -name '*.go' -not -path "./proto/*")
PACKAGES ?= $(shell go list ./...)
# DIRECTORIES
BINARY_DIR=bin
CMD_DIR=cmd
FUNCTION_DIR=functions
ZIP_DIR=zip
# Module Root
MODULE_ROOT=github.com/enosi/billing-adjustment
# VERSIONING
# Make use of lazy evaluation ala http://cakoose.com/wiki/gnu_make_thunks
VERSION_GEN=$(shell git fetch --tags && git describe --tags --dirty --always)
VERSION?=$(eval VERSION := $(VERSION_GEN))$(VERSION)
BUILD_TIME_GEN=$(shell date +%FT%T%z)
BUILD_TIME?=$(eval BUILD_TIME := $(BUILD_TIME_GEN))$(BUILD_TIME)
BUILD_VERSION=-ldflags '-X $(MODULE_ROOT)/pkg/version.Version=$(VERSION) -X $(MODULE_ROOT)/pkg/version.BuildTime=$(BUILD_TIME)'
.PHONY: help
default: help
.PHONY: build
build:
go build ./...
.PHONY: clean
clean: ## go clean
go clean -i ./...
rm -rf $(BINARY_DIR)
mkdir -p $(BINARY_DIR)
rm -rf $(ZIP_DIR)
mkdir -p $(ZIP_DIR)
.PHONY: clean-goimports
clean-goimports: ## needed to deal with <https://github.com/facebook/ent/issues/383>
rm -f go.sum
rm -rf vendor
go clean -modcache
.PHONY: clean-all
clean-all: clean
PHONY: codeclimate-after
codeclimate-after:
./cc-test-reporter format-coverage .coverage/coverage.out -t gocov -o .coverage/codeclimate.json -p github.com/jufemaiz/go-aemo
./cc-test-reporter upload-coverage -i .coverage/codeclimate.json
PHONY: codeclimate-before
codeclimate-before:
./cc-test-reporter before-build
.PHONY: codeclimate-install
codeclimate-install:
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
PHONY: codeclimate-after
codecov-after:
./codecov -t $(CODECOV_TOKEN)
.PHONY: codecov-install
codecov-install:
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step
curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM
chmod +x codecov
.PHONY: codecov-upload
codecov-upload:
./codecov -t $(CODECOV_TOKEN)
.PHONY: coverage-after
coverage-after: codeclimate-after codecov-after
.PHONY: coverage-before
coverage-before: codeclimate-before
.PHONY: coverage-install
coverage-install: codeclimate-install codecov-install
.PHONY: dependencies
dependencies:
go mod tidy
go mod verify
.PHONY: dependencies-download
dependencies-download:
go mod download
.PHONY: fmt
fmt: ## format the go source files
go fmt ./...
goimports -local "${MODULE_ROOT}" -w $(FILES)
.PHONY: generate
generate: ## Generate boilerplate and mock code
go generate ./...
# MANUALLY run the following on CLI, in the folder where the mock should be generated, to create a mock implementation
# moq -out s3_uploader_mock.go -pkg PACKAGE_NAME $(go list -f '{{.Dir}}' github.com/aws/aws-sdk-go/service/s3/s3manager/s3manageriface) UploaderAPI
# moq -out sns_mock.go -pkg PACKAGE_NAME $(go list -f '{{.Dir}}' github.com/aws/aws-sdk-go/service/sns/snsiface) SNSAPI
# moq -out sqs_mock.go -pkg PACKAGE_NAME $(go list -f '{{.Dir}}' github.com/aws/aws-sdk-go/service/sqs/sqsiface) SQSAPI
.PHONY: help
help: ## Show this help
@echo 'usage: make [target] ...'
@echo ''
@echo 'targets:'
@egrep '^(.+)\:\ .*##\ (.+)' ${MAKEFILE_LIST} | sed 's/:.*##/#/' | column -t -c 2 -s '#'
.PHONY: lint-install
lint-install:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.43.0
golangci-lint --version
.PHONY: lint
lint: ## run go lint on the source files
@if ! [ -x "$$(command -v golangci-lint)" ]; then \
echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
exit 1; \
fi; \
golangci-lint run ./... --config ./.golangci.yml --timeout 60m --max-issues-per-linter 50 --max-same-issues 50 --exclude-use-default=false --verbose
.PHONY: lint-verbose
lint-verbose: ## run go lint on the source files
@if ! [ -x "$$(command -v golangci-lint)" ]; then \
echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
exit 1; \
fi; \
golangci-lint run ./... --config ./.golangci.yml --timeout 60m --max-issues-per-linter 5000 --max-same-issues 5000 --exclude-use-default=false --verbose
.PHONY: list
list:
go list ./...
.PHONY: test
test: ## run short tests
mkdir -p .coverage
go test -race -v ./... -timeout 60m -short -coverprofile .coverage/coverage.out -covermode=atomic
go tool cover -func .coverage/coverage.out | grep ^total:
go tool cover -html=.coverage/coverage.out -o .coverage/coverage.html
.PHONY: tools tools-update
tools: ## fetch and install all required tools
go get golang.org/x/tools/cmd/goimports
go get github.com/smartystreets/goconvey
go get github.com/matryer/moq
tools-update: ## fetch, update and install all required tools
go get -u golang.org/x/tools/cmd/goimports
go get -u github.com/smartystreets/goconvey
go get -u github.com/matryer/moq
.PHONY: vet
vet: ## run go vet on the source files
go vet ./...