forked from perber/leafwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (103 loc) · 4.28 KB
/
Copy pathMakefile
File metadata and controls
120 lines (103 loc) · 4.28 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
BINARY_NAME=leafwiki
CMD_DIR=./cmd/leafwiki
VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null || printf '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 ./...
bench:
go test -bench=. -benchmem -benchtime=3s ./internal/links/... ./internal/core/revision/...
# 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 APP_VERSION=$(VERSION) \
--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 \
--build-arg APP_VERSION=$(VERSION) \
--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" \
--sbom=true \
--provenance=mode=max \
--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
run-proxy-e2e:
@echo "🔐 Starting proxy auth E2E tests..."
@./e2e-proxy/run.sh
run-e2e-local:
@echo "⚡ Starting end-to-end tests (local fast path)..."
@E2E_RUN_MODE=local ./e2e/run.sh
# Skip the Vite build when dist/ is already up to date; useful when iterating
# on tests without changing the frontend. Pass GREP=<pattern> to filter tests,
# e.g.: make run-e2e-local-fast GREP="shoutout"
run-e2e-local-fast:
@echo "⚡ Starting end-to-end tests (local, skip UI build)..."
@E2E_RUN_MODE=local E2E_SKIP_UI_BUILD=1 ./e2e/run.sh $(if $(GREP),--grep "$(GREP)",)
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 bench – Run Go benchmarks for links and revision"
@echo " make run-e2e – Run end-to-end tests (using Docker)"
@echo " make run-proxy-e2e – Run reverse-proxy auth E2E tests (Docker + nginx)"
@echo " make run-e2e-local – Run end-to-end tests via local fast path"
@echo " make run-e2e-local-fast – Run E2E tests locally, skip UI build (use when dist/ is current)"
@echo " Optional: GREP=<pattern> to filter tests"
@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 bench fmt lint help docker-build-publish changelog run-e2e run-e2e-local run-e2e-local-fast run-proxy-e2e