11GOPATH? =$(HOME ) /go
22FIRST_GOPATH: =$(firstword $(subst :, ,$(GOPATH ) ) )
33
4- NODE_TAG =22 # Always use LTS
5- SWAGGER_UI_DIR:=./swagger-ui
6-
74# Build available information.
85GIT_HASH: =$(shell git log --format="% h" -n 1 2> /dev/null)
96GIT_BRANCH: =$(shell git rev-parse --abbrev-ref HEAD)
@@ -26,83 +23,186 @@ LOCAL_BIN:=$(CURDIR)/bin
2623
2724# Linter config.
2825GOLANGCI_BIN: =$(LOCAL_BIN ) /golangci-lint
29- 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
3084
3185.PHONY : all
32- all : deps front 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
3396
3497# Install go dependencies
3598.PHONY : deps
3699deps :
37- $(info Installing go dependencies...)
38- go mod download
39-
40- # Build front dependencies.
41- .PHONY : front
42- front : front-install front-build
43- @if [ ! -d " $( SWAGGER_UI_DIR) " ]; then \
44- echo " Downloading Swagger UI..." ; \
45- curl -Ss https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | grep tarball_url | cut -d ' "' -f 4 | \
46- xargs curl -LsS -o swagger-ui.tar.gz; \
47- rm -rf $(SWAGGER_UI_DIR) $(SWAGGER_UI_DIR)-tmp && mkdir $(SWAGGER_UI_DIR)-tmp; \
48- tar xzf swagger-ui.tar.gz -C $(SWAGGER_UI_DIR)-tmp --strip=1; \
49- mv $(SWAGGER_UI_DIR)-tmp/dist $(SWAGGER_UI_DIR); \
50- rm -rf $(SWAGGER_UI_DIR)-tmp && rm swagger-ui.tar.gz; \
51- sed -i.bkp "s|https://petstore.swagger.io/v2/swagger.json|/api/swagger.json|g" $(SWAGGER_UI_DIR)/swagger-initializer.js; \
52- fi
100+ $(call print_step,"Installing go dependencies...")
101+ @go mod download
102+ $(call print_success,"Dependencies installed successfully!")
53103
54104# Run all tests
55105.PHONY : test
56- test :
57- $(info Running tests...)
58- go test ./...
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
59121
60122# Build launchr
61123.PHONY : build
62124build :
63- $(info Building launchr...)
125+ $(call print_step," Building launchr..." )
64126# Application related information available on build time.
65127 $(eval LDFLAGS:=-X '$(GOPKG).name=launchr' -X '$(GOPKG).version=$(APP_VERSION)' $(LDFLAGS_EXTRA))
66128 $(eval BIN?=$(LOCAL_BIN)/launchr)
67- go generate ./...
68- $(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)")
69132
70133# Install launchr
71134.PHONY : install
72135install : all
73- install :
74- $( info Installing launchr to GOPATH...)
75- 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")
76139
77140# Install and run linters
78141.PHONY : lint
79- lint : .install-lint .lint
142+ lint : .install-lint .lint-fix
80143
81144# Install golangci-lint binary
82145.PHONY : .install-lint
83146.install-lint :
84147ifeq ($(wildcard $(GOLANGCI_BIN ) ) ,)
85- 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!")
86160endif
87161
88162# 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+
89171.PHONY : .lint
90172.lint :
91- $(info Running lint...)
92- $(GOLANGCI_BIN ) run --fix ./...
93-
94- # Front tasks.
95- front-install :
96- docker run --rm -it -v $(PWD ) /client:/usr/src/app -w /usr/src/app node:$(NODE_TAG ) sh -c " corepack install && corepack enable && yarn install"
97-
98- front-build :
99- docker run --rm -it -v $(PWD ) /client:/usr/src/app -w /usr/src/app node:$(NODE_TAG ) sh -c " corepack install && corepack enable && yarn build"
100-
101- front-dev :
102- docker run --rm -it -v $(PWD ) /client:/usr/src/app -p 5173:5173 -w /usr/src/app node:$(NODE_TAG ) sh -c " corepack install && corepack enable && yarn dev -- --host"
103-
104- front-lint-fix :
105- docker run --rm -it -v $(PWD ) /client:/usr/src/app -w /usr/src/app node:$(NODE_TAG ) sh -c " corepack install && corepack enable && yarn lint --fix"
106-
107- dev :
108- DEV=1 make build && LAUNCHR_ACTIONS_PATH=example ./bin/launchr web --foreground -vvvv
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