-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
79 lines (63 loc) · 2.66 KB
/
Makefile
File metadata and controls
79 lines (63 loc) · 2.66 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
GO ?= go
VACUUM = github.com/daveshanley/vacuum@latest
GOMPLATE = github.com/hairyhenderson/gomplate/v4/cmd/gomplate@latest
ROOT = spec
DIST = dist
SPEC = openapi.yaml
OUTPUT = /tmp/swagger.yaml
REDOCLY := npx @redocly/cli
REDOCLY_BUNDLE_FLAGS := --remove-unused-components
REDOCLY_DOCS_FLAGS := --disableGoogleFont
SCHEMAS := $(shell find $(ROOT)/schemas -type f)
SCHEMAS_SOURCES = $(shell find $(ROOT) -maxdepth 1 -name '*.yaml')
SCHEMAS_FINAL = $(SCHEMAS_SOURCES:$(ROOT)/%.yaml=$(DIST)/specs/%.yaml)
GOMPLATE_TEMPLATE = spec/templates/resource.yaml.tpl
GOMPLATE_SOURCES = $(shell find $(ROOT)/resources -type f -name '*.yaml')
GOMPLATE_FINAL = $(GOMPLATE_SOURCES:$(ROOT)/resources/%.yaml=$(ROOT)/%.yaml)
VACUUM := $(GO) run $(VACUUM)
VACUUM_LINT_FLAGS := -r config/ruleset-recommended.yaml -b
BLUE = \033[1;34m
GREEN = \033[1;32m
YELLOW = \033[1;33m
RESET = \033[0m
.PHONY: all build resource-apis lint clean tag
all: clean build lint
build: $(DIST) resource-apis $(SCHEMAS_FINAL)
resource-apis:
@command -v gomplate >/dev/null || { echo "$(YELLOW)⚠️ gomplate command not found or not executable. Please install gomplate.\n For instructions visit $(BLUE)https://docs.gomplate.ca/installing/$(RESET)"; exit 1; }
@echo "$(BLUE)Generating OpenAPI resources with gomplate...$(RESET)"
@for f in $(GOMPLATE_SOURCES); do \
group="$$(gomplate -d spec=$$f -i '{{ (ds "spec").group }}')"; \
name="$$(gomplate -d spec=$$f -i '{{ (ds "spec").name }}' | tr '[:upper:]' '[:lower:]' | tr -d ' -')"; \
version="$$(gomplate -d spec=$$f -i '{{ (ds "spec").version }}')"; \
out="$(ROOT)/$${group}.$${name}.$${version}.yaml"; \
echo "$(GREEN)→ $$out$(RESET) from $$f"; \
$(GO) run $(GOMPLATE) -d spec=$$f -f $(GOMPLATE_TEMPLATE) -o $$out; \
done
$(DIST):
@mkdir -p $(DIST)
$(ROOT)/%.yaml: $(ROOT)/resources/%.yaml $(GOMPLATE_TEMPLATE) $(SCHEMAS) | resource-apis
@$(GO) run $(GOMPLATE) -d spec=$< -f $(GOMPLATE_TEMPLATE) -o $@
$(DIST)/specs/%.yaml: $(ROOT)/%.yaml $(SCHEMAS)
@mkdir -p $(dir $@)
@$(REDOCLY) bundle $(REDOCLY_BUNDLE_FLAGS) $< --output=$@
lint: resource-apis
@echo "$(YELLOW)Linting OpenAPI specs...$(RESET)"
@$(MAKE) $(SCHEMAS_FINAL)
@SCHEMAS="$$(find $(DIST)/specs -type f -name '*.yaml')"; \
if [ -z "$$SCHEMAS" ]; then \
echo "$(YELLOW)⚠️ No OpenAPI specs found to lint.$(RESET)"; \
exit 1; \
fi; \
$(VACUUM) lint $(VACUUM_LINT_FLAGS) -d $$SCHEMAS --fail-severity warn
clean:
@echo "$(BLUE)Cleaning up...$(RESET)"
@rm -rf $(DIST) $(OUTPUT) $(ROOT)/*.yaml
tag:
@if [ -z "$(VERSION)" ]; then \
echo "ERROR: VERSION is required. Usage: make tag VERSION=v0.1.0"; \
exit 1; \
fi
@echo "Tagging $(VERSION)..."
git tag $(VERSION)
git push origin $(VERSION)