|
| 1 | +SHELL := /bin/bash |
| 2 | + |
| 3 | +PACKAGE ?= cloudflare-dns-stack |
| 4 | +XRD_DIR := apis/dnsstacks |
| 5 | +COMPOSITION := $(XRD_DIR)/composition.yaml |
| 6 | +DEFINITION := $(XRD_DIR)/definition.yaml |
| 7 | +CONFIGURATION := $(XRD_DIR)/configuration.yaml |
| 8 | +EXAMPLE_DEFAULT := examples/dnsstacks/standard.yaml |
| 9 | +RENDER_TESTS := $(wildcard tests/test-*) |
| 10 | +E2E_TESTS := $(wildcard tests/e2etest-*) |
| 11 | + |
| 12 | +clean: |
| 13 | + rm -rf _output |
| 14 | + rm -rf .up |
| 15 | + rm -f $(CONFIGURATION) |
| 16 | + |
| 17 | +build: |
| 18 | + up project build |
| 19 | + |
| 20 | +generate-configuration: |
| 21 | + @set -euo pipefail; \ |
| 22 | + hops validate generate-configuration --path . --api-path "$(XRD_DIR)" |
| 23 | + |
| 24 | +# Examples list - mirrors GitHub Actions workflow |
| 25 | +# Format: example_path::observed_resources_path (observed_resources_path is optional) |
| 26 | +EXAMPLES := \ |
| 27 | + examples/dnsstacks/minimal.yaml:: \ |
| 28 | + examples/dnsstacks/with-external-secrets.yaml:: \ |
| 29 | + examples/dnsstacks/standard.yaml:: |
| 30 | + |
| 31 | +# Render all examples (parallel execution, output shown per-job when complete) |
| 32 | +render\:all: |
| 33 | + @tmpdir=$$(mktemp -d); \ |
| 34 | + pids=""; \ |
| 35 | + for entry in $(EXAMPLES); do \ |
| 36 | + example=$${entry%%::*}; \ |
| 37 | + observed=$${entry#*::}; \ |
| 38 | + outfile="$$tmpdir/$$(echo $$entry | tr '/:' '__')"; \ |
| 39 | + ( \ |
| 40 | + if [ -n "$$observed" ]; then \ |
| 41 | + echo "=== Rendering $$example with observed-resources $$observed ==="; \ |
| 42 | + up composition render --xrd=$(DEFINITION) $(COMPOSITION) $$example --observed-resources=$$observed; \ |
| 43 | + else \ |
| 44 | + echo "=== Rendering $$example ==="; \ |
| 45 | + up composition render --xrd=$(DEFINITION) $(COMPOSITION) $$example; \ |
| 46 | + fi; \ |
| 47 | + echo "" \ |
| 48 | + ) > "$$outfile" 2>&1 & \ |
| 49 | + pids="$$pids $$!:$$outfile"; \ |
| 50 | + done; \ |
| 51 | + failed=0; \ |
| 52 | + for pair in $$pids; do \ |
| 53 | + pid=$${pair%%:*}; \ |
| 54 | + outfile=$${pair#*:}; \ |
| 55 | + if ! wait $$pid; then failed=1; fi; \ |
| 56 | + cat "$$outfile"; \ |
| 57 | + done; \ |
| 58 | + rm -rf "$$tmpdir"; \ |
| 59 | + exit $$failed |
| 60 | + |
| 61 | +# Validate all examples (parallel execution, output shown per-job when complete) |
| 62 | +validate\:all: generate-configuration |
| 63 | + @tmpdir=$$(mktemp -d); \ |
| 64 | + pids=""; \ |
| 65 | + for entry in $(EXAMPLES); do \ |
| 66 | + example=$${entry%%::*}; \ |
| 67 | + observed=$${entry#*::}; \ |
| 68 | + outfile="$$tmpdir/$$(echo $$entry | tr '/:' '__')"; \ |
| 69 | + ( \ |
| 70 | + if [ -n "$$observed" ]; then \ |
| 71 | + echo "=== Validating $$example with observed-resources $$observed ==="; \ |
| 72 | + up composition render --xrd=$(DEFINITION) $(COMPOSITION) $$example \ |
| 73 | + --observed-resources=$$observed --include-full-xr --quiet | \ |
| 74 | + crossplane beta validate $(XRD_DIR) --error-on-missing-schemas -; \ |
| 75 | + else \ |
| 76 | + echo "=== Validating $$example ==="; \ |
| 77 | + up composition render --xrd=$(DEFINITION) $(COMPOSITION) $$example \ |
| 78 | + --include-full-xr --quiet | \ |
| 79 | + crossplane beta validate $(XRD_DIR) --error-on-missing-schemas -; \ |
| 80 | + fi; \ |
| 81 | + echo "" \ |
| 82 | + ) > "$$outfile" 2>&1 & \ |
| 83 | + pids="$$pids $$!:$$outfile"; \ |
| 84 | + done; \ |
| 85 | + failed=0; \ |
| 86 | + for pair in $$pids; do \ |
| 87 | + pid=$${pair%%:*}; \ |
| 88 | + outfile=$${pair#*:}; \ |
| 89 | + if ! wait $$pid; then failed=1; fi; \ |
| 90 | + cat "$$outfile"; \ |
| 91 | + done; \ |
| 92 | + rm -rf "$$tmpdir"; \ |
| 93 | + exit $$failed |
| 94 | + |
| 95 | +# Shorthand aliases |
| 96 | +.PHONY: render validate generate-configuration |
| 97 | +render: ; @$(MAKE) 'render:all' |
| 98 | +validate: ; @$(MAKE) generate-configuration 'validate:all' |
| 99 | + |
| 100 | +# Single example targets |
| 101 | +render\:%: |
| 102 | + @example="examples/dnsstacks/$*.yaml"; \ |
| 103 | + up composition render --xrd=$(DEFINITION) $(COMPOSITION) $$example |
| 104 | + |
| 105 | +validate\:%: generate-configuration |
| 106 | + @example="examples/dnsstacks/$*.yaml"; \ |
| 107 | + up composition render --xrd=$(DEFINITION) $(COMPOSITION) $$example \ |
| 108 | + --include-full-xr --quiet | \ |
| 109 | + crossplane beta validate $(XRD_DIR) --error-on-missing-schemas - |
| 110 | + |
| 111 | +test: |
| 112 | + up test run $(RENDER_TESTS) |
| 113 | + |
| 114 | +e2e: |
| 115 | + up test run $(E2E_TESTS) --e2e |
| 116 | + |
| 117 | +publish: |
| 118 | + @if [ -z "$(tag)" ]; then echo "Error: tag is not set. Usage: make publish tag=<version>"; exit 1; fi |
| 119 | + up project build --push --tag $(tag) |
0 commit comments