-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
231 lines (187 loc) · 9.73 KB
/
Copy pathMakefile
File metadata and controls
231 lines (187 loc) · 9.73 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Copyright © 2025 OpenCHAMI a Series of LF Projects, LLC
# SPDX-FileCopyrightText: © 2025 OpenCHAMI a Series of LF Projects, LLC
#
# SPDX-License-Identifier: MIT
.PHONY: help build test test-integration lint clean install run container-build container-run release-test check-no-pkg-resources-imports generate generate-check dev
# Variables
BINARY_NAME=boot-service
GO=go
GOFLAGS=-v
TEST_TIMEOUT ?= 5m
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
CONTAINER_PROG ?= $(shell command -v docker 2>/dev/null)
CONTAINER_TAG ?= latest
CONTAINER_GO_VERSION ?= $(shell awk '/^go / {print $$2; exit}' go.mod)
GO_TOOLCHAIN_VERSION ?= $(shell awk '/^go / {print $$2; exit}' go.mod)
FABRICA_VERSION ?= $(shell awk '/github.com\/openchami\/fabrica[[:space:]]+v/ {print $$2; exit}' go.mod)
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
FABRICA_CMD ?= go run github.com/openchami/fabrica/cmd/fabrica@$(FABRICA_VERSION)
FABRICA_SOURCE_ARG ?=
FABRICA_FORCE_FLAG ?=
FABRICA_ENV ?=
LOCAL_FABRICA ?=
ifneq ($(strip $(LOCAL_FABRICA)),)
FABRICA_CMD := $(LOCAL_FABRICA)/bin/fabrica
FABRICA_SOURCE_ARG := --fabrica-source $(LOCAL_FABRICA)
FABRICA_FORCE_FLAG := --force
FABRICA_ENV := GOTOOLCHAIN=auto
endif
help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
build: generate
go build -o bin/server ./cmd/server/
go build -o bin/client ./cmd/client/
generate: ## Regenerate Fabrica outputs from apis/.fabrica.yaml/apis.yaml
ifneq ($(strip $(LOCAL_FABRICA)),)
@if [ ! -x $(LOCAL_FABRICA)/bin/fabrica ]; then \
echo "Local Fabrica binary not found at $(LOCAL_FABRICA)/bin/fabrica"; \
echo "Build it with: (cd $(LOCAL_FABRICA) && go build -o bin/fabrica ./cmd/fabrica)"; \
exit 1; \
fi
endif
$(FABRICA_ENV) $(FABRICA_CMD) generate $(FABRICA_SOURCE_ARG) $(FABRICA_FORCE_FLAG)
generate-check: ## Fail if generated files are out of sync (requires clean git tree)
@if ! git diff --quiet || ! git diff --cached --quiet; then \
echo "Working tree must be clean before running generate-check"; \
git --no-pager status --short; \
exit 1; \
fi
$(MAKE) generate LOCAL_FABRICA="$(LOCAL_FABRICA)"
@if ! git diff --quiet || ! git diff --cached --quiet; then \
echo "Generated files are out of sync. Run 'make generate' and commit the results."; \
git --no-pager diff --stat; \
exit 1; \
fi
dev: build ## Regenerate code then build server and client binaries
test: ## Run tests
$(GO) test $(GOFLAGS) -timeout $(TEST_TIMEOUT) -race -coverprofile=coverage.out -covermode=atomic $$(go list ./... 2>/dev/null | grep -v /examples/)
test-integration: ## Run integration tests with explicit timeout (override with TEST_TIMEOUT=)
BOOT_SERVICE_RUN_INTEGRATION=1 $(GO) test $(GOFLAGS) -timeout $(TEST_TIMEOUT) ./pkg/controllers/bootscript -run TestBootLogicWithExistingData -v
test-coverage: test ## Run tests with coverage report
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
lint: ## Run golangci-lint
GOTOOLCHAIN=go$(GO_TOOLCHAIN_VERSION) golangci-lint run
lint-fix: ## Run golangci-lint with auto-fix
GOTOOLCHAIN=go$(GO_TOOLCHAIN_VERSION) golangci-lint run --fix
clean: ## Clean build artifacts
rm -rf bin/ dist/ coverage.out coverage.html
$(GO) clean -cache
tidy: ## Tidy go.mod
$(GO) mod tidy
run: build ## Build and run the application
./bin/$(BINARY_NAME)
container-build: ## Build container image
$(CONTAINER_PROG) build -f Dockerfile.standalone \
--build-arg GO_VERSION=$(CONTAINER_GO_VERSION) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
--build-arg DATE=$(DATE) \
-t $(BINARY_NAME):$(CONTAINER_TAG) .
container-run: container-build ## Build and run container
$(CONTAINER_PROG) run --rm $(BINARY_NAME):$(CONTAINER_TAG)
release-snapshot: ## Create a snapshot release with GoReleaser
goreleaser release --snapshot --clean
release-test: ## Test release locally using GoReleaser snapshot (requires goreleaser)
@command -v goreleaser >/dev/null 2>&1 || { echo "goreleaser is required but not installed. Install with: 'brew install goreleaser' or 'go install github.com/goreleaser/goreleaser@latest'"; exit 1; }
@goreleaser release --snapshot --clean
fmt: ## Format code
$(GO) fmt ./...
goimports -w .
vet: ## Run go vet
$(GO) vet ./...
vuln: ## Check for vulnerabilities
govulncheck ./...
reuse: ## Check REUSE compliance
reuse lint --lines
reuse-spdx: ## Generate SPDX bill of materials
reuse spdx -o reuse.spdx
reuse-install: ## Install REUSE tool
@command -v pipx >/dev/null 2>&1 || { echo "pipx is required but not installed. Install it with: python3 -m pip install --user pipx"; exit 1; }
pipx install reuse
@echo "REUSE tool installed successfully"
reuse-annotate: ## Add REUSE headers to all files in the repository
@echo "Annotating files with REUSE headers..."
@echo "This will add SPDX headers to files that don't have them yet."
# REUSE-IgnoreStart
@read -p "Copyright holder [OpenCHAMI Contributors]: " holder; \
holder=$${holder:-OpenCHAMI Contributors}; \
read -p "License [MIT]: " license; \
license=$${license:-MIT}; \
read -p "Year [$(shell date +%Y)]: " year; \
year=$${year:-$(shell date +%Y)}; \
echo "Annotating with: SPDX-FileCopyrightText: $$year $$holder"; \
echo " SPDX-License-Identifier: $$license"; \
reuse annotate --copyright="$$holder" --license="$$license" --year="$$year" --skip-existing --recursive --skip-unrecognized .
# REUSE-IgnoreEnd
reuse-download-license: ## Download a license file (usage: make reuse-download-license LICENSE=MIT)
@if [ -z "$(LICENSE)" ]; then \
echo "Error: LICENSE variable is required. Usage: make reuse-download-license LICENSE=MIT"; \
exit 1; \
fi
reuse download $(LICENSE)
pre-commit-install: ## Install pre-commit tool
@command -v pipx >/dev/null 2>&1 || { echo "pipx is required but not installed. Install it with: python3 -m pip install --user pipx"; exit 1; }
pipx install pre-commit
@echo "pre-commit installed successfully"
pre-commit-setup: ## Install pre-commit hooks
@command -v pre-commit >/dev/null 2>&1 || { echo "pre-commit is not installed. Run 'make pre-commit-install' first."; exit 1; }
pre-commit install
pre-commit install --hook-type commit-msg
@echo "pre-commit hooks installed successfully"
pre-commit-run: ## Run pre-commit hooks on all files
pre-commit run --all-files
pre-commit-update: ## Update pre-commit hooks to latest versions
pre-commit autoupdate
setup-dev: reuse-install pre-commit-install pre-commit-setup ## Set up development environment (install tools and hooks)
@echo ""
@echo "Development environment setup complete!"
@echo "Next steps:"
@echo " 1. Run 'make reuse-annotate' to add REUSE headers to all files"
@echo " 2. Run 'make pre-commit-run' to test pre-commit hooks"
@echo " 3. Start coding! Pre-commit hooks will run automatically on git commit"
@echo ""
@echo "Optional: Install 'act' to test GitHub Actions locally:"
@echo " brew install act"
@echo " make act-list # List available workflows"
act-install: ## Install act (GitHub Actions local runner) via Homebrew
@command -v brew >/dev/null 2>&1 || { echo "Homebrew is required. Install from https://brew.sh"; exit 1; }
brew install act
@echo "act installed successfully"
act-list: ## List all GitHub Actions workflows
@command -v act >/dev/null 2>&1 || { echo "act is not installed. Run 'make act-install' first."; exit 1; }
@echo "Available workflows:"
@ls -1 .github/workflows/*.yaml | sed 's/.*\// - /'
act-test: ## Run GitHub Actions test workflow locally (ubuntu only, stable Go)
@command -v act >/dev/null 2>&1 || { echo "act is not installed. Run 'make act-install' first."; exit 1; }
@echo "Note: Testing with ubuntu-latest and stable Go version only (full matrix runs on GitHub)"
act push -W .github/workflows/test.yaml --container-architecture linux/amd64 --matrix os:ubuntu-latest --matrix go-version:stable
act-build: ## Run GitHub Actions build workflow locally
@command -v act >/dev/null 2>&1 || { echo "act is not installed. Run 'make act-install' first."; exit 1; }
act push -W .github/workflows/build.yaml --container-architecture linux/amd64
act-lint: ## Run GitHub Actions golangci-lint workflow locally
@command -v act >/dev/null 2>&1 || { echo "act is not installed. Run 'make act-install' first."; exit 1; }
act push -W .github/workflows/golangci-lint.yaml --container-architecture linux/amd64
act-reuse: ## Run GitHub Actions REUSE workflow locally
@command -v act >/dev/null 2>&1 || { echo "act is not installed. Run 'make act-install' first."; exit 1; }
act push -W .github/workflows/reuse.yaml --container-architecture linux/amd64
act-vuln: ## Run GitHub Actions vulnerability check workflow locally
@command -v act >/dev/null 2>&1 || { echo "act is not installed. Run 'make act-install' first."; exit 1; }
act push -W .github/workflows/govulncheck.yaml --container-architecture linux/amd64
act-all: ## Run all testable workflows locally (build, test, lint, reuse, vuln)
@command -v act >/dev/null 2>&1 || { echo "act is not installed. Run 'make act-install' first."; exit 1; }
@echo "Running all testable workflows..."
@echo "\n=== Build Workflow ==="
@act -W .github/workflows/build.yaml || true
@echo "\n=== Test Workflow ==="
@act -W .github/workflows/test.yaml || true
@echo "\n=== Lint Workflow ==="
@act -W .github/workflows/golangci-lint.yaml || true
@echo "\n=== REUSE Workflow ==="
@act -W .github/workflows/reuse.yaml || true
@echo "\n=== Vulnerability Check Workflow ==="
@act -W .github/workflows/govulncheck.yaml || true
all: clean install lint test build ## Run all checks and build
.DEFAULT_GOAL := help