Makefile RawHistoryFolder
1# This Makefile is used for dev purposes
2# Variables
3REPO := ghcr.io/bnema/gordon
4TAG := v2-dev
5DEV_TAG := v2-dev-$(shell date +%Y%m%d-%H%M%S)
6DIST_DIR := ./dist
7ENGINE := podman
8
9# Version information
10VERSION := $(shell git describe --tags --always --dirty)
11COMMIT := $(shell git rev-parse --short HEAD)
12BUILD_DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p')
13# Probe the working tree directly (tracked edits and untracked files) instead
14# of parsing VERSION, so an overridden VERSION cannot mask a dirty checkout.
15# `git describe --dirty`, which VERSION uses, only reflects tracked edits.
16DIRTY := $(if $(shell git status --porcelain --untracked-files=normal 2>/dev/null),true,false)
17
18# Build flags
19LDFLAGS := -s -w \
20 -X main.version=$(VERSION) \
21 -X main.commit=$(COMMIT) \
22 -X main.date=$(BUILD_DATE) \
23 -X main.dirty=$(DIRTY)
24
25# Architectures
26ARCHS := amd64 arm64
27
28# Phony targets
29.PHONY: all build build-push clean dev-release \
30 test test-short test-race test-coverage \
31 lint fmt check mocks clean-test help
32
33# Default target
34all: build
35
36##@ Development
37
38help: ## Show this help
39 @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
40
41fmt: ## Format Go code
42 @echo "Formatting Go code..."
43 @go fmt ./...
44
45lint: ## Run golangci-lint
46 @echo "Running linter..."
47 @golangci-lint run ./...
48
49mocks: ## Generate mocks using mockery
50 @echo "Generating mocks..."
51 @mockery
52 @echo "Mocks generated successfully"
53
54check: lint test ## Run lint and tests
55
56##@ Testing
57
58test: ## Run all tests
59 @echo "Running tests..."
60 @go test ./...
61
62test-v: ## Run all tests with verbose output
63 @go test -v ./...
64
65test-short: ## Run tests (skip long-running tests)
66 @go test -short ./...
67
68test-race: ## Run tests with race detector
69 @echo "Running tests with race detector..."
70 @go test -race ./...
71
72test-coverage: ## Run tests with coverage report
73 @echo "Running tests with coverage..."
74 @go test -coverprofile=coverage.out ./...
75 @go tool cover -func=coverage.out
76 @go tool cover -html=coverage.out -o coverage.html
77 @echo "Coverage report generated: coverage.html"
78
79test-usecase: ## Run usecase layer tests only
80 @go test -v ./internal/usecase/...
81
82test-adapter: ## Run adapter layer tests only
83 @go test -v ./internal/adapters/...
84
85##@ Build
86
87build: ## Build binaries for linux (amd64 and arm64)
88 @echo "Building Go binaries..."
89 @mkdir -p $(DIST_DIR)
90 @rm -f $(DIST_DIR)/*
91 @echo "Building with version $(VERSION), commit $(COMMIT), date $(BUILD_DATE), dirty $(DIRTY)"
92 @CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-amd64 ./main.go
93 @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-arm64 ./main.go
94 @echo "Go binaries built successfully"
95
96build-local: ## Build binary for current platform
97 @echo "Building for current platform..."
98 @go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon ./main.go
99 @echo "Binary built: $(DIST_DIR)/gordon"
100
101##@ Release
102
103build-push: ## Build and push Docker images
104 @echo "Cleaning up dangling images..."
105 @$(ENGINE) image prune -f
106
107 @echo "Building and pushing Docker images..."
108 @for arch in $(ARCHS); do \
109 $(ENGINE) build --platform linux/$$arch \
110 --build-arg VERSION="$(VERSION)" \
111 --build-arg COMMIT="$(COMMIT)" \
112 --build-arg BUILD_DATE="$(BUILD_DATE)" \
113 --build-arg DIRTY="$(DIRTY)" \
114 -t $(REPO):$(TAG)-$$arch .; \
115 $(ENGINE) push $(REPO):$(TAG)-$$arch; \
116 done
117
118 @echo "Removing existing manifest..."
119 @$(ENGINE) manifest rm $(REPO):$(TAG) || true
120
121 @echo "Creating multi-arch manifest..."
122 @$(ENGINE) manifest create $(REPO):$(TAG) \
123 $(REPO):$(TAG)-amd64 \
124 $(REPO):$(TAG)-arm64
125
126 @echo "Annotating arm64 image..."
127 @$(ENGINE) manifest annotate $(REPO):$(TAG) \
128 $(REPO):$(TAG)-arm64 --arch arm64 --variant v8
129
130 @echo "Inspecting manifest..."
131 @$(ENGINE) manifest inspect $(REPO):$(TAG)
132
133 @echo "Pushing multi-arch manifest..."
134 @$(ENGINE) manifest push --all $(REPO):$(TAG)
135
136 @echo "Script completed successfully."
137
138dev-release: build ## Create dev GitHub release
139 @echo "Creating dev GitHub release..."
140 @if [ -z "$(shell which gh)" ]; then \
141 echo "Error: GitHub CLI (gh) is not installed. Please install it first."; \
142 exit 1; \
143 fi
144 @echo "Creating dev release $(DEV_TAG)..."
145 @gh release create $(DEV_TAG) \
146 --title "Gordon Dev Build $(DEV_TAG)" \
147 --notes "🚧 **Development Build** 🚧\n\nThis is an automated development build for testing purposes.\n\n**Commit:** $(COMMIT)\n**Build Date:** $(BUILD_DATE)\n\n⚠️ This is not a stable release. Use at your own risk." \
148 --prerelease \
149 --draft=false \
150 $(DIST_DIR)/gordon-linux-amd64 \
151 $(DIST_DIR)/gordon-linux-arm64
152 @echo "Dev release created successfully!"
153 @echo ""
154 @echo "📦 Download URLs:"
155 @echo " AMD64: wget https://git.bnema.dev/gordon/releases/download/$(DEV_TAG)/gordon-linux-amd64"
156 @echo " ARM64: wget https://git.bnema.dev/gordon/releases/download/$(DEV_TAG)/gordon-linux-arm64"
157 @echo ""
158 @echo "🔗 Release page: https://git.bnema.dev/gordon/releases/tag/$(DEV_TAG)"
159
160##@ Cleanup
161
162clean: ## Clean build artifacts
163 @echo "Cleaning up..."
164 @rm -rf $(DIST_DIR)
165 @echo "Cleanup completed."
166
167clean-all: clean clean-test ## Clean all artifacts including test files
168 @$(ENGINE) system prune -f
169
170clean-test: ## Clean test artifacts
171 @rm -f coverage.out coverage.html