|
| 1 | +# Get the directory where this Makefile is, so we can use it below for including |
| 2 | +DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))) |
| 3 | + |
| 4 | +# Definitions for the extended tests |
| 5 | +GO_PKG_NAME := github.com/openshift-eng/openshift-tests-extension |
| 6 | + |
| 7 | +GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown') |
| 8 | +BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 9 | +GIT_TREE_STATE := $(shell if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet; then echo clean; else echo dirty; fi; else echo unknown; fi) |
| 10 | + |
| 11 | +LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \ |
| 12 | + -X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \ |
| 13 | + -X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)' |
| 14 | + |
| 15 | +METADATA := $(shell pwd)/.openshift-tests-extension |
| 16 | + |
| 17 | +TOOLS_BIN_DIR := $(CURDIR)/bin |
| 18 | +BINARY_NAME := cluster-kube-apiserver-operator-tests-ext |
| 19 | + |
| 20 | +.PHONY: help |
| 21 | +help: #HELP Display essential help. |
| 22 | + @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) |
| 23 | + |
| 24 | +#SECTION Development |
| 25 | +.PHONY: verify #HELP To verify the code |
| 26 | +verify: tidy fmt vet |
| 27 | + |
| 28 | +.PHONY: tidy #HELP Run go mod tidy. |
| 29 | +tidy: |
| 30 | + go mod tidy |
| 31 | + |
| 32 | +.PHONY: fmt |
| 33 | +fmt: #HELP Run go fmt against code. |
| 34 | + go fmt ./... |
| 35 | + |
| 36 | +.PHONY: vet |
| 37 | +vet: #HELP Run go vet against code. |
| 38 | + go vet ./... |
| 39 | + |
| 40 | +.PHONY: build |
| 41 | +build: #HELP Build the extended tests binary |
| 42 | + @mkdir -p $(TOOLS_BIN_DIR) |
| 43 | + GO_COMPLIANCE_POLICY="exempt_all" CGO_ENABLED=0 go build -mod=mod -ldflags "$(LDFLAGS)" -o $(TOOLS_BIN_DIR)/$(BINARY_NAME) ./cmd/... |
| 44 | + |
| 45 | +.PHONY: update-metadata |
| 46 | +update-metadata: build #HELP Build and run 'update-metadata' to generate test metadata |
| 47 | + $(TOOLS_BIN_DIR)/$(BINARY_NAME) update |
| 48 | + $(MAKE) clean-metadata |
| 49 | + |
| 50 | +.PHONY: build-update |
| 51 | +build-update: build update-metadata #HELP Build and update metadata and sanitize output |
| 52 | + |
| 53 | +.PHONY: clean |
| 54 | +clean: #HELP Remove build artifacts |
| 55 | + rm -rf $(TOOLS_BIN_DIR) |
| 56 | + |
| 57 | +#SECTION Metadata |
| 58 | + |
| 59 | +.PHONY: list-test-names |
| 60 | +list-test-names: build #HELP Show current full test names |
| 61 | + @$(TOOLS_BIN_DIR)/$(BINARY_NAME) list -o names |
| 62 | + |
| 63 | +.PHONY: clean-metadata |
| 64 | +clean-metadata: #HELP Remove 'codeLocations' from metadata JSON |
| 65 | + @echo "Cleaning metadata (removing codeLocations)..." |
| 66 | + @for f in $(METADATA)/*.json; do \ |
| 67 | + jq 'map(del(.codeLocations))' "$$f" > "$$f.tmp" && mv "$$f.tmp" "$$f"; \ |
| 68 | + done |
| 69 | + |
| 70 | +.PHONY: verify-metadata #HELP To verify that the metadata was properly updated |
| 71 | +verify-metadata: update-metadata |
| 72 | + @if ! git diff --exit-code $(METADATA); then \ |
| 73 | + echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \ |
| 74 | + exit 1; \ |
| 75 | + fi |
0 commit comments