forked from auth0/auth0-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
158 lines (127 loc) · 6.55 KB
/
Copy pathMakefile
File metadata and controls
158 lines (127 loc) · 6.55 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
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
#-----------------------------------------------------------------------------------------------------------------------
# Variables (https://www.gnu.org/software/make/manual/html_node/Using-Variables.html#Using-Variables)
#-----------------------------------------------------------------------------------------------------------------------
.DEFAULT_GOAL := help
NAME := auth0-cli
GO_PKG := github.com/auth0/$(NAME)
GO_BIN ?= $(shell go env GOPATH)/bin
GO_PACKAGES := $(shell go list ./... | grep -v vendor)
## Configuration for build-info
BUILD_DIR ?= $(CURDIR)/out
BUILD_INFO_PKG := $(GO_PKG)/internal/buildinfo
BUILD_USER := $(shell whoami)
BUILD_TIME := $(shell date -u '+%Y-%m-%d %H:%M:%S')
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_UNTRACKED_CHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GIT_UNTRACKED_CHANGES),)
GITCOMMIT := $(GIT_COMMIT)-dirty
endif
GIT_BRANCH ?= $(shell git rev-parse --verify --abbrev-ref HEAD)
GO_LINKER_FLAGS = -X '$(BUILD_INFO_PKG).Version=dev' \
-X '$(BUILD_INFO_PKG).Revision=$(GIT_COMMIT)' \
-X '$(BUILD_INFO_PKG).Branch=$(GIT_BRANCH)' \
-X '$(BUILD_INFO_PKG).BuildUser=$(BUILD_USER)' \
-X '$(BUILD_INFO_PKG).BuildDate=$(BUILD_TIME)'
# Colors for the printf
RESET = $(shell tput sgr0)
COLOR_WHITE = $(shell tput setaf 7)
COLOR_BLUE = $(shell tput setaf 4)
COLOR_YELLOW = $(shell tput setaf 3)
TEXT_INVERSE = $(shell tput smso)
#-----------------------------------------------------------------------------------------------------------------------
# Rules (https://www.gnu.org/software/make/manual/html_node/Rule-Introduction.html#Rule-Introduction)
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: help
help: ## Show this help
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
#-----------------------------------------------------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: deps
deps: ## Download dependencies
${call print, "Downloading dependencies"}
@go mod vendor -v
$(GO_BIN)/mockgen:
${call print, "Installing mockgen"}
@go install -v github.com/golang/mock/mockgen@latest
$(GO_BIN)/golangci-lint:
${call print, "Installing golangci-lint"}
@go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GO_BIN)/govulncheck:
${call print, "Installing go vulnerability checker"}
@go install golang.org/x/vuln/cmd/govulncheck@latest
$(GO_BIN)/commander:
${call print, "Installing commander"}
@go install -v github.com/commander-cli/commander/v2/cmd/commander@latest
$(GO_BIN)/auth0:
@$(MAKE) install
#-----------------------------------------------------------------------------------------------------------------------
# Documentation
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: docs docs-start docs-clean
docs: docs-clean ## Build the documentation
@go run ./cmd/doc-gen
@mv ./docs/auth0.md ./docs/index.md
docs-start: ## Start the doc site locally for testing purposes
@cd docs && bundle install && bundle exec jekyll serve
docs-clean: ## Remove the documentation
@rm -f ./docs/auth0_*.md
#-----------------------------------------------------------------------------------------------------------------------
# Building & Installing
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: build build-all-platforms install
build: ## Build the cli binary for the native platform
${call print, "Building the cli binary"}
go build -v -ldflags "$(GO_LINKER_FLAGS)" -o "${BUILD_DIR}/auth0" cmd/auth0/main.go
build-all-platforms: ## Build a dev version of the cli binary for all supported platforms
for os in darwin linux windows; \
do env GOOS=$$os go build -ldflags "$(GO_LINKER_FLAGS)" -o "${BUILD_DIR}/auth0-$${os}" cmd/auth0/main.go; \
done
install: ## Install the cli binary for the native platform
${call print, "Installing the cli binary"}
@$(MAKE) build BUILD_DIR="$(GO_BIN)"
#-----------------------------------------------------------------------------------------------------------------------
# Checks
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: lint
lint: $(GO_BIN)/golangci-lint ## Run go linter checks
${call print, "Running golangci-lint over project"}
@golangci-lint run -v -c .golangci.yml ./...
check-vuln: $(GO_BIN)/govulncheck ## Check go vulnerabilities
${call print, "Running govulncheck over project"}
@govulncheck -v ./...
check-docs: ## Check that documentation was generated correctly
${call print, "Checking that documentation was generated correctly"}
@$(MAKE) docs
@if [ -n "$$(git status --porcelain)" ]; \
then \
echo "Rebuilding the documentation resulted in changed files:"; \
echo "$$(git diff)"; \
echo "Please run \`make docs\` to regenerate docs."; \
exit 1; \
fi
@echo "Documentation is generated correctly."
#-----------------------------------------------------------------------------------------------------------------------
# Testing
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: test test-unit test-integration test-mocks
test: test-unit test-integration ## Run all tests
test-unit: ## Run unit tests
${call print, "Running unit tests"}
@go test -race ${GO_PACKAGES} -count 1
test-integration: $(GO_BIN)/commander ## Run integration tests. To run a specific test pass the FILTER var. Usage: `make test-integration FILTER="attack protection"`
${call print, "Running integration tests"}
@$(MAKE) install # ensure fresh install prior to running test
@bash ./test/integration/scripts/run-test-suites.sh
test-mocks: $(GO_BIN)/mockgen ## Generate testing mocks using mockgen
${call print, "Generating test mocks"}
@go generate -v ./...
#-----------------------------------------------------------------------------------------------------------------------
# Helpers
#-----------------------------------------------------------------------------------------------------------------------
define print
@printf "${TEXT_INVERSE}${COLOR_WHITE} :: ${COLOR_BLUE} %-75s ${COLOR_WHITE} ${RESET}\n" $(1)
endef
define print_warning
@printf "${TEXT_INVERSE}${COLOR_WHITE} ! ${COLOR_YELLOW} %-75s ${COLOR_WHITE} ${RESET}\n" $(1)
endef