-
Notifications
You must be signed in to change notification settings - Fork 80
/
Makefile
176 lines (145 loc) · 4.31 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#
# 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
RHCS_LOCAL_DIR=$(DESTINATION_PREFIX)/terraform.local/local/rhcs
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//' | sed 's/-prerelease\.[0-9]*//')
commit:=$(shell git rev-parse --short HEAD)
git_status:=$(shell git status --porcelain)
REL_VER=$(version)
# 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: clean 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="$(RHCS_LOCAL_DIR)/$${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 internal/...
.PHONY: unit-test-coverage
unit-test-coverage:
ginkgo run \
--succinct \
--cover \
--coverprofile coverage.out \
-ldflags="$(ldflags)" \
-r provider internal/...
.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_tests
fmt_tests:
terraform fmt -recursive tests
.PHONY: fmt
fmt: fmt_go fmt_tf fmt_tests
.PHONY: clean
clean:
rm -rf "$(RHCS_LOCAL_DIR)"
generate: tools
go generate ./...
.PHONY: tools
tools:
go install github.com/onsi/ginkgo/v2/[email protected]
go install go.uber.org/mock/[email protected]
.PHONY: e2e_sanity_test
e2e_sanity_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: e2e_clean_tf_states
e2e_clean_tf_states:
find tests/tf-manifests -name 'terraform.tfstate*' -exec rm -rf {} \; || true
.PHONY: e2e_clean_tf_vars
e2e_clean_tf_vars:
find tests/tf-manifests -name 'terraform.tfvars*' -exec rm -rf {} \; || true
.PHONY: e2e_clean_tf_init
e2e_clean_tf_init:
find tests/tf-manifests -name '.terraform*' -exec rm -rf {} \; || true
.PHONY: e2e_clean_tf
e2e_clean_tf: e2e_clean_tf_init e2e_clean_tf_states e2e_clean_tf_vars
.PHONY: apply_folder
apply_folder: install
bash ./ci/apply_folder.sh
.PHONY: destroy_folder
destroy_folder: install
bash ./ci/destroy_folder.sh
.PHONY: binary
binary:
podman run --pull=always --rm registry.ci.openshift.org/ci/rhcs-tf-bin:latest cat /root/terraform-provider-rhcs > ~/terraform-provider-rhcs && chmod +x ~/terraform-provider-rhcs
.PHONY: e2e_test
e2e_test: tools install
ginkgo run \
--label-filter $(LabelFilter)\
--timeout 5h \
-r \
--focus-file tests/e2e/.* \
$(NULL)
.PHONY: check-gen
check-gen: generate
scripts/assert_no_diff.sh "generate"
.PHONY: prepare_release
prepare_release:
import_path=${import_path} ldflags="${ldflags}" bash ./build/build_multiarch