-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
58 lines (52 loc) · 1.86 KB
/
Makefile
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
# ⚙️ Variables
APP_NAME := angel
MAIN_FILE := cmd/angel/main.go
BUILD_DIR := bin
# Detect OS type for sed compatibility (Linux or macOS)
ifeq ($(shell uname), Darwin)
SED_INPLACE = -i ''
else
SED_INPLACE = -i
endif
# 🏗️ Build the project
build:
@echo "🔨 Building..."
@mkdir -p $(BUILD_DIR)
go build -ldflags '-s -w' -o $(BUILD_DIR)/$(APP_NAME) $(MAIN_FILE)
@echo "✅ Build completed: $(BUILD_DIR)/$(APP_NAME)"
# 🚀 Run the project
run: build
@echo "🏃 Running..."
./$(BUILD_DIR)/$(APP_NAME)
# 🧹 Clean build artifacts
clean:
@echo "🧹 Cleaning build files..."
rm -rf $(BUILD_DIR)
@echo "✅ Clean completed!"
# 🏷️ Tag version, update main.go, and push to GitHub (tag should be in vX.X.X format with integers >= 0)
tag:
@if [ -z "$(TAG)" ]; then \
echo "❗ Usage: make tag TAG=vX.X.X"; \
exit 1; \
fi
@if ! echo "$(strip $(TAG))" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$'; then \
echo "❌ Invalid tag format! Use vX.X.X format (e.g., v1.0.0, v0.2.3, v2.1.5)"; \
exit 1; \
fi
@echo "🔄 Updating version in $(MAIN_FILE) to: $(TAG)"
@sed $(SED_INPLACE) "s/^\(var version = \)\".*\"/\1\"$(TAG)\"/" $(MAIN_FILE)
git add $(MAIN_FILE)
git commit -m "🔖 Version update: $(TAG)"
git tag -a $(TAG) -m "🔖 Release $(TAG)"
@echo "⬆️ Pushing tag $(TAG) to GitHub..."
git push origin $(TAG)
@echo "⬆️ Pushing main branch to GitHub..."
git push origin main
@echo "✅ Tag $(TAG) and main branch updated on GitHub!"
# 🆘 Display help (default target)
help:
@echo "📘 Available commands:"
@echo " make build - Build the project"
@echo " make run - Build and run the project"
@echo " make clean - Remove build artifacts"
@echo " make tag TAG=vX.X.X - Update version in main.go, create an annotated Git tag (vX.X.X format, integers >= 0), and push to GitHub (also updates main branch)"