forked from cycloidio/terracognita
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (79 loc) · 2.99 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
SHELL := /bin/bash
BIN := terracognita
BIN_DIR := $(GOPATH)/bin
GOLINT := $(BIN_DIR)/golinter
GOIMPORTS := $(BIN_DIR)/goimports
ENUMER := $(BIN_DIR)/enumer
MOCKGEN := $(BIN_DIR)/mockgen
VERSION= $(shell git describe --tags --always)
PLATFORMS=darwin linux windows
ARCHITECTURES=386 amd64
BUILD_PATH := builds
PROVIDER ?= all
IS_CI := 0
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-X github.com/cycloidio/terracognita/cmd.Version=${VERSION}"
.PHONY: help
help: Makefile ## This help dialog
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//'`); \
for help_line in $${help_lines[@]}; do \
IFS=$$'#' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf "%-30s %s\n" $$help_command $$help_info ; \
done
$(MOCKGEN):
@go get -u github.com/golang/mock/mockgen
$(GOIMPORTS):
@go get -u golang.org/x/tools/cmd/goimports
$(ENUMER):
@go get -u github.com/dmarkham/enumer
$(GOLINT):
@go get -u golang.org/x/lint/golint
.PHONY: lint
lint: $(GOLINT) $(GOIMPORTS) ## Runs the linter
@GO111MODULE=on golint -set_exit_status ./... && test -z "`go list -f {{.Dir}} ./... | xargs goimports -l | tee /dev/stderr`"
.PHONY: generate
generate: $(MOCKGEN) $(GOIMPORTS) $(ENUMER) ## Generates the needed code
@GO111MODULE=on rm -rf ./mock/a && \
go generate ./... && \
goimports -w ./mock
.PHONY: test
test: ## Runs the tests
@docker run --rm \
-v $$(pwd):/app \
-w /app \
-u $(shell id -u):$(shell id -g) \
-v $(shell go env GOCACHE):/tmp/gocach \
-e "GOCACHE=/tmp/gocach" \
-v $(GOPATH)/pkg/mod:/go/pkg/mod golang:1.17 \
go test ./...
.PHONY: ci
ci: lint test ## Runs the linter and the tests
.PHONY: dbuild
dbuild: ## Builds the docker image with same name as the binary
@docker build -t $(BIN) .
.PHONY: build
build: ## Builds the binary
GO111MODULE=on CGO_ENABLED=0 GOARCH=amd64 go build -o $(BIN) ${LDFLAGS}
.PHONY: build-all build-compress
build-all: ## Builds the binaries
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES),\
$(shell export GO111MODULE=on; export CGO_ENABLED=0; export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build -v -o $(BUILD_PATH)/$(BIN)-$(GOOS)-$(GOARCH) ${LDFLAGS})))
build-compress: build-all ## Builds and compress the binaries
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES),\
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); tar -C $(BUILD_PATH) -czf $(BUILD_PATH)/$(BIN)-$(GOOS)-$(GOARCH).tar.gz $(BIN)-$(GOOS)-$(GOARCH))))
.PHONY: install
install: ## Install the binary
GO111MODULE=on CGO_ENABLED=0 GOARCH=amd64 go install ${LDFLAGS}
.PHONY: clean
clean: ## Removes binary and/or docker image
rm -f $(BIN)
docker rmi -f $(BIN)
.PHONY: update-terraform-provider
update-terraform-provider: ## Update terraform-provider version used for AWS, Azure, GCP
./scripts/terraform-provider-update/update.sh $(PROVIDER)