-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
95 lines (78 loc) · 3.36 KB
/
Makefile
File metadata and controls
95 lines (78 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
UV_CHECK := $(shell command -v uv 2>/dev/null)
HELM_CHECK := $(shell command -v helm 2>/dev/null)
HELM_UNITTEST_CHECK := $(shell helm plugin list | grep unittest 2>/dev/null)
CHART_KIT = uv run --directory ./scripts chartkit
DRY_RUN ?= 0
ifeq ($(DRY_RUN),1)
DRY_RUN_ARG = --dry-run
else
DRY_RUN_ARG =
endif
UPDATE_SNAPSHOTS ?= 0
UPDATE_SNAPSHOTS_FLAG := $(filter 1 true yes True Yes TRUE YES,$(UPDATE_SNAPSHOTS))
ifneq ($(UPDATE_SNAPSHOTS_FLAG),)
UNIT_TEST_MESSAGE = Running unit tests for all charts and creating new snapshots...
UPDATE_SNAPSHOTS_ARG = -u
else
UNIT_TEST_MESSAGE = Running unit tests for all charts...
UPDATE_SNAPSHOTS_ARG =
endif
PARALLEL ?=
PARALLEL_ARG := $(if $(PARALLEL),--parallel $(PARALLEL),)
%:
@:
args = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}`
MOZILLA_CRD_SCHEMAS = https://raw.githubusercontent.com/mozilla/mozcloud/main/crdSchemas/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json
.PHONY: help, install, update-dependencies, bump-charts, unit-tests, unit-tests-affected, kubeconform, clean
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
install: ## Install dependencies and pre-commit hooks
ifndef UV_CHECK
@echo "uv is not installed. Please install uv..."
@exit 1
endif
ifndef HELM_CHECK
@echo "helm is not installed. Please install helm..."
@exit 1
endif
@echo "Installing pre-commit hooks..."
@pre-commit install
ifndef HELM_UNITTEST_CHECK
@echo "Installing unittest Helm plugin..."
@helm plugin install https://github.com/helm-unittest/helm-unittest.git --verify=false
else
@echo "Updating unittest Helm plugin..."
@helm plugin update unittest
endif
update-dependencies: ## Update chart dependencies (args: chart path or --all, set DRY_RUN=1 for dry run)
$(CHART_KIT) update-dependencies $(DRY_RUN_ARG) $(call args, '--all')
bump-charts: ## Bump chart versions (args: chart path or --staged, set DRY_RUN=1 for dry run)
$(CHART_KIT) version bump $(DRY_RUN_ARG) $(call args, '--staged')
unit-tests: ## Run unit tests for all charts (set UPDATE_SNAPSHOTS=1 to update snapshots)
@missing=$$(find **/application -type f -name "Chart.yaml" -exec dirname {} \; | while read dir; do [ ! -d "$$dir/charts" ] && echo "$$dir"; done); \
if [ -n "$$missing" ]; then \
echo "Dependencies not found in: $$missing"; \
echo "Running update-dependencies..."; \
$(MAKE) update-dependencies; \
fi
@echo "$(UNIT_TEST_MESSAGE)"
@$(CHART_KIT) unittest $(UPDATE_SNAPSHOTS_ARG) $(PARALLEL_ARG)
unit-tests-affected: ## Run unit tests for staged charts and their dependents
@affected=$$($(CHART_KIT) affected); \
if [ -n "$$affected" ]; then \
$(CHART_KIT) unittest $(UPDATE_SNAPSHOTS_ARG) $$affected; \
fi
kubeconform: ## Validate snapshot resources against Kubernetes and GKE CRD schemas
@echo "Running kubeconform against test snapshots..."
@for snap in mozcloud/application/tests/__snapshot__/*.snap; do \
yq '.[] | .[]' "$$snap" | awk '/^apiVersion:/{print "---"}{print}'; \
done | kubeconform \
-schema-location default \
-schema-location '$(MOZILLA_CRD_SCHEMAS)' \
-ignore-missing-schemas \
-summary \
-output pretty
clean: ## Remove all downloaded chart dependencies
@echo "Removing downloaded chart dependencies..."
@find **/application -type d -name "charts" -exec rm -rf {} + 2>/dev/null || true
@echo "Clean complete"