forked from terraform-redhat/terraform-provider-rhcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (103 loc) · 2.89 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
#
# Copyright (c) 2021 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Disable CGO so that we always generate static binaries:
export CGO_ENABLED=0
export version=""
ifeq ($(shell go env GOOS),windows)
BINARY=terraform-provider-rhcs.exe
DESTINATION_PREFIX=$(APPDATA)/terraform.d/plugins
else
BINARY=terraform-provider-rhcs
DESTINATION_PREFIX=$(HOME)/.terraform.d/plugins
endif
GO_ARCH=$(shell go env GOARCH)
TARGET_ARCH=$(shell go env GOOS)_${GO_ARCH}
# Import path of the project:
import_path:=github.com/terraform-redhat/terraform-provider-rhcs
# Version of the project:
version=$(shell git describe --abbrev=0 | sed 's/^v//')
commit:=$(shell git rev-parse --short HEAD)
# Set the linker flags so that the version will be included in the binaries:
ldflags:=\
-X $(import_path)/build.Version=$(version) \
-X $(import_path)/build.Commit=$(commit) \
$(NULL)
.PHONY: build
build:
go build -ldflags="$(ldflags)" -o ${BINARY}
.PHONY: install
install: build
platform=$$(terraform version -json | jq -r .platform); \
extension=""; \
if [[ "$${platform}" =~ ^windows_.*$$ ]]; then \
extension=".exe"; \
fi; \
if [ -z "${version}" ]; then \
version="0.0.2"; \
fi; \
dir="$(DESTINATION_PREFIX)/terraform.local/local/rhcs/$${version}/$(TARGET_ARCH)"; \
file="terraform-provider-rhcs$${extension}"; \
mkdir -p "$${dir}"; \
mv ${BINARY} "$${dir}/$${file}"
.PHONY: subsystem-test
subsystem-test: install
ginkgo run \
--succinct \
-ldflags="$(ldflags)" \
-r subsystem
.PHONY: unit-test
unit-test:
ginkgo run \
--succinct \
-ldflags="$(ldflags)" \
-r provider
.PHONY: test tests
test tests: unit-test subsystem-test
.PHONY: fmt_go
fmt_go:
gofmt -s -l -w $$(find . -name '*.go')
.PHONY: fmt_tf
fmt_tf:
terraform fmt -recursive examples
.PHONY: fmt
fmt: fmt_go fmt_tf
.PHONY: clean
clean:
rm -rf .terraform.d
generate:
go generate ./...
.PHONY: tools
tools:
go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.1
go install github.com/golang/mock/mockgen@v1.6.0
.PHONY: e2e_test
e2e_test: tools install
ginkgo run $(ginkgo_flags) \
--timeout 5h \
-r \
--focus-file ci/e2e/.* \
-- \
--token-url=$(test_token_url) \
--gateway-url=$(test_gateway_url) \
--offline-token=$(test_token) \
--openshift-version=$(openshift_version) \
$(NULL)
.PHONY: apply_folder
apply_folder: install
bash ./ci/apply_folder.sh
.PHONY: destroy_folder
destroy_folder: install
bash ./ci/destroy_folder.sh