forked from kubernetes/cloud-provider-gcp
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPSTREAM: <carry> Add standard Makefile targets
Signed-off-by: Nolan Brubaker <[email protected]>
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
|
||
VERSION ?= $(shell git describe --always --abbrev=7) | ||
MUTABLE_TAG ?= latest | ||
IMAGE ?= gcp-cloud-controller-manager | ||
BUILD_IMAGE ?= registry.ci.openshift.org/openshift/release:golang-1.20 | ||
|
||
ifeq ($(shell command -v podman > /dev/null 2>&1 ; echo $$? ), 0) | ||
ENGINE=podman | ||
else ifeq ($(shell command -v docker > /dev/null 2>&1 ; echo $$? ), 0) | ||
ENGINE=docker | ||
endif | ||
|
||
USE_DOCKER ?= 0 | ||
ifeq ($(USE_DOCKER), 1) | ||
ENGINE=docker | ||
endif | ||
|
||
|
||
.PHONY: all | ||
all: build | ||
|
||
##@ General | ||
|
||
# The help target prints out all targets with their descriptions organized | ||
# beneath their categories. The categories are represented by '##@' and the | ||
# target descriptions by '##'. The awk commands is responsible for reading the | ||
# entire set of makefiles included in this invocation, looking for lines of the | ||
# file as xyz: ## something, and then pretty-format the target and help. Then, | ||
# if there's a line with ##@ 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 | ||
|
||
.PHONY: help | ||
help: ## Display this help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
##@ Development | ||
|
||
.PHONY: fmt | ||
fmt: ## Run go fmt against code. | ||
go fmt ./... | ||
|
||
.PHONY: vet | ||
vet: ## Run go vet against code. | ||
go vet ./... | ||
|
||
.PHONY: vendor | ||
vendor: ## Ensure the vendor directory is up to date. | ||
go mod tidy | ||
go mod vendor | ||
go mod verify | ||
|
||
.PHONY: lint | ||
lint: ## Run golangci-lint over the codebase. | ||
$(call ensure-home, ${GOLANGCI_LINT} run ./... --timeout 5m) | ||
./openshift-hack/scripts/verify-log-keys.sh | ||
|
||
.PHONY: test | ||
test: fmt vet unit ## Run tests. | ||
|
||
.PHONY: verify-% | ||
verify-%: ## Ensure no diff after running some other target | ||
make $* | ||
./openshift-hack/scripts/verify-diff.sh | ||
|
||
##@ Build | ||
|
||
.PHONY: build | ||
build:fmt vet ## Build manager binary. | ||
go build -o bin/gcp-cloud-controller-manager ./cmd/cloud-controller-manager | ||
|
||
|
||
.PHONY: images | ||
images: ## Create images | ||
$(ENGINE) build -t "$(IMAGE):$(VERSION)" -t "$(IMAGE):$(MUTABLE_TAG)" ./ | ||
|
||
.PHONY: push | ||
push: ## Push images | ||
$(ENGINE) push "$(IMAGE):$(VERSION)" | ||
$(ENGINE) push "$(IMAGE):$(MUTABLE_TAG)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FILE_DIFF=$(git ls-files -o --exclude-standard) | ||
|
||
if [ "$FILE_DIFF" != "" ]; then | ||
echo "Found untracked files:" | ||
echo $FILE_DIFF | ||
exit 1 | ||
fi | ||
|
||
git diff --exit-code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
invalidLines=0 | ||
|
||
for f in $(find . -name "*_test.go"); do | ||
# Find all lines that have a KeysAndValues (ie any test case inspecting set log keys). | ||
# We have to use pcregrep here so that it captures multi line regexes. | ||
allKeys=$(pcregrep --line-offsets -M 'KeysAndValues: \[\]interface{}{[^}]*},' ${f}) | ||
|
||
# Find all lines that have a compliant set of keys (ie lowerCamelCase). | ||
# We have to use pcregrep here so that it captures multi line regexes. | ||
compliantKeys=$(pcregrep --line-offsets -M 'KeysAndValues: \[\]interface{}{(\n)?(\s*\"[a-z][A-Za-z]*\",[^}]*,?\n?)*\n?\s*},' ${f}) | ||
|
||
# Find the lines which are only present in the first of these | ||
nonCompliantLines=$(echo $allKeys $compliantKeys | xargs -n1 | sort | uniq -u) | ||
|
||
for l in $nonCompliantLines; do | ||
((invalidLines+=1)) | ||
echo "Found non-compliant log key around ${f} line ${l}. All log keys should be lowerCamelCase." | ||
|
||
# We keep the beginning of the line so sum the start and end of the offset to work out how many characters to print. | ||
chars=$(echo $l | cut -d: -f2 | awk 'BEGIN {RS="," ; sum = 0 }{sum += $1 }END { print sum }') | ||
# Print starting at the matched line number, the number of chars we calculated | ||
tail -n +$(echo $l | cut -d: -f1) ${f} | head -c $chars | ||
# Ensure a new line at the end | ||
echo | ||
done | ||
done | ||
|
||
exit $invalidLines |