-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (73 loc) · 2.42 KB
/
Makefile
File metadata and controls
89 lines (73 loc) · 2.42 KB
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
LOCAL_BIN := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/.bin
DEFAULT_GO_RUN_ARGS ?= ""
GOLANGCI_LINT_VERSION := latest
REVIVE_VERSION := v1.3.7
.PHONY: all
all: clean tools lint build
@echo " # Completed all steps."
.PHONY: clean
clean:
@echo " # Cleaning up the workspace..."
@rm -fr $(LOCAL_BIN)
@if [ -d "vendor" ]; then \
echo " # Removing vendor directory..."; \
rm -fr vendor; \
fi
@echo " # Clean complete."
.PHONY: tools
tools: golangci-lint-install revive-install vendor
@echo " # All tools installed."
.PHONY: golangci-lint-install
golangci-lint-install:
@echo " # Installing golangci-lint..."
@GOBIN=$(LOCAL_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
@echo " # golangci-lint installation complete."
.PHONY: revive-install
revive-install:
@echo " # Installing revive..."
@GOBIN=$(LOCAL_BIN) go install github.com/mgechev/revive@$(REVIVE_VERSION)
@echo " # Revive installation complete."
.PHONY: lint
lint: tools run-lint
@echo " # Linting complete."
.PHONY: run-lint
run-lint: lint-golangci-lint lint-revive
@echo " # Running all linters..."
.PHONY: lint-golangci-lint
lint-golangci-lint:
@echo " # Running golangci-lint..."
@$(LOCAL_BIN)/golangci-lint -v run ./... || (echo "golangci-lint returned an error, exiting!"; sh -c 'exit 1';)
.PHONY: lint-revive
lint-revive:
@echo " # Running revive..."
@$(LOCAL_BIN)/revive -formatter=stylish -config=build/ci/.revive.toml -exclude ./vendor/... ./... || (echo "Revive returned an error, exiting!"; sh -c 'exit 1';)
.PHONY: upgrade-deps
upgrade-deps: vendor
@echo " # Upgrading dependencies..."
@for item in `grep -v 'indirect' go.mod | grep '/' | cut -d ' ' -f 1`; do \
echo "Trying to upgrade direct dependency $$item" ; \
go get -u $$item ; \
done
@go mod tidy
@go mod vendor
@echo " # Dependencies upgraded."
.PHONY: tidy
tidy:
@echo " # Tidying up the go.mod and go.sum files..."
@go mod tidy
@echo " # Go module tidy complete."
.PHONY: vendor
vendor: tidy
@echo " # Vendoring dependencies..."
@go mod vendor
@echo " # Vendoring complete."
.PHONY: build
build: vendor
@echo " # Building binary..."
@go build -o .bin/dbac main.go || (echo "An error occurred while building the binary, exiting!"; sh -c 'exit 1';)
@echo " # Binary built successfully."
.PHONY: run
run: vendor
@echo " # Running the application..."
@go run main.go $(DEFAULT_GO_RUN_ARGS)
@echo " # Application run complete."