|
| 1 | +# Colors for output |
| 2 | +GREEN := $(shell printf '\033[32m') |
| 3 | +RESET := $(shell printf '\033[0m') |
| 4 | +BOLD := $(shell printf '\033[1m') |
| 5 | + |
| 6 | +# Shell source files - use shfmt to find them (respects .editorconfig) |
| 7 | +SHELL_SRC_FILES := $(shell shfmt -f .) |
| 8 | + |
| 9 | +.PHONY: all |
| 10 | +all: build |
| 11 | + |
| 12 | +.PHONY: build |
| 13 | +build: |
| 14 | + go build ./... |
| 15 | + |
| 16 | +.PHONY: test |
| 17 | +test: |
| 18 | + go test ./... -race |
| 19 | + |
| 20 | +.PHONY: test/integration |
| 21 | +test/integration: |
| 22 | + go test -tags=integration -v -timeout=8m ./... |
| 23 | + |
| 24 | +.PHONY: lint |
| 25 | +lint: lint/go lint/shellcheck |
| 26 | + |
| 27 | +.PHONY: lint/go |
| 28 | +lint/go: |
| 29 | + golangci-lint run --timeout=5m |
| 30 | + |
| 31 | +.PHONY: lint/shellcheck |
| 32 | +lint/shellcheck: $(SHELL_SRC_FILES) |
| 33 | + echo "--- shellcheck" |
| 34 | + shellcheck --external-sources $(SHELL_SRC_FILES) |
| 35 | + |
| 36 | +.PHONY: fmt |
| 37 | +fmt: fmt/go fmt/shfmt |
| 38 | + |
| 39 | +.PHONY: fmt/go |
| 40 | +fmt/go: |
| 41 | + go fmt ./... |
| 42 | + |
| 43 | +.PHONY: fmt/shfmt |
| 44 | +fmt/shfmt: $(SHELL_SRC_FILES) |
| 45 | +ifdef FILE |
| 46 | + # Format single shell script |
| 47 | + if [[ -f "$(FILE)" ]] && [[ "$(FILE)" == *.sh ]]; then \ |
| 48 | + echo "$(GREEN)==>$(RESET) $(BOLD)fmt/shfmt$(RESET) $(FILE)"; \ |
| 49 | + shfmt -w "$(FILE)"; \ |
| 50 | + fi |
| 51 | +else |
| 52 | + echo "$(GREEN)==>$(RESET) $(BOLD)fmt/shfmt$(RESET)" |
| 53 | +# Only do diff check in CI, errors on diff. |
| 54 | +ifdef CI |
| 55 | + shfmt -d $(SHELL_SRC_FILES) |
| 56 | +else |
| 57 | + shfmt -w $(SHELL_SRC_FILES) |
| 58 | +endif |
| 59 | +endif |
| 60 | + |
| 61 | +.PHONY: clean |
| 62 | +clean: |
| 63 | + rm -f coder-logstream-kube |
| 64 | + |
| 65 | +.PHONY: kind/create |
| 66 | +kind/create: |
| 67 | + ./scripts/kind-setup.sh create |
| 68 | + |
| 69 | +.PHONY: kind/delete |
| 70 | +kind/delete: |
| 71 | + ./scripts/kind-setup.sh delete |
| 72 | + |
| 73 | +.PHONY: help |
| 74 | +help: |
| 75 | + @echo "Available targets:" |
| 76 | + @echo " build - Build the project" |
| 77 | + @echo " test - Run unit tests" |
| 78 | + @echo " test/integration - Run integration tests (requires KinD cluster)" |
| 79 | + @echo " lint - Run all linters" |
| 80 | + @echo " lint/go - Run golangci-lint" |
| 81 | + @echo " lint/shellcheck - Run shellcheck on shell scripts" |
| 82 | + @echo " fmt - Format all code" |
| 83 | + @echo " fmt/go - Format Go code" |
| 84 | + @echo " fmt/shfmt - Format shell scripts" |
| 85 | + @echo " kind/create - Create KinD cluster for integration tests" |
| 86 | + @echo " kind/delete - Delete KinD cluster" |
| 87 | + @echo " clean - Remove build artifacts" |
0 commit comments