-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (80 loc) · 2.89 KB
/
Makefile
File metadata and controls
93 lines (80 loc) · 2.89 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
BINARY_NAME=leafwiki
CMD_DIR=./cmd/leafwiki
VERSION ?= v0.1.0
RELEASE_DIR := releases
DOCKER_BUILDER := Dockerfile.builder
PLATFORMS := \
linux/amd64 \
linux/arm64 \
windows/amd64 \
darwin/amd64 \
darwin/arm64
all: build
build:
go build -o $(BINARY_NAME) $(CMD_DIR)
run:
go run $(CMD_DIR)
clean:
rm -f $(BINARY_NAME)
rm -rf $(RELEASE_DIR)
test:
go test ./...
# Build all platform targets
release: $(PLATFORMS)
@echo "✅ All builds complete."
# Build for each platform using Docker
$(PLATFORMS):
@mkdir -p $(RELEASE_DIR)
@GOOS=$(word 1,$(subst /, ,$@)) ; \
GOARCH=$(word 2,$(subst /, ,$@)) ; \
EXT=$$( [ "$$GOOS" = "windows" ] && echo ".exe" || echo "" ) ; \
OUTPUT=$(BINARY_NAME)-$(VERSION)-$$GOOS-$$GOARCH$$EXT ; \
echo "📦 Building $$OUTPUT..." ; \
docker build -f $(DOCKER_BUILDER) \
--build-arg GOOS=$$GOOS \
--build-arg GOARCH=$$GOARCH \
--build-arg OUTPUT=$(BINARY_NAME) \
-t leafwiki-builder-$$GOOS-$$GOARCH . ; \
ID=$$(docker create leafwiki-builder-$$GOOS-$$GOARCH) ; \
docker cp $$ID:/out/$(BINARY_NAME) $(RELEASE_DIR)/$$OUTPUT ; \
docker rm $$ID ; \
echo "✅ Binary done: $(RELEASE_DIR)/$$OUTPUT" ; \
sha256sum $(RELEASE_DIR)/$$OUTPUT > $(RELEASE_DIR)/$$OUTPUT.sha256 ; \
zip -j $(RELEASE_DIR)/$$OUTPUT.zip $(RELEASE_DIR)/$$OUTPUT ; \
tar -czf $(RELEASE_DIR)/$$OUTPUT.tar.gz -C $(RELEASE_DIR) $$OUTPUT ; \
echo "📦 Compressed: zip and tar.gz"
# Final production Docker image
docker-build-publish:
ifndef REPO_OWNER
$(error REPO_OWNER is not set. Usage: make docker-build-publish VERSION=vX.Y.Z REPO_OWNER=your_github_username)
endif
docker buildx build \
--platform linux/amd64,linux/arm64 \
--file Dockerfile \
--target final \
--tag ghcr.io/$(REPO_OWNER)/leafwiki:$(VERSION) \
--tag ghcr.io/$(REPO_OWNER)/leafwiki:latest \
--annotation "index:org.opencontainers.image.title=LeafWiki" \
--annotation "index:org.opencontainers.image.description=LeafWiki – A fast wiki for people who think in folders, not feeds" \
--push .
# Generate markdown changelog between two tags
changelog:
@if [ -z "$(PREVIOUS)" ] || [ -z "$(CURRENT)" ]; then \
echo "Usage: make changelog PREVIOUS=v0.1.0 CURRENT=v0.2.0"; \
exit 1; \
fi
@./scripts/changelog.sh $(PREVIOUS) $(CURRENT)
run-e2e:
@echo "🚀 Starting end-to-end tests..."
@./e2e/run.sh
help:
@echo "Available commands:"
@echo " make build – Build binary for current system"
@echo " make release – Cross-compile binaries for all platforms (via Docker)"
@echo " make clean – Clean all generated files"
@echo " make test – Run all Go tests"
@echo " make run-e2e – Run end-to-end tests (using Docker)"
@echo " make run – Run development server"
@echo " make docker-build-publish – Build and push multi-arch Docker image"
@echo " make changelog – Generate changelog"
.PHONY: all build run clean test fmt lint help docker-build-publish changelog run-e2e