-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (60 loc) · 3.13 KB
/
Copy pathMakefile
File metadata and controls
76 lines (60 loc) · 3.13 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
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BASE_LDFLAGS = -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
LDFLAGS = -s -w $(BASE_LDFLAGS)
WIKI_ADDR ?= 127.0.0.1:8080
WIKI_DB ?= ccg.db
WIKI_REPO ?= .
WIKI_TOKEN ?=
HOST_GOOS := $(shell go env GOOS)
CONTAINER_ARCH ?= $(shell go env GOARCH)
.PHONY: build release build-debug build-json install vet test test-integration-helpers wiki-build wiki-db wiki-docs wiki-run wiki-run-indexed container-artifacts clean
build: release
release:
CGO_ENABLED=1 go build -tags "fts5" -ldflags '$(LDFLAGS)' -o ccg ./cmd/ccg/
CGO_ENABLED=1 go build -tags "fts5" -ldflags '$(LDFLAGS)' -o ccg-server ./cmd/ccg-server/
build-debug:
CGO_ENABLED=1 go build -tags "fts5" -ldflags '$(BASE_LDFLAGS)' -o ccg ./cmd/ccg/
CGO_ENABLED=1 go build -tags "fts5" -ldflags '$(BASE_LDFLAGS)' -o ccg-server ./cmd/ccg-server/
build-json:
CGO_ENABLED=1 go build -json -tags "fts5" ./... > build-results.json
install:
CGO_ENABLED=1 go install -tags "fts5" -ldflags '$(LDFLAGS)' ./cmd/ccg/ ./cmd/ccg-server/
vet:
go vet ./...
test: test-integration-helpers
CGO_ENABLED=1 go test -tags "fts5" ./...
bash ./scripts/integration-test-helpers_test.sh
test-integration-helpers:
bash ./scripts/integration-test-helpers_test.sh
wiki-build:
cd web/wiki && npm ci && npm run build
container-artifacts: wiki-build
mkdir -p container-artifacts/$(CONTAINER_ARCH) container-artifacts/wiki
if [ "$(HOST_GOOS)" = "linux" ]; then \
$(MAKE) release; \
else \
docker run --rm --platform linux/$(CONTAINER_ARCH) \
--user "$$(id -u):$$(id -g)" \
-e GOCACHE=/tmp/go-build \
-e VERSION="$(VERSION)" \
-e COMMIT="$(COMMIT)" \
-e DATE="$(DATE)" \
-v "$$(pwd):/src" -w /src golang:1.25-bookworm \
sh -c 'CGO_ENABLED=1 go build -tags "fts5" -ldflags "-s -w -X main.version=$$VERSION -X main.commit=$$COMMIT -X main.date=$$DATE" -o ccg ./cmd/ccg/ && CGO_ENABLED=1 go build -tags "fts5" -ldflags "-s -w -X main.version=$$VERSION -X main.commit=$$COMMIT -X main.date=$$DATE" -o ccg-server ./cmd/ccg-server/'; \
fi
cp ccg container-artifacts/$(CONTAINER_ARCH)/ccg
cp ccg-server container-artifacts/$(CONTAINER_ARCH)/ccg-server
cp -R web/wiki/dist/. container-artifacts/wiki/
wiki-db:
CGO_ENABLED=1 go run -tags "fts5" ./cmd/ccg --db-driver sqlite --db-dsn '$(WIKI_DB)' migrate
CGO_ENABLED=1 go run -tags "fts5" ./cmd/ccg --db-driver sqlite --db-dsn '$(WIKI_DB)' build '$(WIKI_REPO)'
wiki-docs: wiki-db
CGO_ENABLED=1 go run -tags "fts5" ./cmd/ccg --db-driver sqlite --db-dsn '$(WIKI_DB)' docs --out docs
wiki-run: wiki-build wiki-db
CGO_ENABLED=1 go run -tags "fts5" ./cmd/ccg-server --db-driver sqlite --db-dsn '$(WIKI_DB)' --http-addr '$(WIKI_ADDR)' --http-bearer-token '$(WIKI_TOKEN)' --wiki-dir web/wiki/dist
wiki-run-indexed: wiki-build wiki-docs
CGO_ENABLED=1 go run -tags "fts5" ./cmd/ccg-server --db-driver sqlite --db-dsn '$(WIKI_DB)' --http-addr '$(WIKI_ADDR)' --http-bearer-token '$(WIKI_TOKEN)' --wiki-dir web/wiki/dist
clean:
rm -f ccg ccg-server