-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathMakefile
More file actions
75 lines (57 loc) · 2.61 KB
/
Copy pathMakefile
File metadata and controls
75 lines (57 loc) · 2.61 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
# Get the directory where this Makefile is, so we can use it below for including
DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
# Definitions for the extended tests
GO_PKG_NAME := github.com/openshift-eng/openshift-tests-extension
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
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)
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
TOOLS_BIN_DIR := $(CURDIR)/bin
BINARY_NAME := openshift-apiserver-tests-ext
.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 Development
.PHONY: verify #HELP To verify the code
verify: tidy fmt vet
.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: build
build: #HELP Build the extended tests binary
@mkdir -p $(TOOLS_BIN_DIR)
GO_COMPLIANCE_POLICY="exempt_all" CGO_ENABLED=0 go build -mod=mod -ldflags "$(LDFLAGS)" -o $(TOOLS_BIN_DIR)/$(BINARY_NAME) ./cmd/...
.PHONY: update-metadata
update-metadata: build #HELP Build and run 'update-metadata' to generate test metadata
$(TOOLS_BIN_DIR)/$(BINARY_NAME) update
$(MAKE) clean-metadata
.PHONY: build-update
build-update: build update-metadata #HELP Build and update metadata and sanitize output
.PHONY: clean
clean: #HELP Remove build artifacts
rm -rf $(TOOLS_BIN_DIR)
#SECTION Metadata
.PHONY: list-test-names
list-test-names: build #HELP Show current full test names
@$(TOOLS_BIN_DIR)/$(BINARY_NAME) list -o names
.PHONY: clean-metadata
clean-metadata: #HELP Remove 'codeLocations' from metadata JSON
@echo "Cleaning metadata (removing codeLocations)..."
@for f in $(METADATA)/*.json; do \
jq 'map(del(.codeLocations))' "$$f" > "$$f.tmp" && mv "$$f.tmp" "$$f"; \
done
.PHONY: verify-metadata #HELP To verify that the metadata was properly updated
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