forked from openshift/operator-framework-operator-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
192 lines (158 loc) · 8.11 KB
/
Makefile
File metadata and controls
192 lines (158 loc) · 8.11 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Get the directory where this Makefile is, so we can use it below for including
# Include the same Bingo variables used by the project
DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
# Use openshift's Bingo variables
include $(DIR)/../.bingo/Variables.mk
# Definitions for the extended tests
GO_PKG_NAME := github.com/openshift-eng/openshift-tests-extension
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_TREE_STATE := $(shell if git diff --quiet; then echo clean; else echo dirty; fi)
LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \
-X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \
-X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)'
METADATA := $(shell pwd)/.openshift-tests-extension/openshift_payload_olmv1.json
#SECTION General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '#SECTION' and the
# target descriptions by '#HELP' or '#EXHELP'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: #HELP something, and then pretty-format the target and help. Then,
# if there's a line with #SECTION something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
# The extended-help target uses '#EXHELP' as the delineator.
.PHONY: help
help: #HELP Display essential help.
@awk 'BEGIN {FS = ":[^#]*#HELP"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\n"} /^[a-zA-Z_0-9-]+:.*#HELP / { printf " \033[36m%-17s\033[0m %s\n", $$1, $$2 } ' $(MAKEFILE_LIST)
#SECTION Tests
TOOLS_BIN_DIR := $(CURDIR)/bin
#SECTION Development
.PHONY: verify #HELP To verify the code
verify: tidy fmt vet lint
.PHONY: tidy #HELP Run go mod tidy.
tidy:
go mod tidy
.PHONY: fmt
fmt: #HELP Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: #HELP Run go vet against code.
go vet ./...
.PHONY: lint
lint: $(GOLANGCI_LINT) #HELP Run golangci linter.
$(GOLANGCI_LINT) run
.PHONY: fix-lint
fix-lint: $(GOLANGCI_LINT) #HELP Fix lint issues
$(GOLANGCI_LINT) run --fix
.PHONY: bindata
bindata: $(GO_BINDATA)
bindata: pkg/bindata/operator/operator.go
pkg/bindata/operator/operator.go: $(shell find testdata/operator -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg operator -o $@ -prefix "testdata/operator" testdata/operator/...
go fmt ./$(@D)/...
bindata: pkg/bindata/catalog/catalog.go
pkg/bindata/catalog/catalog.go: $(shell find testdata/catalog -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg catalog -o $@ -prefix "testdata/catalog" testdata/catalog/...
go fmt ./$(@D)/...
bindata: pkg/bindata/webhook/bundle/bundle.go
pkg/bindata/webhook/bundle/bundle.go: $(shell find testdata/webhook/bundle -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg webhookbundle -o $@ -prefix "testdata/webhook/bundle" testdata/webhook/bundle/...
go fmt ./$(@D)/...
bindata: pkg/bindata/webhook/index/index.go
pkg/bindata/webhook/index/index.go: $(shell find testdata/webhook/index -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg webhookindex -o $@ -prefix "testdata/webhook/index" testdata/webhook/index/...
go fmt ./$(@D)/...
bindata: pkg/bindata/singleown/bundle/bundle.go
pkg/bindata/singleown/bundle/bundle.go: $(shell find testdata/singleown/bundle -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg singleownbundle -o $@ -prefix "testdata/singleown/bundle" testdata/singleown/bundle/...
go fmt ./$(@D)/...
bindata: pkg/bindata/singleown/index/index.go
pkg/bindata/singleown/index/index.go: $(shell find testdata/singleown/index -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg singleownindex -o $@ -prefix "testdata/singleown/index" testdata/singleown/index/...
go fmt ./$(@D)/...
bindata: pkg/bindata/boxcutter/bundle/bundle.go
pkg/bindata/boxcutter/bundle/bundle.go: $(shell find testdata/boxcutter/bundle -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg boxcutterbundle -o $@ -prefix "testdata/boxcutter/bundle" testdata/boxcutter/bundle/...
go fmt ./$(@D)/...
bindata: pkg/bindata/boxcutter/catalog/catalog.go
pkg/bindata/boxcutter/catalog/catalog.go: $(shell find testdata/boxcutter/catalog -type f)
mkdir -p $(@D)
$(GO_BINDATA) -pkg boxcuttercatalog -o $@ -prefix "testdata/boxcutter/catalog" testdata/boxcutter/catalog/...
go fmt ./$(@D)/...
bindata: pkg/bindata/qe/bindata.go
pkg/bindata/qe/bindata.go: $(shell find test/qe/testdata -type f)
mkdir -p $(@D)
$(GO_BINDATA) -nocompress -nometadata \
-pkg testdata -o $@ -prefix "testextended" test/qe/testdata/...
gofmt -s -w $@
# GO_COMPLIANCE_POLICY="exempt_all" must only be used for test related binaries.
# It prevents various FIPS compliance policies from being applied to this compilation.
# Do not set globally.
.PHONY: build
build: #HELP Build the extended tests binary
@mkdir -p $(TOOLS_BIN_DIR)
GO_COMPLIANCE_POLICY="exempt_all" go build -ldflags "$(LDFLAGS)" -mod=vendor -o $(TOOLS_BIN_DIR)/olmv1-tests-ext ./cmd/...
.PHONY: update-metadata
update-metadata: #HELP Build and run 'update-metadata' to generate test metadata
$(TOOLS_BIN_DIR)/olmv1-tests-ext update --component openshift:payload:olmv1
$(MAKE) clean-metadata
# Ensure TestID is unique over time.
# TestID is built over Product:Type:ComponentName:TestDescription
# (i.e. openshift:payload:olmv1:TestName)
# Details:
# - https://github.com/openshift/enhancements/blob/master/enhancements/testing/openshift-tests-extension.md#test-id
# - https://github.com/openshift-eng/ci-test-mapping
#──────────────────────────────────────────────────────────────
# How to rename a test?
# 1. Run: make list-test-names
# 2. Find the current full test name (e.g. "[sig-abc] My test does XYZ")
# 3. Add a Ginkgo label: ginkgo.Label("original-name:[sig-abc] My test does XYZ"). if there is existing original-name label, please do not update the label again and keep it unchanged.
# 4. Change the test name string and run: make build-update
# **Example**
# It("should pass a renamed sanity check",
# Label("original-name:[sig-olmv1] OLMv1 should pass a trivial sanity check"),
# func(ctx context.Context) {
# Expect(len("test")).To(BeNumerically(">", 0))
# })
# Note: You only add the label once. Do not update it after future renames.
#──────────────────────────────────────────────────────────────
# How to delete a test?
# 1. Run: make list-test-names
# 2. In main.go add:
# ext.IgnoreObsoleteTests(
# "[sig-olmv1] My removed test name",
# )
# 3. Delete the test code in your suite file (e.g. olmv1.go)
# 4. Run: make build-update.
# This will regenerate the metadata without the test entry.
#────────────────────────────────────────────────────────────────────
.PHONY: build-update
build-update: bindata build update-metadata #HELP Build and update metadata and sanitize output
#SECTION Metadata
.PHONY: list-test-names
list-test-names: #HELP Show current full test names
@$(TOOLS_BIN_DIR)/olmv1-tests-ext list -o names
# Remove 'codeLocations' to avoid absolute paths like:
# "/Users/$(USER)/go/src/.../olmv1.go:12"
# These are machine-specific and make the metadata non-idempotent.
# More info: https://issues.redhat.com/browse/TRT-2186
.PHONY: clean-metadata
clean-metadata: #HELP Remove 'codeLocations' from metadata JSON
@echo "Cleaning metadata (removing codeLocations)..."
@jq 'map(del(.codeLocations))' $(METADATA) > $(METADATA).tmp && mv $(METADATA).tmp $(METADATA)
.PHONY: verify-metadata #HELP To verify that the metadata was properly update
verify-metadata: update-metadata
@if ! git diff --exit-code $(METADATA); then \
echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \
exit 1; \
fi