-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
64 lines (47 loc) · 2.55 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
NAME := terraform-provider-docker
ROOT_DIR := $(if $(ROOT_DIR),$(ROOT_DIR),$(shell git rev-parse --show-toplevel))
BUILD_DIR := $(ROOT_DIR)/dist
VERSION := $(shell git describe --tags --dirty)
GITSHA := $(shell git rev-parse --short HEAD)
BUILD_TIME := $(shell date +'%Y-%m-%d_%T')
GO_OS := $(if $(GOHOSTOS),$(GOHOSTOS),$(shell go env GOHOSTOS))
GO_ARCH := $(if $(GOHOSTARCH),$(GOHOSTARCH),$(shell go env GOHOSTARCH))
OS_ARCH := $(GO_OS)_$(GO_ARCH)
GIT_BRANCH :=$(shell git rev-parse --abbrev-ref HEAD)
GIT_REVISION :=$(shell git rev-list -1 HEAD)
GIT_REVISION_DIRTY :=$(shell (git diff-index --quiet HEAD -- . && git diff --staged --quiet -- .) || echo "-dirty")
GO_LINT_CHECKS := govet ineffassign staticcheck unused
.PHONY: prepare lint check sec build-dev build install test testacc fmt release-test release clean
all: testacc build
prepare:
mkdir -p $(BUILD_DIR)
lint:
$(GO_LINT_HEAD) $(GO_ENV_VARS) golangci-lint run --disable-all $(foreach check,$(GO_LINT_CHECKS), -E $(check)) $(foreach issue,$(GO_LINT_EXCLUDE_ISSUES), -e $(issue)) $(GO_LINT_TRAIL)
check: lint test
sec:
go get -u github.com/securego/gosec/v2/cmd/gosec
$(shell go list -f {{.Target}} github.com/securego/gosec/v2/cmd/gosec) -fmt=golint ./...
build-dev:
go build -ldflags "-X main.commit=$(GIT_BRANCH)@$(GIT_REVISION)$(GIT_REVISION_DIRTY) -X main.buildTime=$(BUILD_TIME) -X main.version=$(VERSION) -X main.builtBy=${USER}" -o ~/.terraform.d/plugins/$(NAME)_$(VERSION) .
build: prepare
go build -ldflags "-X main.commit=$(GIT_BRANCH)@$(GIT_REVISION)$(GIT_REVISION_DIRTY) -X main.buildTime=$(BUILD_TIME) -X main.version=$(VERSION) -X main.builtBy=${USER}" -o $(BUILD_DIR)/$(NAME)_$(VERSION) .
install: build
mkdir -p ~/.terraform.d/plugins/github.com/habakke/docker/$(VERSION)/$(OS_ARCH)
mv $(BUILD_DIR)/$(NAME)_$(VERSION) ~/.terraform.d/plugins/github.com/habakke/docker/$(VERSION)/$(OS_ARCH)/$(NAME)_$(VERSION)
test: prepare
go test -v -tags unit -coverprofile=$(BUILD_DIR)/cover.out ./...
testacc: export TF_ACC=true
testacc: prepare
go test -v -coverprofile=$(BUILD_DIR)/cover.out ./...
fmt:
go fmt ./...
release-test: export GITHUB_SHA=$(GITSHA)
release-test: export GPG_FINGERPRINT=0000
release-test: testacc
goreleaser release --skip-publish --snapshot --rm-dist --skip-sign
release: export GITHUB_SHA=$(GITSHA)
release: test
@read -p "Enter Release Tag: " release; git tag -a $$release -m "Release $$release" && git push origin $$release
clean:
rm -rf $(BUILD_DIR)
rm -rf ~/.terraform.d/plugins/github.com/habakke/docker