@@ -3,8 +3,7 @@ FIRST_GOPATH:=$(firstword $(subst :, ,$(GOPATH)))
33
44# Build available information.
55GIT_HASH: =$(shell git log --format="% h" -n 1 2> /dev/null)
6- RAW_GIT_BRANCH := $(if $(GITHUB_REF_NAME ) ,$(GITHUB_REF_NAME ) ,$(shell git rev-parse --abbrev-ref HEAD) )
7- GIT_BRANCH = $(shell echo $(RAW_GIT_BRANCH ) | sed 's/[^a-zA-Z0-9-]//g')
6+ GIT_BRANCH: =$(shell git rev-parse --abbrev-ref HEAD)
87APP_VERSION: ="$(GIT_BRANCH ) -$(GIT_HASH ) "
98GOPKG: =github.com/launchrctl/launchr
109
@@ -24,62 +23,186 @@ LOCAL_BIN:=$(CURDIR)/bin
2423
2524# Linter config.
2625GOLANGCI_BIN: =$(LOCAL_BIN ) /golangci-lint
27- GOLANGCI_TAG: =1.64.5
26+ GOLANGCI_TAG: =2.5.0
27+
28+ GOTESTFMT_BIN: =$(GOBIN ) /gotestfmt
29+
30+ # Color definitions
31+ RED =\033[0;31m
32+ GREEN =\033[0;32m
33+ YELLOW =\033[0;33m
34+ BLUE =\033[0;34m
35+ MAGENTA =\033[0;35m
36+ CYAN =\033[0;36m
37+ WHITE =\033[0;37m
38+ BOLD =\033[1m
39+ RESET =\033[0m
40+
41+ # Disable colors on Windows.
42+ ifeq ($(OS ) ,Windows_NT)
43+ RED =
44+ GREEN =
45+ YELLOW =
46+ BLUE =
47+ MAGENTA =
48+ CYAN =
49+ WHITE =
50+ BOLD =
51+ RESET =
52+ endif
53+
54+ # Print functions
55+ define print_header
56+ @echo "$(BOLD )$(CYAN ) ╔═════════════════════════════════════════════════════════════╗$(RESET ) "
57+ @echo "$(BOLD )$(CYAN ) ║ LAUNCHR ║$(RESET ) "
58+ @echo "$(BOLD )$(CYAN ) ╚═════════════════════════════════════════════════════════════╝$(RESET ) "
59+ endef
60+
61+ define print_success
62+ @echo "$(BOLD )$(GREEN ) ✅ $(1 )$(RESET ) "
63+ @echo
64+ endef
65+
66+ define print_info
67+ @echo "$(BOLD )$(BLUE ) 📋 $(1 )$(RESET ) "
68+ @echo
69+ endef
70+
71+ define print_warning
72+ @echo "$(BOLD )$(YELLOW ) ⚠️ $(1 )$(RESET ) "
73+ @echo
74+ endef
75+
76+ define print_error
77+ @echo "$(BOLD )$(RED ) ❌ $(1 )$(RESET ) "
78+ @echo
79+ endef
80+
81+ define print_step
82+ @echo "$(BOLD )$(MAGENTA ) 🔧 $(1 )$(RESET ) "
83+ endef
2884
2985.PHONY : all
30- all : deps test build
86+ all : banner deps test-short build
87+ $(call print_success,"🎉 All tasks completed successfully!")
88+
89+ .PHONY : banner
90+ banner :
91+ $(call print_header)
92+ @echo " $( BOLD) $( WHITE) 📦 Version: $( APP_VERSION) $( RESET) "
93+ @echo " $( BOLD) $( WHITE) 🌿 Branch: $( GIT_BRANCH) $( RESET) "
94+ @echo " $( BOLD) $( WHITE) 🔗 Hash: $( GIT_HASH) $( RESET) "
95+ @echo
3196
3297# Install go dependencies
3398.PHONY : deps
3499deps :
35- $(info Installing go dependencies...)
36- go mod download
100+ $(call print_step,"Installing go dependencies...")
101+ @go mod download
102+ $(call print_success,"Dependencies installed successfully!")
37103
38104# Run all tests
39105.PHONY : test
40- test :
41- $(info Running tests...)
42- go test ./...
43-
44- # Echo vars for debbug
45- .PHONY : debugvars
46- debugvars :
47- $(shell echo "GITHUB_REF_NAME=${GITHUB_REF_NAME}")
48- $(shell echo "RAW_GIT_BRANCH=${SANITIZED_GIT_BRANCH}")
49- $(shell echo "GIT_BRANCH=$(GIT_BRANCH ) ")
50- $(shell echo "GIT_HASH=$(GIT_HASH ) ")
51- $(shell echo "APP_VERSION=$(APP_VERSION ) ")
106+ test : .install-gotestfmt
107+ $(call print_step,"Running all tests...")
108+ @go test -json -v ./... | $(GOTESTFMT_BIN ) -hide all && \
109+ echo " $( BOLD) $( GREEN) 🧪 ✅ All tests passed$( RESET) " || \
110+ echo " $( BOLD) $( RED) 🧪 ❌ Some tests failed$( RESET) "
111+ @echo
112+
113+ # Run short tests
114+ .PHONY : test-short
115+ test-short : .install-gotestfmt
116+ $(call print_step,"Running short tests...")
117+ @go test -json -short -v ./... | $(GOTESTFMT_BIN ) -hide all && \
118+ echo " $( BOLD) $( GREEN) 🧪 ✅ All short tests passed$( RESET) " || \
119+ echo " $( BOLD) $( RED) 🧪 ❌ Some short tests failed$( RESET) "
120+ @echo
52121
53122# Build launchr
54123.PHONY : build
55124build :
56- $(info Building launchr...)
125+ $(call print_step," Building launchr..." )
57126# Application related information available on build time.
58127 $(eval LDFLAGS:=-X '$(GOPKG).name=launchr' -X '$(GOPKG).version=$(APP_VERSION)' $(LDFLAGS_EXTRA))
59128 $(eval BIN?=$(LOCAL_BIN)/launchr)
60- go generate ./...
61- $(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
129+ @go generate ./...
130+ @$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
131+ $(call print_success,"🔨 Build completed: $(BIN)")
62132
63133# Install launchr
64134.PHONY : install
65135install : all
66- install :
67- $( info Installing launchr to GOPATH...)
68- cp $( LOCAL_BIN ) / launchr $(GOBIN ) /launchr
136+ $( call print_step,"Installing launchr to GOPATH...")
137+ @cp $( LOCAL_BIN ) / launchr $( GOBIN ) /launchr
138+ $( call print_success,"🚀 launchr installed to $(GOBIN ) /launchr")
69139
70140# Install and run linters
71141.PHONY : lint
72- lint : .install-lint .lint
142+ lint : .install-lint .lint-fix
73143
74144# Install golangci-lint binary
75145.PHONY : .install-lint
76146.install-lint :
77147ifeq ($(wildcard $(GOLANGCI_BIN ) ) ,)
78- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
148+ $(call print_step,"Installing golangci-lint v$(GOLANGCI_TAG)...")
149+ @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
150+ $(call print_success,"golangci-lint installed!")
151+ endif
152+
153+ # Install gotestfmt binary
154+ .PHONY : .install-gotestfmt
155+ .install-gotestfmt :
156+ ifeq ($(wildcard $(GOTESTFMT_BIN ) ) ,)
157+ $(call print_step,"Installing gotestfmt...")
158+ @go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
159+ $(call print_success,"gotestfmt installed!")
79160endif
80161
81162# Runs linters
163+ .PHONY : .lint-fix
164+ .lint-fix :
165+ $(call print_step,"Running linters with auto-fix...")
166+ @$(GOLANGCI_BIN ) run --fix ./... && \
167+ echo " $( BOLD) $( GREEN) 🔍 ✅ All linting checks passed$( RESET) " || \
168+ echo " $( BOLD) $( YELLOW) 🔍 ⚠️ Some linting issues found - please review$( RESET) "
169+ @echo
170+
82171.PHONY : .lint
83172.lint :
84- $(info Running lint...)
85- $(GOLANGCI_BIN ) run --fix ./...
173+ $(call print_step,"Running linters...")
174+ @$(GOLANGCI_BIN ) run && \
175+ echo " $( BOLD) $( GREEN) 🔍 ✅ All linting checks passed$( RESET) " || \
176+ echo " $( BOLD) $( YELLOW) 🔍 ⚠️ Some linting issues found - please review$( RESET) "
177+ @echo
178+
179+ # Clean build artifacts
180+ .PHONY : clean
181+ clean :
182+ $(call print_step,"Cleaning build artifacts...")
183+ @rm -rf $(LOCAL_BIN )
184+ $(call print_success,"🧹 Cleanup completed!")
185+
186+ # Show help
187+ .PHONY : help
188+ help :
189+ $(call print_header)
190+ @echo " $( BOLD) $( WHITE) Available targets:$( RESET) "
191+ @echo " "
192+ @echo " $( BOLD) $( GREEN) all$( RESET) 🎯 Run deps, test, and build"
193+ @echo " $( BOLD) $( GREEN) deps$( RESET) 📦 Install go dependencies"
194+ @echo " $( BOLD) $( GREEN) test$( RESET) 🧪 Run all tests"
195+ @echo " $( BOLD) $( GREEN) test-short$( RESET) ⚡ Run short tests only"
196+ @echo " $( BOLD) $( GREEN) build$( RESET) 🔨 Build launchr binary"
197+ @echo " $( BOLD) $( GREEN) install$( RESET) 🚀 Install launchr to GOPATH"
198+ @echo " $( BOLD) $( GREEN) lint$( RESET) 🔍 Run linters with auto-fix"
199+ @echo " $( BOLD) $( GREEN) clean$( RESET) 🧹 Clean build artifacts"
200+ @echo " $( BOLD) $( GREEN) help$( RESET) ❓ Show this help message"
201+ @echo " "
202+ @echo " $( BOLD) $( CYAN) Environment variables:$( RESET) "
203+ @echo " $( BOLD) $( YELLOW) DEBUG=1$( RESET) Enable debug build"
204+ @echo " $( BOLD) $( YELLOW) BIN=path$( RESET) Custom binary output path"
205+ @echo " "
206+
207+ # Default target shows help
208+ .DEFAULT_GOAL := help
0 commit comments