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
14# Build flags
15LDFLAGS := -s -w \
16 -X main.version=$(VERSION) \
17 -X main.commit=$(COMMIT) \
18 -X main.date=$(BUILD_DATE)
19
20# Architectures
21ARCHS := amd64 arm64
22
23# Phony targets
24.PHONY: all build build-push clean dev-release \
25 test test-short test-race test-coverage \
26 lint fmt check mocks clean-test help
27
28# Default target
29all: build
30
31##@ Development
32
33help: ## Show this help
34 @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)
35
36fmt: ## Format Go code
37 @echo "Formatting Go code..."
38 @go fmt ./...
39
40lint: ## Run golangci-lint
41 @echo "Running linter..."
42 @golangci-lint run ./...
43
44mocks: ## Generate mocks using mockery
45 @echo "Generating mocks..."
46 @mockery
47 @echo "Mocks generated successfully"
48
49check: lint test ## Run lint and tests
50
51##@ Testing
52
53test: ## Run all tests
54 @echo "Running tests..."
55 @go test ./...
56
57test-v: ## Run all tests with verbose output
58 @go test -v ./...
59
60test-short: ## Run tests (skip long-running tests)
61 @go test -short ./...
62
63test-race: ## Run tests with race detector
64 @echo "Running tests with race detector..."
65 @go test -race ./...
66
67test-coverage: ## Run tests with coverage report
68 @echo "Running tests with coverage..."
69 @go test -coverprofile=coverage.out ./...
70 @go tool cover -func=coverage.out
71 @go tool cover -html=coverage.out -o coverage.html
72 @echo "Coverage report generated: coverage.html"
73
74test-usecase: ## Run usecase layer tests only
75 @go test -v ./internal/usecase/...
76
77test-adapter: ## Run adapter layer tests only
78 @go test -v ./internal/adapters/...
79
80##@ Build
81
82build: ## Build binaries for linux (amd64 and arm64)
83 @echo "Building Go binaries..."
84 @mkdir -p $(DIST_DIR)
85 @rm -f $(DIST_DIR)/*
86 @echo "Building with version $(VERSION), commit $(COMMIT), date $(BUILD_DATE)"
87 @CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-amd64 ./main.go
88 @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-arm64 ./main.go
89 @echo "Go binaries built successfully"
90
91build-local: ## Build binary for current platform
92 @echo "Building for current platform..."
93 @go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon ./main.go
94 @echo "Binary built: $(DIST_DIR)/gordon"
95
96##@ Release
97
98build-push: build ## Build and push Docker images
99 @echo "Cleaning up dangling images..."
100 @$(ENGINE) image prune -f
101
102 @echo "Building and pushing Docker images..."
103 @for arch in $(ARCHS); do \
104 cp $(DIST_DIR)/gordon-linux-$$arch gordon; \
105 $(ENGINE) build -t $(REPO):$(TAG)-$$arch .; \
106 rm gordon; \
107 $(ENGINE) push $(REPO):$(TAG)-$$arch; \
108 done
109
110 @echo "Removing existing manifest..."
111 @$(ENGINE) manifest rm $(REPO):$(TAG) || true
112
113 @echo "Creating multi-arch manifest..."
114 @$(ENGINE) manifest create $(REPO):$(TAG) \
115 $(REPO):$(TAG)-amd64 \
116 $(REPO):$(TAG)-arm64
117
118 @echo "Annotating arm64 image..."
119 @$(ENGINE) manifest annotate $(REPO):$(TAG) \
120 $(REPO):$(TAG)-arm64 --arch arm64 --variant v8
121
122 @echo "Inspecting manifest..."
123 @$(ENGINE) manifest inspect $(REPO):$(TAG)
124
125 @echo "Pushing multi-arch manifest..."
126 @$(ENGINE) manifest push --all $(REPO):$(TAG)
127
128 @echo "Script completed successfully."
129
130dev-release: build ## Create dev GitHub release
131 @echo "Creating dev GitHub release..."
132 @if [ -z "$(shell which gh)" ]; then \
133 echo "Error: GitHub CLI (gh) is not installed. Please install it first."; \
134 exit 1; \
135 fi
136 @echo "Creating dev release $(DEV_TAG)..."
137 @gh release create $(DEV_TAG) \
138 --title "Gordon Dev Build $(DEV_TAG)" \
139 --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." \
140 --prerelease \
141 --draft=false \
142 $(DIST_DIR)/gordon-linux-amd64 \
143 $(DIST_DIR)/gordon-linux-arm64
144 @echo "Dev release created successfully!"
145 @echo ""
146 @echo "📦 Download URLs:"
147 @echo " AMD64: wget https://github.com/bnema/gordon/releases/download/$(DEV_TAG)/gordon-linux-amd64"
148 @echo " ARM64: wget https://github.com/bnema/gordon/releases/download/$(DEV_TAG)/gordon-linux-arm64"
149 @echo ""
150 @echo "🔗 Release page: https://github.com/bnema/gordon/releases/tag/$(DEV_TAG)"
151
152##@ Cleanup
153
154clean: ## Clean build artifacts
155 @echo "Cleaning up..."
156 @rm -rf $(DIST_DIR)
157 @echo "Cleanup completed."
158
159clean-all: clean clean-test ## Clean all artifacts including test files
160 @$(ENGINE) system prune -f
161
162clean-test: ## Clean test artifacts
163 @rm -f coverage.out coverage.html