-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
128 lines (98 loc) · 3.53 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
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
#! /usr/bin/make
#(C) Copyright 2022-2024 Hewlett Packard Enterprise Development LP
# Inspiration from https://github.com/rightscale/go-boilerplate/blob/master/Makefile
NAME=$(shell find cmd -name ".gitkeep_provider" -exec dirname {} \; | sort -u | sed -e 's|cmd/||')
ifeq ("$(GOARCH)","")
GOARCH="amd64"
endif
GOFLAGS_OTHER= CGO_ENABLED=0
FIPS_BUILD ?= 0
ifeq ("$(FIPS_BUILD)","1")
GOFLAGS_OTHER=
undefine CGO_ENABLED
endif
# version shouldn't have 'v' prefix for >= 0.13
VERSION=$(shell cat ./version)
# Change DUMMY_PROVIDER below to reflect the name of the service under development. The
# value of this variable is used in LOCAL_LOCATION, and is also used in the
DUMMY_PROVIDER=metal
LOCAL_LOCATION=~/.local/share/terraform/plugins/terraform.example.com/$(DUMMY_PROVIDER)/hpegl/$(VERSION)/linux_$(GOARCH)
# Stuff that needs to be installed globally (not in vendor)
DEPEND=
# Directory for documentation.
DOCS_DIR="docs"
# Will get the branch name
SYMBOLIC_REF=$(shell if [ -n "$$CIRCLE_TAG" ] ; then echo $$CIRCLE_TAG; else git symbolic-ref HEAD | cut -d"/" -f 3; fi)
COMMIT_ID=$(shell git rev-parse --verify HEAD)
DATE=$(shell date +"%F %T")
PACKAGE := $(shell git remote get-url origin | sed -e 's|http://||' -e 's|^.*@||' -e 's|.git||' -e 's|:|/|')
VERSION_PACKAGE=$(PACKAGE)/pkg/cmd/$@
VFLAG=-X '$(VERSION_PACKAGE).name=$@' \
-X '$(VERSION_PACKAGE).version=$(SYMBOLIC_REF)' \
-X '$(VERSION_PACKAGE).buildDate=$(DATE)' \
-X '$(VERSION_PACKAGE).buildSha=$(COMMIT_ID)'
TAGS=
# kelog issue: https://github.com/rjeczalik/notify/issues/108
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
TAGS=-tags kqueue
endif
TMPFILE := $(shell mktemp)
GOOSALT ?= 'linux'
GOOS='$(GOOSALT)'
LOCALIZATION_FILES := $(shell find . -name \*.toml | grep -v vendor | grep -v ./bin)
$(NAME): $(shell find . -name \*.go)
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOFLAGS_OTHER) go build $(TAGS) -ldflags "$(VFLAG)" -o build/$@ .
default: all
.PHONY: default
vendor: go.mod go.sum
go mod download
go mod vendor
update up: really-clean vendor
.PHONY: update up
clean:
rm -rf gathered_logs build .vendor/pkg $(testreport_dir) $(coverage_dir)
.PHONY: clean
really-clean clean-all cleanall: clean
rm -rf vendor
.PHONY: really-clean clean-all cleanall
procs := $(shell grep -c ^processor /proc/cpuinfo 2>/dev/null || echo 1)
go-lint: vendor golangci-lint-config.yaml
@golangci-lint --version
golangci-lint run --config golangci-lint-config.yaml --new-from-rev origin/master --max-issues-per-linter 0 --max-same-issues 0
.PHONY: go-lint
tf-lint:
@terraform fmt -check -recursive -diff || \
(echo "Some terraform files need to be formatted. Run 'terraform fmt -recursive' to fix them." && return false)
.PHONY: tf-lint
lint: go-lint tf-lint
.PHONY: lint
tools: vendor
@go install github.com/golangci/golangci-lint/cmd/golangci-lint
.PHONY: tools
testreport_dir := test-reports
test:
go test -v ./...
.PHONY: test
coverage_dir := coverage/go
coverage: vendor
@mkdir -p $(coverage_dir)/html
go test -coverpkg=./... -coverprofile=$(coverage_dir)/coverage.out -v $$(go list ./... | grep -v /vendor/)
@go tool cover -html=$(coverage_dir)/coverage.out -o $(coverage_dir)/html/main.html;
@echo "Generated $(coverage_dir)/html/main.html";
.PHONY: coverage
acceptance:
TF_ACC=true go test -v -count=1 -timeout=600s ./...
build: vendor $(NAME)
.PHONY: build
install: build $(NAME)
# terraform >= v0.13
mkdir -p $(LOCAL_LOCATION)
cp build/$(NAME) $(LOCAL_LOCATION)
.PHONY: install
docs: vendor
mkdir -p $(DOCS_DIR)
go generate ./main.go
.PHONY: docs
all: lint test
.PHONY: all