|
| 1 | +CYAN := \033[36m |
| 2 | +GREEN := \033[32m |
| 3 | +YELLOW := \033[33m |
| 4 | +RESET := \033[0m |
| 5 | +BOLD := \033[1m |
| 6 | + |
| 7 | +define print_task |
| 8 | + printf "$(BOLD)$(CYAN)[TASK]$(RESET) $(BOLD)%s$(RESET)\n" "$(1)" |
| 9 | +endef |
| 10 | +define print_subtask |
| 11 | + printf " $(YELLOW)→$(RESET) %s\n" "$(1)" |
| 12 | +endef |
| 13 | +define print_success |
| 14 | + printf " $(GREEN)✓$(RESET) %s\n" "$(1)" |
| 15 | +endef |
| 16 | + |
| 17 | +## help: Show this help info. |
| 18 | +.PHONY: help |
| 19 | +help: |
| 20 | + @echo "Envoy Dynamic Modules.\n" |
| 21 | + @echo "Usage:\n make \033[36m<Target>\033[0m \n\nTargets:" |
| 22 | + @awk 'BEGIN {FS = ":.*##"; printf ""} /^[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) |
| 23 | + |
| 24 | +# This runs all necessary steps to prepare for a commit. |
| 25 | +.PHONY: precommit |
| 26 | +precommit: ## Run all necessary steps to prepare for a commit. |
| 27 | +precommit: precommit-go precommit-rust |
| 28 | + |
| 29 | +.PHONY: precommit-go |
| 30 | +precommit-go: ## This runs the linter, formatter, and tidy on the Go codebase. |
| 31 | + @$(call print_task,Tidying Go modules) |
| 32 | + @find . -name "go.mod" \ |
| 33 | + | grep go.mod \ |
| 34 | + | xargs -I {} bash -c 'dirname {}' \ |
| 35 | + | xargs -I {} bash -c 'cd {} && $(call print_subtask,Tidying {}) && go mod tidy -v;' |
| 36 | + @$(call print_success,Tidying completed) |
| 37 | + @$(call print_task,Running linter) |
| 38 | + @$(call print_subtask,Checking ./...) |
| 39 | + @cd go && go tool golangci-lint run --build-tags==cgo ./... |
| 40 | + @$(call print_success,Linting completed) |
| 41 | + @$(call print_task,Formatting code) |
| 42 | + @$(call print_subtask,Running gofmt) |
| 43 | + @cd go && find . -type f -name '*.go' | xargs gofmt -s -w |
| 44 | + @$(call print_subtask,Running gofumpt) |
| 45 | + @cd go && find . -type f -name '*.go' | xargs go tool gofumpt -l -w |
| 46 | + @$(call print_subtask,Running gci) |
| 47 | + @cd go && go tool gci write -s standard -s default -s "prefix(github.com/envoyproxy/dynamic-modules-examples)" `find . -name '*.go'` |
| 48 | + @$(call print_success,Formatting completed) |
| 49 | + |
| 50 | +.PHONY: precommt-rust |
| 51 | +precommit-rust: ## This runs the linter, formatter, and tidy on the Rust codebase. |
| 52 | + @$(call print_task,Running Rust precommit steps) |
| 53 | + @$(call print_subtask,Running cargo fmt) |
| 54 | + @cd rust && cargo fmt --all -- --check |
| 55 | + @$(call print_subtask,Running cargo clippy) |
| 56 | + @cd rust && cargo clippy -- -D warnings |
| 57 | + @$(call print_success,Rust precommit steps completed) |
| 58 | + |
| 59 | +# This runs precommit and checks for any differences in the codebase, failing if there are any. |
| 60 | +.PHONY: check |
| 61 | +check: precommit ## Run all necessary steps to prepare for a commit and check for any differences in the codebase. |
| 62 | + @$(call print_task,Checking for uncommitted changes) |
| 63 | + @if [ ! -z "`git status -s`" ]; then \ |
| 64 | + echo "$(BOLD)$(YELLOW)The following differences will fail CI until committed:$(RESET)"; \ |
| 65 | + git diff --exit-code; \ |
| 66 | + echo "$(BOLD)$(YELLOW)Please ensure you have run 'make precommit' and committed the changes.$(RESET)"; \ |
| 67 | + exit 1; \ |
| 68 | + fi |
| 69 | + @$(call print_success,No uncommitted changes found) |
| 70 | + |
| 71 | +.PHONY: test |
| 72 | +test: test-rust test-rust ## Run all tests for the codebase. |
| 73 | +.PHONY: test-go |
| 74 | +test-go:## Run the unit tests for the Go codebase. This doesn't run the integration tests like test-* targets. |
| 75 | + @$(call print_task,Running Go tests) |
| 76 | + @cd go && go test -v ./... |
| 77 | + @$(call print_success,Go unit tests completed) |
| 78 | +.PHONY: test-rust |
| 79 | +test-rust: ## Run the unit tests for the Rust codebase. |
| 80 | + @$(call print_task,Running Rust tests) |
| 81 | + @cd rust && cargo test |
| 82 | + @$(call print_success,Rust unit tests completed) |
| 83 | + |
| 84 | +.PHONY: build |
| 85 | +build: build-go build-rust ## Build all dynamic modules. |
| 86 | + |
| 87 | +.PHONY: build-go |
| 88 | +build-go: ## Build the Go dynamic module. |
| 89 | + @$(call print_task,Building Go dynamic module) |
| 90 | + @cd go && go build -buildmode=c-shared -o libgo_module.so . |
| 91 | + @$(call print_success,Go dynamic module built at go/libgo_module.so) |
| 92 | + @$(call print_task,Copying Go dynamic module for easier use with Envoy) |
| 93 | + @cp go/libgo_module.so integration/libgo_module.so |
| 94 | + |
| 95 | +.PHONY: build-rust |
| 96 | +build-rust: ## Build the Rust dynamic module. |
| 97 | + @$(call print_task,Building Rust dynamic module) |
| 98 | + @cd rust && cargo build |
| 99 | + @$(call print_success,Rust dynamic module built at rust/target/debug/librust_module.so) |
| 100 | + @$(call print_task,Copying Rust dynamic module for easier use with Envoy) |
| 101 | + @cp rust/target/debug/librust_module.dylib integration/librust_module.so || true |
| 102 | + @cp rust/target/debug/librust_module.so integration/librust_module.so || true |
| 103 | + |
| 104 | +.PHONY: integration-test |
| 105 | +integration-test: build-go build-rust ## Run the integration tests. |
| 106 | + @$(call print_task,Running integration tests) |
| 107 | + @cd integration && go test -v ./... |
| 108 | + @$(call print_success,Integration tests completed) |
0 commit comments