Skip to content
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

makefile enhancements #95

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 26 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
SHELL := /bin/bash

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_PATH := $(abspath $(firstword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
GO ?= go

all: help

.PHONY : help
help: Makefile
@sed -n 's/^##//p' $<

# Ginkgo tool
GINKGO = $(PROJECT_PATH)/bin/ginkgo
$(GINKGO):
# In order to make sure the version of the ginkgo cli installed
# is the same as the version of go.mod,
# instead of calling go-install-tool,
# running go install from the current module will pick version from current go.mod file.
GOBIN=$(PROJECT_PATH)/bin go install github.com/onsi/ginkgo/v2/ginkgo

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.

KIND = $(PROJECT_PATH)/bin/kind
KIND_VERSION = v0.22.0
$(KIND):
$(call go-install-tool,$(KIND),sigs.k8s.io/kind@$(KIND_VERSION))
# 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: kind
kind: $(KIND) ## Download kind locally if necessary.
.PHONY : help
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very fancy 🧐

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%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

KUSTOMIZE = $(PROJECT_PATH)/bin/kustomize
$(KUSTOMIZE):
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
include ./make/tools/*.mk

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
##@ Development

## test: Run unit tests
.PHONY : test
test: clean-cov fmt vet $(GINKGO)
test: clean-cov fmt vet $(GINKGO) ## Run unit tests
mkdir -p $(PROJECT_PATH)/coverage
# Shuffle both the order in which specs within a suite run, and the order in which different suites run
# You can always rerun a given ordering later by passing the --seed flag a matching seed.
Expand All @@ -51,9 +38,9 @@ test: clean-cov fmt vet $(GINKGO)
--coverprofile cover.out \
./pkg/... ./cmd/...

## install: Build and install kuadrantctl binary ($GOBIN or GOPATH/bin)

.PHONY : install
install: fmt vet
install: fmt vet ## Build and install kuadrantctl binary ($GOBIN or GOPATH/bin)
@set -e; \
GIT_SHA=$$(git rev-parse --short=7 HEAD 2>/dev/null) || { \
GIT_HASH=$${GITHUB_SHA:-NO_SHA}; \
Expand All @@ -79,28 +66,30 @@ prepare-local-cluster: $(KIND) ## Deploy locally kuadrant operator from the curr
env-setup:
$(MAKE) gateway-api-install

## local-setup: Sets up Kind cluster with GatewayAPI manifests and istio GW, nothing Kuadrant. Build and install kuadrantctl binary
.PHONY: local-setup
local-setup:
local-setup: ## Sets up Kind cluster with GatewayAPI manifests
$(MAKE) prepare-local-cluster
$(MAKE) env-setup

## local-cleanup: Delete local cluster
.PHONY: local-cleanup
local-cleanup: ## Delete local cluster
$(MAKE) kind-delete-cluster

.PHONY : fmt
fmt:
fmt: ## Run go fmt ./...
$(GO) fmt ./...

.PHONY : vet
vet:
vet: ## Run go vet ./...
$(GO) vet ./...

.PHONY: clean-cov
clean-cov: ## Remove coverage reports
rm -rf $(PROJECT_PATH)/coverage

.PHONY: run-lint
run-lint: $(GOLANGCI-LINT) ## Run linter tool (golangci-lint)
$(GOLANGCI-LINT) run --timeout 2m

# Include last to avoid changing MAKEFILE_LIST used above
include ./make/*.mk
10 changes: 10 additions & 0 deletions make/tools/ginkgo.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GINKGO = $(PROJECT_PATH)/bin/ginkgo
$(GINKGO):
# In order to make sure the version of the ginkgo cli installed
# is the same as the version of go.mod,
# instead of calling go-install-tool,
# running go install from the current module will pick version from current go.mod file.
GOBIN=$(PROJECT_PATH)/bin go install github.com/onsi/ginkgo/v2/ginkgo

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
7 changes: 7 additions & 0 deletions make/tools/kind.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
KIND = $(PROJECT_PATH)/bin/kind
KIND_VERSION = v0.22.0
$(KIND):
$(call go-install-tool,$(KIND),sigs.k8s.io/kind@$(KIND_VERSION))

.PHONY: kind
kind: $(KIND) ## Download kind locally if necessary.
6 changes: 6 additions & 0 deletions make/tools/kustomize.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
KUSTOMIZE = $(PROJECT_PATH)/bin/kustomize
$(KUSTOMIZE):
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
7 changes: 2 additions & 5 deletions make/lint.mk → make/tools/lint.mk
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

GOLANGCI-LINT=$(PROJECT_PATH)/bin/golangci-lint
$(GOLANGCI-LINT):
mkdir -p $(PROJECT_PATH)/bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.55.2

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI-LINT)

.PHONY: run-lint
run-lint: $(GOLANGCI-LINT)
$(GOLANGCI-LINT) run --timeout 2m
golangci-lint: $(GOLANGCI-LINT) ## Download golangci-lint
Loading