-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (154 loc) · 6.82 KB
/
Makefile
File metadata and controls
177 lines (154 loc) · 6.82 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
.PHONY: build test clean generate sync-specs install lint verify-generated verify-site smoke smoke-seed smoke-cleanup release-check site
# Build variables
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
# Default target
all: build
# Build the CLI
build:
go build $(LDFLAGS) -o bin/jamf-cli ./cmd/jamf-cli
# Install locally
install:
go install $(LDFLAGS) ./cmd/jamf-cli
# Run tests (with race detection for concurrent code)
test:
go test -race -v ./...
# Run tests with coverage
test-cover:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Lint
lint:
golangci-lint run
# Clean build artifacts
clean:
rm -rf bin/
rm -f coverage.out coverage.html
# Path to jamf-pro-server repo (override with: make sync-specs JAMF_SERVER_PATH=/path/to/repo)
# Specs are scattered across module directories under jamf-pro-server/.
JAMF_SERVER_PATH ?= ../jamf-pro-server
JAMF_SERVER_ROOT := $(JAMF_SERVER_PATH)/jamf-pro-server
# Sync OpenAPI specs from jamf-pro-server repo and regenerate commands
sync-specs:
@if [ ! -d "$(JAMF_SERVER_ROOT)" ]; then \
echo "Error: jamf-pro-server not found at $(JAMF_SERVER_PATH)"; \
echo "Expected $(JAMF_SERVER_ROOT) to exist."; \
echo "Usage: make sync-specs JAMF_SERVER_PATH=/path/to/jss"; \
exit 1; \
fi
@echo "Syncing OpenAPI specs from $(JAMF_SERVER_ROOT)..."
@rm -f specs/*.yaml
@find $(JAMF_SERVER_ROOT) -path "*/swagger_docs/uapi/*.yaml" \
-not -path "*/uapi/hiddenapi/*" -not -path "*/uapi/common/*" \
-exec cp {} specs/ +
@find $(JAMF_SERVER_ROOT) -path "*/swagger_docs/uapi/common/*.yaml" \
-exec cp {} specs/ +
@# Normalise upstream naming where the spec filename doesn't match its paths.
@# MobileDeviceExtensionAttribute.yaml upstream holds only the legacy preview
@# endpoint (/devices/extensionAttributes — tag mobile-device-extension-attributes-preview)
@# which returns just names and is redundant with the full /v1 CRUD. Drop it
@# and rename DeviceExtensionAttribute.yaml (which actually contains the
@# /v1/mobile-device-extension-attributes CRUD) into its place so the parser
@# derives the correct resource name from the filename.
@if [ -f specs/DeviceExtensionAttribute.yaml ]; then \
rm -f specs/MobileDeviceExtensionAttribute.yaml; \
mv specs/DeviceExtensionAttribute.yaml specs/MobileDeviceExtensionAttribute.yaml; \
echo " Renamed DeviceExtensionAttribute.yaml → MobileDeviceExtensionAttribute.yaml (legacy preview dropped)"; \
fi
@dupes=$$(ls specs/*.yaml | xargs -n1 basename | sort | uniq -d); \
if [ -n "$$dupes" ]; then \
echo "Error: duplicate spec filenames (last-write-wins risk):"; \
echo "$$dupes"; \
exit 1; \
fi
@echo "Copied specs:"
@ls specs/*.yaml | wc -l | xargs echo " Total files:"
@echo "Regenerating commands..."
@$(MAKE) generate
@echo "Done! Review changes with: git diff"
# Path to, or URL of, a consolidated Jamf Pro OpenAPI document (e.g.
# https://<instance>/api/schema/). When set, sync-spec splits it into per-
# resource spec files under specs/ before regenerating.
JAMF_MONOLITH_SPEC ?=
# Sync OpenAPI specs from a single consolidated document and regenerate commands.
# JAMF_MONOLITH_SPEC accepts a local path or an http(s):// URL, e.g.:
# make sync-spec JAMF_MONOLITH_SPEC=/path/to/monolith-schema.json
# make sync-spec JAMF_MONOLITH_SPEC=https://<instance>/api/schema/
# Preserved spec files (see generator/monolith/overrides.go PreservedSpecs) and
# the classic/ and blueprint-components/ subdirectories are left untouched.
sync-spec:
@if [ -z "$(JAMF_MONOLITH_SPEC)" ]; then \
echo "Error: JAMF_MONOLITH_SPEC is not set."; \
echo "Usage: make sync-spec JAMF_MONOLITH_SPEC=<path-or-url>"; \
echo " e.g. JAMF_MONOLITH_SPEC=/tmp/monolith-schema.json"; \
echo " e.g. JAMF_MONOLITH_SPEC=https://<instance>/api/schema/"; \
exit 1; \
fi
@case "$(JAMF_MONOLITH_SPEC)" in \
http://*|https://*) ;; \
*) \
if [ ! -f "$(JAMF_MONOLITH_SPEC)" ]; then \
echo "Error: $(JAMF_MONOLITH_SPEC) not found"; \
exit 1; \
fi ;; \
esac
@echo "Ingesting monolith spec: $(JAMF_MONOLITH_SPEC)"
@$(MAKE) generate JAMF_MONOLITH_SPEC=$(JAMF_MONOLITH_SPEC)
@echo "Done! Review changes with: git diff specs internal/commands/pro/generated"
# Generate CLI commands from OpenAPI specs and Classic API manifest.
# If JAMF_MONOLITH_SPEC is set, the monolith is split into per-resource spec
# files before parsing, preserving the existing filename layout.
generate:
@echo "Generating commands from OpenAPI specs and Classic API manifest..."
ifneq ($(JAMF_MONOLITH_SPEC),)
go run ./generator/main.go --specs ./specs --output ./internal/commands/pro/generated --monolith $(JAMF_MONOLITH_SPEC)
else
go run ./generator/main.go --specs ./specs --output ./internal/commands/pro/generated
endif
@go fmt ./internal/commands/pro/generated/...
@-go fmt ./internal/blueprintcomponents/... 2>/dev/null
@echo "Generated commands:"
@ls internal/commands/pro/generated/*.go | grep -v registry | grep -v classic_ | wc -l | xargs echo " Modern API resource files:"
@ls internal/commands/pro/generated/classic_*.go 2>/dev/null | grep -v registry | wc -l | xargs echo " Classic API resource files:"
# Development helpers
dev: build
./bin/jamf-cli
# Update dependencies
deps:
go mod tidy
go mod download
# Generate site data and serve locally
site: build
go run ./generator/site/main.go --binary ./bin/jamf-cli --output ./docs/site/commands.json
@echo "Serving at http://localhost:8080 — press Ctrl+C to stop"
@cd docs/site && python3 -m http.server 8080
# Verify site has support for all product namespaces (CI-safe)
verify-site: build
@./scripts/verify-site-products.sh
# Verify generated code is up to date (CI-safe)
verify-generated:
@ls internal/commands/pro/generated/*.go | grep -v '_test\.go' | xargs rm -f
@$(MAKE) generate
@if ! git diff --quiet -- internal/commands/pro/generated/; then \
echo "Error: generated code is out of date"; \
git diff --stat -- internal/commands/pro/generated/; \
exit 1; \
fi
@echo "Generated code is up to date."
# Smoke test against a real Jamf Pro instance (reads from default config profile)
smoke:
JAMF_SMOKE_TEST=1 go test -v -run 'TestSmoke' -timeout 10m -count=1 ./internal/commands/...
# Seed test instance with minimal _smoke-test resources
smoke-seed:
JAMF_SMOKE_TEST=1 go test -v -run 'TestSmoke_Seed' -timeout 5m -count=1 ./internal/commands/...
# Remove all _smoke-test resources from the test instance
smoke-cleanup:
JAMF_SMOKE_TEST=1 go test -v -run 'TestSmoke_Cleanup' -timeout 5m -count=1 ./internal/commands/...
# Pre-release verification: unit tests + smoke tests
release-check: test smoke
# Format code
fmt:
go fmt ./...
gofumpt -w .