-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (124 loc) · 4.95 KB
/
Makefile
File metadata and controls
166 lines (124 loc) · 4.95 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
# Stackaroo Makefile
# Copyright © 2025 Stackaroo Contributors
# SPDX-License-Identifier: BSD-3-Clause
.PHONY: build test test-unit clean help run install lint fmt vet
# Variables
BINARY_NAME := stackaroo
BUILD_DIR := bin
CMD_DIR := ./cmd
INTERNAL_DIR := ./internal
# Version variables
BASE_VERSION := $(shell cat VERSION 2>/dev/null || echo "0.0.0")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
BUILD_DATE := $(shell date -u '+%Y-%m-%d %H:%M:%S UTC')
# Determine if we're on a clean release tag
GIT_TAG := $(shell git describe --exact-match --tags 2>/dev/null || echo "")
GIT_DIRTY := $(shell test -z "$$(git status --porcelain 2>/dev/null)" || echo "-dirty")
# Version logic:
# - If on exact tag matching VERSION file: use clean version (v1.0.0)
# - Otherwise: append git info (1.0.0+a1b2c3d or 1.0.0+a1b2c3d-dirty)
VERSION := $(if $(and $(GIT_TAG),$(filter v$(BASE_VERSION),$(GIT_TAG))),v$(BASE_VERSION),$(BASE_VERSION)+$(GIT_COMMIT)$(GIT_DIRTY))
# Build flags
LDFLAGS := -ldflags="-w -s \
-X 'codeberg.org/orien/stackaroo/internal/version.Version=$(VERSION)' \
-X 'codeberg.org/orien/stackaroo/internal/version.GitCommit=$(GIT_COMMIT)' \
-X 'codeberg.org/orien/stackaroo/internal/version.BuildDate=$(BUILD_DATE)'"
# Default target
help: ## Show this help message
@echo "Available targets:"
@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)
##@ Build
build: ## Build the main stackaroo binary
@echo "🔨 Building stackaroo $(VERSION)..."
@mkdir -p $(BUILD_DIR)
@go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "✅ Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build-all: build ## Build all binaries
##@ Test
test: test-unit ## Run all tests
test-unit: ## Run unit tests
@echo "🧪 Running unit tests..."
@go test -v ./cmd/... ./internal/...
##@ Development
run: build ## Build and run stackaroo
@echo "🚀 Running stackaroo..."
@$(BUILD_DIR)/$(BINARY_NAME)
install: ## Install stackaroo to GOPATH/bin
@echo "📦 Installing stackaroo..."
@go install .
@echo "✅ Installed to $(shell go env GOPATH)/bin/$(BINARY_NAME)"
fmt: ## Format Go code
@echo "🎨 Formatting code..."
@go fmt ./...
vet: ## Run go vet
@echo "🔍 Running go vet..."
@go vet ./...
golangci-lint: ## Run golangci-lint
@echo "🔍 Running golangci-lint..."
@golangci-lint run
install-golangci-lint: ## Install golangci-lint
@echo "📦 Installing golangci-lint..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@echo "✅ golangci-lint installed"
lint: fmt vet golangci-lint ## Run all linting tools
tidy: ## Tidy and verify module dependencies
@echo "🧹 Tidying module dependencies..."
@go mod tidy
@go mod verify
##@ Clean
clean: ## Clean build artifacts
@echo "🧹 Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@go clean
clean-all: clean ## Clean all artifacts including module cache
@echo "🧹 Cleaning all artifacts..."
@go clean -modcache
##@ Release
version: ## Show version information that would be embedded in binary
@echo "Stackaroo version information:"
@echo "Version: $(VERSION)"
@echo "Base version: $(BASE_VERSION)"
@echo "Git commit: $(GIT_COMMIT)"
@echo "Build date: $(BUILD_DATE)"
@echo "Git tag: $(GIT_TAG)"
@echo "Git dirty: $(GIT_DIRTY)"
@echo "Go version: $(shell go version)"
install-goreleaser: ## Install GoReleaser
@echo "📦 Installing GoReleaser..."
@go install github.com/goreleaser/goreleaser@latest
@echo "✅ GoReleaser installed"
goreleaser-check: ## Check GoReleaser configuration
@echo "🔍 Checking GoReleaser configuration..."
@goreleaser check
goreleaser-snapshot: clean ## Build snapshot release with GoReleaser (no git tag required)
@echo "📸 Building snapshot release with GoReleaser..."
@goreleaser release --snapshot --clean
@echo "✅ Snapshot release built in dist/"
@ls -la dist/
goreleaser-dry-run: ## Dry run GoReleaser release process
@echo "🧪 Running GoReleaser dry run..."
@goreleaser release --skip=publish --clean
@echo "✅ Dry run completed"
release-prepare: ## Prepare for release (run checks, validate config)
@echo "🚀 Preparing for release..."
@./scripts/release.sh --dry-run $(shell cat VERSION)
release: ## Create and push release tag (requires version argument: make release VERSION=1.2.3)
ifdef VERSION
@echo "🚀 Creating release $(VERSION)..."
@./scripts/release.sh $(VERSION)
else
@echo "❌ VERSION argument required. Usage: make release VERSION=1.2.3"
@exit 1
endif
##@ Git
git-check: ## Check git status and requirements
@echo "📋 Git status:"
@git status --porcelain
@echo "📋 Recent commits:"
@git --no-pager log --oneline -5
lint-fix: ## Run golangci-lint with auto-fix
@echo "🔧 Running golangci-lint with auto-fix..."
@golangci-lint run --fix
commit-check: lint test git-check ## Run pre-commit checks
@echo "✅ All checks passed!"
##@ Info