-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile
101 lines (79 loc) · 2.08 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
SHELL = /bin/sh
APP_NAME ?= terraform-provider-ansiblevault
PACKAGES ?= ./...
GO_FILES ?= *.go */*/*.go
VERSION = $(shell git describe --tags)
GOBIN=bin
BINARY_PATH=$(GOBIN)/$(APP_NAME)
LIB_SOURCE = main.go
GO_ARCH ?= $(shell go env GOHOSTARCH)
GO_OS ?= $(shell go env GOHOSTOS)
TERRAFORM_PLUGIN_FOLDER ?= $(HOME)/.terraform.d/plugins
.DEFAULT_GOAL := app
## help: Display list of commands
.PHONY: help
help: Makefile
@sed -n 's|^##||p' $< | column -t -s ':' | sed -e 's|^| |'
## name: Output name
.PHONY: name
name:
@printf "%s" "$(APP_NAME)"
## version: Output sha1 of last commit
.PHONY: version
version:
@printf "%s" "$(VERSION)"
##app: Build app with dependencies download
.PHONY: app
app: init dev
## dev: Build app
.PHONY: dev
dev: format style test build
## init: Download dependencies
.PHONY: init
init:
go install github.com/kisielk/errcheck@latest
go install "github.com/golangci/golangci-lint/cmd/golangci-lint@latest"
go install "golang.org/x/tools/cmd/goimports@latest"
go mod tidy
## format: Format code
.PHONY: format
format:
goimports -w $(GO_FILES)
gofmt -s -w $(GO_FILES)
## style: Lint code
.PHONY: style
style:
golangci-lint run
errcheck -ignoretests $(PACKAGES)
go vet $(PACKAGES)
## test: Test with coverage
.PHONY: test
test:
script/coverage
## build: Build binary
.PHONY: build
build:
CGO_ENABLED=0 go build -ldflags="-s -w" -installsuffix nocgo -o "$(BINARY_PATH)_$(VERSION)" "$(LIB_SOURCE)"
# install: Install plugin into terraform plugin system
.PHONY: install
install:
mkdir -p "$(TERRAFORM_PLUGIN_FOLDER)/$(GO_OS)_$(GO_ARCH)/"
cp "$(BINARY_PATH)_$(VERSION)" "$(TERRAFORM_PLUGIN_FOLDER)/$(GO_OS)_$(GO_ARCH)/$(APP_NAME)_$(VERSION)"
# uninstall: Remove plugin from terraform plugin system
.PHONY: uninstall
uninstall:
rm "$(TERRAFORM_PLUGIN_FOLDER)/$(GO_OS)_$(GO_ARCH)/$(APP_NAME)_$(VERSION)"
# clean: Delete binary
.PHONY: clean
clean:
rm "$(BINARY_PATH)_$(VERSION)"
## github: Build and deploy on github
.PHONY: github
github:
script/release
## config: Configure dev environment
.PHONY: config
config:
script/install_hooks
.PHONY: all
all: build install