-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UPSTREAM: <carry> Add standard Makefile targets #37
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ func TestCACacheVerify(t *testing.T) { | |
} | ||
}) | ||
for desc, invalidCert := range ca.invalidCerts { | ||
invalidCert := invalidCert | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be in this pull request? Or is this from something else you are working on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's to make verification pass - the loop variable was being captured, which caused linting failures. |
||
t.Run(desc, func(t *testing.T) { | ||
t.Parallel() | ||
if err := c.verify(invalidCert); err == nil { | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably don't want this one, this was a strict experiment with CPMS and would probably not be appropriate for a forked repository. The idea is that all log keys in the structured logs are camelCase but, I don't even know if this project uses structured logs |
||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BUILD_IMAGE is not used.