|
| 1 | +# Get the directory where this Makefile is, so we can use it below for including |
| 2 | +# Include the same Bingo variables used by the project |
| 3 | +DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))) |
| 4 | +# Use openshift's Bingo variables |
| 5 | +include $(DIR)/../../.bingo/Variables.mk |
| 6 | + |
| 7 | +# Definitions for the extended tests |
| 8 | + |
| 9 | +GO_PKG_NAME := github.com/openshift-eng/openshift-tests-extension |
| 10 | + |
| 11 | +GIT_COMMIT := $(shell git rev-parse --short HEAD) |
| 12 | +BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 13 | +GIT_TREE_STATE := $(shell if git diff --quiet; then echo clean; else echo dirty; fi) |
| 14 | + |
| 15 | +LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \ |
| 16 | + -X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \ |
| 17 | + -X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)' |
| 18 | + |
| 19 | + |
| 20 | +METADATA := $(shell pwd)/.openshift-tests-extension/openshift_payload_olmv0.json |
| 21 | + |
| 22 | +#SECTION General |
| 23 | + |
| 24 | +# The help target prints out all targets with their descriptions organized |
| 25 | +# beneath their categories. The categories are represented by '#SECTION' and the |
| 26 | +# target descriptions by '#HELP' or '#EXHELP'. The awk commands is responsible for reading the |
| 27 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 28 | +# file as xyz: #HELP something, and then pretty-format the target and help. Then, |
| 29 | +# if there's a line with #SECTION something, that gets pretty-printed as a category. |
| 30 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 31 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 32 | +# More info on the awk command: |
| 33 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 34 | +# The extended-help target uses '#EXHELP' as the delineator. |
| 35 | + |
| 36 | +.PHONY: help |
| 37 | +help: #HELP Display essential help. |
| 38 | + @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) |
| 39 | + |
| 40 | +#SECTION Tests |
| 41 | +TOOLS_BIN_DIR := $(CURDIR)/bin |
| 42 | + |
| 43 | +#SECTION Development |
| 44 | +.PHONY: verify #HELP To verify the code |
| 45 | +verify: tidy fmt vet lint |
| 46 | + |
| 47 | +.PHONY: tidy #HELP Run go mod tidy. |
| 48 | +tidy: |
| 49 | + go mod tidy |
| 50 | + |
| 51 | +.PHONY: fmt |
| 52 | +fmt: #HELP Run go fmt against code. |
| 53 | + go fmt ./... |
| 54 | + |
| 55 | +.PHONY: vet |
| 56 | +vet: #HELP Run go vet against code. |
| 57 | + go vet ./... |
| 58 | + |
| 59 | +.PHONY: lint |
| 60 | +lint: $(GOLANGCI_LINT) #HELP Run golangci linter. |
| 61 | + $(GOLANGCI_LINT) run |
| 62 | + |
| 63 | +.PHONY: fix-lint |
| 64 | +fix-lint: $(GOLANGCI_LINT) #HELP Fix lint issues |
| 65 | + $(GOLANGCI_LINT) run --fix |
| 66 | + |
| 67 | +# Bindata generation |
| 68 | +.PHONY: bindata |
| 69 | +bindata: $(GO_BINDATA) |
| 70 | + |
| 71 | +bindata: test/extended/testdata/bindata.go |
| 72 | +test/extended/testdata/bindata.go: $(shell find test/extended/testdata -type f ! -name 'bindata.go') |
| 73 | + mkdir -p $(@D) |
| 74 | + $(GO_BINDATA) -nocompress -nometadata \ |
| 75 | + -pkg testdata -o $@ -prefix "testextended" \ |
| 76 | + -ignore "test/extended/testdata/bindata.go" test/extended/testdata/... |
| 77 | + gofmt -s -w $@ |
| 78 | + |
| 79 | +# GO_COMPLIANCE_POLICY="exempt_all" must only be used for test related binaries. |
| 80 | +# It prevents various FIPS compliance policies from being applied to this compilation. |
| 81 | +# Do not set globally. |
| 82 | +.PHONY: build |
| 83 | +build: #HELP Build the extended tests binary |
| 84 | + @mkdir -p $(TOOLS_BIN_DIR) |
| 85 | + GO_COMPLIANCE_POLICY="exempt_all" go build -ldflags "$(LDFLAGS)" -mod=vendor -o $(TOOLS_BIN_DIR)/olmv0-tests-ext ./cmd/... |
| 86 | + |
| 87 | +.PHONY: update-metadata |
| 88 | +update-metadata: #HELP Build and run 'update-metadata' to generate test metadata |
| 89 | + $(TOOLS_BIN_DIR)/olmv0-tests-ext update --component openshift:payload:olmv0 |
| 90 | + $(MAKE) clean-metadata |
| 91 | + |
| 92 | + |
| 93 | +# Ensure TestID is unique over time. |
| 94 | +# TestID is built over Product:Type:ComponentName:TestDescription |
| 95 | +# (i.e. openshift:payload:olmv0:TestName) |
| 96 | +# Details: |
| 97 | +# - https://github.com/openshift/enhancements/blob/master/enhancements/testing/openshift-tests-extension.md#test-id |
| 98 | +# - https://github.com/openshift-eng/ci-test-mapping |
| 99 | +#────────────────────────────────────────────────────────────── |
| 100 | +# How to rename a test? |
| 101 | +# 1. Run: make list-test-names |
| 102 | +# 2. Find the current full test name (e.g. "[sig-abc] My test does XYZ") |
| 103 | +# 3. Add a Ginkgo label: ginkgo.Label("original-name:[sig-abc] My test does XYZ") |
| 104 | +# 4. Change the test name string and run: make build-update |
| 105 | +# **Example** |
| 106 | +# It("should pass a renamed sanity check", |
| 107 | +# Label("original-name:[sig-operator] OLMv0 should pass a trivial sanity check"), |
| 108 | +# func(ctx context.Context) { |
| 109 | +# Expect(len("test")).To(BeNumerically(">", 0)) |
| 110 | +# }) |
| 111 | +# Note: You only add the label once. Do not update it after future renames. |
| 112 | +#────────────────────────────────────────────────────────────── |
| 113 | +# How to delete a test? |
| 114 | +# 1. Run: make list-test-names |
| 115 | +# 2. In main.go add: |
| 116 | +# ext.IgnoreObsoleteTests( |
| 117 | +# "[sig-operator] My removed test name", |
| 118 | +# ) |
| 119 | +# 3. Delete the test code in your suite file (e.g. olmv0.go) |
| 120 | +# 4. Run: make build-update. |
| 121 | +# This will regenerate the metadata without the test entry. |
| 122 | +#──────────────────────────────────────────────────────────────────── |
| 123 | +.PHONY: build-update |
| 124 | +build-update: bindata build update-metadata #HELP Build and update metadata and sanitize output |
| 125 | + |
| 126 | +#SECTION Metadata |
| 127 | + |
| 128 | +.PHONY: list-test-names |
| 129 | +list-test-names: #HELP Show current full test names |
| 130 | + @$(TOOLS_BIN_DIR)/olmv0-tests-ext list -o names |
| 131 | + |
| 132 | +# Remove 'codeLocations' to avoid absolute paths like: |
| 133 | +# "/Users/$(USER)/go/src/.../olmv0.go:12" |
| 134 | +# These are machine-specific and make the metadata non-idempotent. |
| 135 | +# More info: https://issues.redhat.com/browse/TRT-2186 |
| 136 | +.PHONY: clean-metadata |
| 137 | +clean-metadata: #HELP Remove 'codeLocations' from metadata JSON |
| 138 | + @echo "Cleaning metadata (removing codeLocations)..." |
| 139 | + @jq 'map(del(.codeLocations))' $(METADATA) > $(METADATA).tmp && mv $(METADATA).tmp $(METADATA) |
| 140 | + |
| 141 | +.PHONY: verify-metadata #HELP To verify that the metadata was properly update |
| 142 | +verify-metadata: update-metadata |
| 143 | + @if ! git diff --exit-code $(METADATA); then \ |
| 144 | + echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \ |
| 145 | + exit 1; \ |
| 146 | + fi |
0 commit comments