-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
182 lines (143 loc) · 7.45 KB
/
Makefile
File metadata and controls
182 lines (143 loc) · 7.45 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
# Copyright © 2025 OpenCHAMI a Series of LF Projects, LLC
# SPDX-FileCopyrightText: 2025 OpenCHAMI Contributors
#
# SPDX-License-Identifier: MIT
.PHONY: help build test lint clean install run docker-build docker-run release-test
# Variables
BINARY_NAME=ex-bootstrap
GO=go
GOFLAGS=-v
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")
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
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: ## Build the application
$(GO) build $(GOFLAGS) $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd
test: ## Run tests
$(GO) test $(GOFLAGS) -race -coverprofile=coverage.out -covermode=atomic $$(go list ./... 2>/dev/null | grep -v /examples/)
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
golangci-lint run
lint-fix: ## Run golangci-lint with auto-fix
golangci-lint run --fix
clean: ## Clean build artifacts
rm -rf bin/ dist/ coverage.out coverage.html
$(GO) clean
install: ## Install dependencies
$(GO) mod download
$(GO) mod verify
tidy: ## Tidy go.mod
$(GO) mod tidy
run: build ## Build and run the application
./bin/$(BINARY_NAME)
docker-build: ## Build Docker image
docker build -t $(BINARY_NAME):latest .
docker-run: docker-build ## Build and run Docker container
docker run --rm $(BINARY_NAME):latest
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
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