-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (116 loc) · 7.54 KB
/
Copy pathMakefile
File metadata and controls
134 lines (116 loc) · 7.54 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
.PHONY: run build dev build-all build-linux build-darwin build-windows deps clean build-ui release checksums docker-builder docker-push
# ── Variables ──────────────────────────────────────────────────────────────────
APP_NAME := beamdrop
MODULE := github.com/ekilie/beamdrop
LATEST_TAG := $(shell git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -1)
NEXT_PATCH = $(shell echo $(LATEST_TAG) | awk -F. '{printf "%s.%s.%d", $$1, $$2, $$3+1}')
VERSION ?= $(if $(LATEST_TAG),$(NEXT_PATCH),v0.1.0)
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -s -w \
-X '$(MODULE)/config.VERSION=$(VERSION)' \
-X '$(MODULE)/config.Commit=$(COMMIT)' \
-X '$(MODULE)/config.BuildDate=$(BUILD_DATE)'
BUILD_DIR := ./build
CGO_ENABLED ?= 0
# ── Development ───────────────────────────────────────────────────────────────
run: build
./cmd/beam/beamdrop -p="tach"
build-ui:
cd ./static/frontend && bun install && bun run build
build: deps build-ui
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o ./cmd/beam/beamdrop ./cmd/beam
dev:
go run ./cmd/beam --dir="."
# ── Cross-platform builds (all) ──────────────────────────────────────────────
build-all: deps build-ui
@echo "==> Building for all platforms ($(VERSION))..."
mkdir -p $(BUILD_DIR)
# macOS Apple Silicon (M1/M2/M3/M4...)
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64 ./cmd/beam
# macOS Intel
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-darwin-amd64 ./cmd/beam
# Linux amd64
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64 ./cmd/beam
# Linux arm64
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-linux-arm64 ./cmd/beam
# Windows amd64
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-windows-amd64.exe ./cmd/beam
# Windows arm64
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-windows-arm64.exe ./cmd/beam
@echo "==> Packaging archives..."
cd $(BUILD_DIR) && cp $(APP_NAME)-darwin-arm64 $(APP_NAME) && tar czf $(APP_NAME)-darwin-arm64.tar.gz $(APP_NAME) && rm $(APP_NAME)
cd $(BUILD_DIR) && cp $(APP_NAME)-darwin-amd64 $(APP_NAME) && tar czf $(APP_NAME)-darwin-amd64.tar.gz $(APP_NAME) && rm $(APP_NAME)
cd $(BUILD_DIR) && cp $(APP_NAME)-linux-amd64 $(APP_NAME) && tar czf $(APP_NAME)-linux-amd64.tar.gz $(APP_NAME) && rm $(APP_NAME)
cd $(BUILD_DIR) && cp $(APP_NAME)-linux-arm64 $(APP_NAME) && tar czf $(APP_NAME)-linux-arm64.tar.gz $(APP_NAME) && rm $(APP_NAME)
cd $(BUILD_DIR) && cp $(APP_NAME)-windows-amd64.exe $(APP_NAME).exe && zip $(APP_NAME)-windows-amd64.zip $(APP_NAME).exe && rm $(APP_NAME).exe
cd $(BUILD_DIR) && cp $(APP_NAME)-windows-arm64.exe $(APP_NAME).exe && zip $(APP_NAME)-windows-arm64.zip $(APP_NAME).exe && rm $(APP_NAME).exe
@echo "==> Done! Binaries in $(BUILD_DIR)/"
# ── Individual platform builds ───────────────────────────────────────────────
build-darwin: deps build-ui
@echo "==> Building for macOS..."
mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64 ./cmd/beam
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-darwin-amd64 ./cmd/beam
cd $(BUILD_DIR) && cp $(APP_NAME)-darwin-arm64 $(APP_NAME) && tar czf $(APP_NAME)-darwin-arm64.tar.gz $(APP_NAME) && rm $(APP_NAME)
cd $(BUILD_DIR) && cp $(APP_NAME)-darwin-amd64 $(APP_NAME) && tar czf $(APP_NAME)-darwin-amd64.tar.gz $(APP_NAME) && rm $(APP_NAME)
build-linux: deps build-ui
@echo "==> Building for Linux..."
mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64 ./cmd/beam
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-linux-arm64 ./cmd/beam
cd $(BUILD_DIR) && cp $(APP_NAME)-linux-amd64 $(APP_NAME) && tar czf $(APP_NAME)-linux-amd64.tar.gz $(APP_NAME) && rm $(APP_NAME)
cd $(BUILD_DIR) && cp $(APP_NAME)-linux-arm64 $(APP_NAME) && tar czf $(APP_NAME)-linux-arm64.tar.gz $(APP_NAME) && rm $(APP_NAME)
build-windows: deps build-ui
@echo "==> Building for Windows..."
mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-windows-amd64.exe ./cmd/beam
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME)-windows-arm64.exe ./cmd/beam
cd $(BUILD_DIR) && cp $(APP_NAME)-windows-amd64.exe $(APP_NAME).exe && zip $(APP_NAME)-windows-amd64.zip $(APP_NAME).exe && rm $(APP_NAME).exe
cd $(BUILD_DIR) && cp $(APP_NAME)-windows-arm64.exe $(APP_NAME).exe && zip $(APP_NAME)-windows-arm64.zip $(APP_NAME).exe && rm $(APP_NAME).exe
# ── Docker Hub (requires docker buildx + docker login) ───────────────────────
docker-builder:
docker buildx create --use --name beamdrop-builder
docker-push:
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t ekilie/beamdrop:latest \
-t ekilie/beamdrop:$(VERSION) \
--push .
# ── SHA256 checksums ─────────────────────────────────────────────────────────
checksums:
@echo "==> Generating checksums..."
cd $(BUILD_DIR) && shasum -a 256 *.tar.gz *.zip > checksums.txt
@cat $(BUILD_DIR)/checksums.txt
# ── GitHub Release (requires gh CLI) ─────────────────────────────────────────
# Usage:
# make release # auto-bump patch version from latest tag (v0.2.1 → v0.2.2)
# make release VERSION=v0.3.0 # create a specific version release
# make release VERSION=v0.3.0 FORCE=1 # delete existing release first, then recreate
# Auto-detect next patch version if VERSION is not set
# (LATEST_TAG / NEXT_PATCH / VERSION are defined at the top of the Makefile)
release: clean build-all checksums
@echo "==> Tagging $(VERSION)..."
git tag -f $(VERSION)
git push origin $(VERSION) --force
ifdef FORCE
@echo "==> Deleting existing release $(VERSION) (FORCE=1)..."
-gh release delete $(VERSION) --yes --cleanup-tag 2>/dev/null || true
@sleep 2
endif
@echo "==> Creating GitHub release $(VERSION)..."
gh release create $(VERSION) \
--title "Beamdrop $(VERSION)" \
--generate-notes \
$(BUILD_DIR)/*.tar.gz \
$(BUILD_DIR)/*.zip \
$(BUILD_DIR)/checksums.txt
# ── Utilities ─────────────────────────────────────────────────────────────────
deps:
go mod tidy
clean:
rm -f ./cmd/beam/beamdrop
rm -rf $(BUILD_DIR)