-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (179 loc) · 6.01 KB
/
Makefile
File metadata and controls
208 lines (179 loc) · 6.01 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
GOPATH?=$(HOME)/go
FIRST_GOPATH:=$(firstword $(subst :, ,$(GOPATH)))
# Build available information.
GIT_HASH:=$(shell git log --format="%h" -n 1 2> /dev/null)
GIT_BRANCH:=$(shell git rev-parse --abbrev-ref HEAD)
APP_VERSION:="$(GIT_BRANCH)-$(GIT_HASH)"
GOPKG:=github.com/launchrctl/launchr
DEBUG?=0
ifeq ($(DEBUG), 1)
LDFLAGS_EXTRA=
BUILD_OPTS=-gcflags "all=-N -l"
else
LDFLAGS_EXTRA=-s -w
BUILD_OPTS=-trimpath
endif
BUILD_ENVPARMS:=CGO_ENABLED=0
GOBIN:=$(FIRST_GOPATH)/bin
LOCAL_BIN:=$(CURDIR)/bin
# Linter config.
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
GOLANGCI_TAG:=2.5.0
GOTESTFMT_BIN:=$(GOBIN)/gotestfmt
# Color definitions
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[0;33m
BLUE=\033[0;34m
MAGENTA=\033[0;35m
CYAN=\033[0;36m
WHITE=\033[0;37m
BOLD=\033[1m
RESET=\033[0m
# Disable colors on Windows.
ifeq ($(OS),Windows_NT)
RED=
GREEN=
YELLOW=
BLUE=
MAGENTA=
CYAN=
WHITE=
BOLD=
RESET=
endif
# Print functions
define print_header
@echo "$(BOLD)$(CYAN)╔═════════════════════════════════════════════════════════════╗$(RESET)"
@echo "$(BOLD)$(CYAN)║ LAUNCHR ║$(RESET)"
@echo "$(BOLD)$(CYAN)╚═════════════════════════════════════════════════════════════╝$(RESET)"
endef
define print_success
@echo "$(BOLD)$(GREEN)✅ $(1)$(RESET)"
@echo
endef
define print_info
@echo "$(BOLD)$(BLUE)📋 $(1)$(RESET)"
@echo
endef
define print_warning
@echo "$(BOLD)$(YELLOW)⚠️ $(1)$(RESET)"
@echo
endef
define print_error
@echo "$(BOLD)$(RED)❌ $(1)$(RESET)"
@echo
endef
define print_step
@echo "$(BOLD)$(MAGENTA)🔧 $(1)$(RESET)"
endef
.PHONY: all
all: banner deps test-short build
$(call print_success,"🎉 All tasks completed successfully!")
.PHONY: banner
banner:
$(call print_header)
@echo "$(BOLD)$(WHITE)📦 Version: $(APP_VERSION)$(RESET)"
@echo "$(BOLD)$(WHITE)🌿 Branch: $(GIT_BRANCH)$(RESET)"
@echo "$(BOLD)$(WHITE)🔗 Hash: $(GIT_HASH)$(RESET)"
@echo
# Install go dependencies
.PHONY: deps
deps:
$(call print_step,"Installing go dependencies...")
@go mod download
$(call print_success,"Dependencies installed successfully!")
# Run all tests
.PHONY: test
test: .install-gotestfmt
$(call print_step,"Running all tests...")
@go test -json -v ./... | $(GOTESTFMT_BIN) -hide all && \
echo "$(BOLD)$(GREEN)🧪 ✅ All tests passed$(RESET)" || \
echo "$(BOLD)$(RED)🧪 ❌ Some tests failed$(RESET)"
@echo
# Run short tests
.PHONY: test-short
test-short: .install-gotestfmt
$(call print_step,"Running short tests...")
@go test -json -short -v ./... | $(GOTESTFMT_BIN) -hide all && \
echo "$(BOLD)$(GREEN)🧪 ✅ All short tests passed$(RESET)" || \
echo "$(BOLD)$(RED)🧪 ❌ Some short tests failed$(RESET)"
@echo
# Build launchr
.PHONY: build
build:
$(call print_step,"Building launchr...")
# Application related information available on build time.
$(eval LDFLAGS:=-X '$(GOPKG).name=launchr' -X '$(GOPKG).version=$(APP_VERSION)' $(LDFLAGS_EXTRA))
$(eval BIN?=$(LOCAL_BIN)/launchr)
@go generate ./...
@$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
$(call print_success,"🔨 Build completed: $(BIN)")
# Install launchr
.PHONY: install
install: all
$(call print_step,"Installing launchr to GOPATH...")
@cp $(LOCAL_BIN)/launchr $(GOBIN)/launchr
$(call print_success,"🚀 launchr installed to $(GOBIN)/launchr")
# Install and run linters
.PHONY: lint
lint: .install-lint .lint-fix
# Install golangci-lint binary
.PHONY: .install-lint
.install-lint:
ifeq ($(wildcard $(GOLANGCI_BIN)),)
$(call print_step,"Installing golangci-lint v$(GOLANGCI_TAG)...")
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
$(call print_success,"golangci-lint installed!")
endif
# Install gotestfmt binary
.PHONY: .install-gotestfmt
.install-gotestfmt:
ifeq ($(wildcard $(GOTESTFMT_BIN)),)
$(call print_step,"Installing gotestfmt...")
@go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
$(call print_success,"gotestfmt installed!")
endif
# Runs linters
.PHONY: .lint-fix
.lint-fix:
$(call print_step,"Running linters with auto-fix...")
@$(GOLANGCI_BIN) run --fix ./... && \
echo "$(BOLD)$(GREEN)🔍 ✅ All linting checks passed$(RESET)" || \
echo "$(BOLD)$(YELLOW)🔍 ⚠️ Some linting issues found - please review$(RESET)"
@echo
.PHONY: .lint
.lint:
$(call print_step,"Running linters...")
@$(GOLANGCI_BIN) run && \
echo "$(BOLD)$(GREEN)🔍 ✅ All linting checks passed$(RESET)" || \
echo "$(BOLD)$(YELLOW)🔍 ⚠️ Some linting issues found - please review$(RESET)"
@echo
# Clean build artifacts
.PHONY: clean
clean:
$(call print_step,"Cleaning build artifacts...")
@rm -rf $(LOCAL_BIN)
$(call print_success,"🧹 Cleanup completed!")
# Show help
.PHONY: help
help:
$(call print_header)
@echo "$(BOLD)$(WHITE)Available targets:$(RESET)"
@echo ""
@echo " $(BOLD)$(GREEN)all$(RESET) 🎯 Run deps, test, and build"
@echo " $(BOLD)$(GREEN)deps$(RESET) 📦 Install go dependencies"
@echo " $(BOLD)$(GREEN)test$(RESET) 🧪 Run all tests"
@echo " $(BOLD)$(GREEN)test-short$(RESET) ⚡ Run short tests only"
@echo " $(BOLD)$(GREEN)build$(RESET) 🔨 Build launchr binary"
@echo " $(BOLD)$(GREEN)install$(RESET) 🚀 Install launchr to GOPATH"
@echo " $(BOLD)$(GREEN)lint$(RESET) 🔍 Run linters with auto-fix"
@echo " $(BOLD)$(GREEN)clean$(RESET) 🧹 Clean build artifacts"
@echo " $(BOLD)$(GREEN)help$(RESET) ❓ Show this help message"
@echo ""
@echo "$(BOLD)$(CYAN)Environment variables:$(RESET)"
@echo " $(BOLD)$(YELLOW)DEBUG=1$(RESET) Enable debug build"
@echo " $(BOLD)$(YELLOW)BIN=path$(RESET) Custom binary output path"
@echo ""
# Default target shows help
.DEFAULT_GOAL := help