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 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 $(ENGINE) build --platform linux/$$arch \
105 --build-arg VERSION="$(VERSION)" \
106 --build-arg COMMIT="$(COMMIT)" \
107 --build-arg BUILD_DATE="$(BUILD_DATE)" \
108 -t $(REPO):$(TAG)-$$arch .; \
109 $(ENGINE) push $(REPO):$(TAG)-$$arch; \
110 done
111
112 @echo "Removing existing manifest..."
113 @$(ENGINE) manifest rm $(REPO):$(TAG) || true
114
115 @echo "Creating multi-arch manifest..."
116 @$(ENGINE) manifest create $(REPO):$(TAG) \
117 $(REPO):$(TAG)-amd64 \
118 $(REPO):$(TAG)-arm64
119
120 @echo "Annotating arm64 image..."
121 @$(ENGINE) manifest annotate $(REPO):$(TAG) \
122 $(REPO):$(TAG)-arm64 --arch arm64 --variant v8
123
124 @echo "Inspecting manifest..."
125 @$(ENGINE) manifest inspect $(REPO):$(TAG)
126
127 @echo "Pushing multi-arch manifest..."
128 @$(ENGINE) manifest push --all $(REPO):$(TAG)
129
130 @echo "Script completed successfully."
131
132dev-release: build ## Create dev GitHub release
133 @echo "Creating dev GitHub release..."
134 @if [ -z "$(shell which gh)" ]; then \
135 echo "Error: GitHub CLI (gh) is not installed. Please install it first."; \
136 exit 1; \
137 fi
138 @echo "Creating dev release $(DEV_TAG)..."
139 @gh release create $(DEV_TAG) \
140 --title "Gordon Dev Build $(DEV_TAG)" \
141 --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." \
142 --prerelease \
143 --draft=false \
144 $(DIST_DIR)/gordon-linux-amd64 \
145 $(DIST_DIR)/gordon-linux-arm64
146 @echo "Dev release created successfully!"
147 @echo ""
148 @echo "📦 Download URLs:"
149 @echo " AMD64: wget https://github.com/bnema/gordon/releases/download/$(DEV_TAG)/gordon-linux-amd64"
150 @echo " ARM64: wget https://github.com/bnema/gordon/releases/download/$(DEV_TAG)/gordon-linux-arm64"
151 @echo ""
152 @echo "🔗 Release page: https://github.com/bnema/gordon/releases/tag/$(DEV_TAG)"
153
154##@ Cleanup
155
156clean: ## Clean build artifacts
157 @echo "Cleaning up..."
158 @rm -rf $(DIST_DIR)
159 @echo "Cleanup completed."
160
161clean-all: clean clean-test ## Clean all artifacts including test files
162 @$(ENGINE) system prune -f
163
164clean-test: ## Clean test artifacts
165 @rm -f coverage.out coverage.html