forked from mem9-ai/drive9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (132 loc) · 5.63 KB
/
Copy pathMakefile
File metadata and controls
159 lines (132 loc) · 5.63 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
SHELL := /bin/bash
GO ?= go
DOCKER ?= docker
HOST_GOOS ?= $(shell $(GO) env GOOS)
HOST_GOARCH ?= $(shell $(GO) env GOARCH)
# Build target defaults to the local environment; callers can override.
GOOS ?= $(HOST_GOOS)
GOARCH ?= $(HOST_GOARCH)
APP_NAME ?= drive9-server
CLI_NAME ?= drive9
LOCAL_SERVER_NAME ?= drive9-server-local
BIN_DIR ?= bin
# Use an absolute GOBIN for tool installation; `go install` is more predictable
# with an absolute path than a repo-relative bin dir.
BIN_DIR_ABS := $(abspath $(BIN_DIR))
DIST_DIR ?= dist
SERVER_BIN ?= $(BIN_DIR)/$(APP_NAME)
CLI_BIN ?= $(BIN_DIR)/$(CLI_NAME)
LOCAL_SERVER_BIN ?= $(BIN_DIR)/$(LOCAL_SERVER_NAME)
VERSION ?=
GIT_HASH ?= $(shell git rev-parse HEAD 2>/dev/null || echo unknown)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
CLI_TARGETS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64
GOLANGCI_LINT_VERSION ?= v2.5.0
GOLANGCI_LINT_BIN ?= $(BIN_DIR)/golangci-lint
IMAGE_REPO ?= drive9-server
IMAGE_TAG ?= latest
IMAGE ?= $(IMAGE_REPO):$(IMAGE_TAG)
LINT_TIMEOUT ?= 10m
TEST_TIMEOUT ?= 10m
TEST_P ?=
TEST_RUN ?=
TEST_PKGS ?= ./...
BUILDINFO_LDFLAGS = -X github.com/mem9-ai/drive9/pkg/buildinfo.Version=$(if $(VERSION),$(VERSION),dev) \
-X github.com/mem9-ai/drive9/pkg/buildinfo.GitHash=$(GIT_HASH) \
-X github.com/mem9-ai/drive9/pkg/buildinfo.GitBranch=$(GIT_BRANCH) \
-X github.com/mem9-ai/drive9/pkg/buildinfo.BuildTime=$(BUILD_TIME)
.PHONY: mod test test-failpoint test-podman fmt lint install-lint build build-server build-server-local build-cli build-cli-release run-server-local e2e-local sdk-integration-tests docker-build
mod:
$(GO) mod tidy
$(GO) mod download
# Run tests. MySQL-backed suites reuse DRIVE9_TEST_MYSQL_DSN when provided. When
# it is unset and podman is available locally, automatically configure the
# podman-backed testcontainers environment before running go test.
# - TEST_P to pass `-p <value>` to `go test`
# - TEST_RUN to pass `-run <regex>` to `go test`
# - TEST_PKGS to choose the packages under test (defaults to `./...`).
test:
@set -euo pipefail; \
test_p_flag=""; \
test_run_flag=""; \
if [ -n "$(TEST_P)" ]; then \
test_p_flag="-p $(TEST_P)"; \
fi; \
if [ -n "$(TEST_RUN)" ]; then \
test_run_flag="-run $(TEST_RUN)"; \
fi; \
if [ -z "$${DRIVE9_TEST_MYSQL_DSN:-}" ] && command -v podman >/dev/null 2>&1; then \
if podman_env="$$(bash -lc 'source ./scripts/test-podman.sh && env | grep -E "^(DOCKER_HOST|TESTCONTAINERS_RYUK_DISABLED)="')"; then \
while IFS= read -r line; do \
export "$$line"; \
done <<< "$$podman_env"; \
else \
echo "make test: Podman testcontainers setup unavailable, falling back to default runtime" >&2; \
fi; \
fi; \
$(GO) test $$test_p_flag $$test_run_flag -v -timeout $(TEST_TIMEOUT) $(TEST_PKGS)
# Run only failpoint-tagged tests through repository-wide instrumentation.
# Do not run this concurrently with the normal test target because failpoint-ctl
# rewrites the source tree while the tests are running.
test-failpoint:
./scripts/run_failpoint_tests.py
fmt:
$(MAKE) install-lint
$(GOLANGCI_LINT_BIN) run --fix
lint:
$(MAKE) install-lint
$(GOLANGCI_LINT_BIN) run --timeout $(LINT_TIMEOUT)
install-lint:
@echo "Checking for golangci-lint..."
@if [ ! -x "$(GOLANGCI_LINT_BIN)" ]; then \
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION) to $(BIN_DIR)..."; \
mkdir -p "$(BIN_DIR)"; \
GOBIN="$(BIN_DIR_ABS)" $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION); \
else \
echo "golangci-lint already installed at $(GOLANGCI_LINT_BIN)"; \
fi
build: build-server build-cli
build-server:
mkdir -p $(BIN_DIR)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build -ldflags "$(BUILDINFO_LDFLAGS)" -o $(SERVER_BIN) ./cmd/drive9-server
build-server-local:
mkdir -p $(BIN_DIR)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build -ldflags "$(BUILDINFO_LDFLAGS)" -o $(LOCAL_SERVER_BIN) ./cmd/drive9-server-local
run-server-local: build-server-local
@source ./scripts/drive9-server-local-env.sh && "./$(LOCAL_SERVER_BIN)"
e2e-local:
bash e2e/local-smoke.sh
# Run the cross-SDK live-server integration suites for all drive9 SDKs
# (Go, TypeScript, Rust, Python, Kotlin, Swift). Boots a disposable Docker MySQL
# container, starts drive9-server-local, points each SDK at it via
# DRIVE9_SERVER/DRIVE9_API_KEY, runs every suite, and tears it all down.
# Pass extra args through to the runner via SDK_INTEGRATION_ARGS, e.g.:
# make sdk-integration-tests
# make sdk-integration-tests SDK_INTEGRATION_ARGS="--only go,ts"
# make sdk-integration-tests SDK_INTEGRATION_ARGS="--keep-server"
# (GNU make treats tokens after `--` as goals, so forward args through the
# SDK_INTEGRATION_ARGS variable rather than `make ... -- ...`.)
sdk-integration-tests:
bash scripts/sdk-integration-tests.sh $(SDK_INTEGRATION_ARGS)
build-cli:
mkdir -p $(BIN_DIR)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build -ldflags "$(BUILDINFO_LDFLAGS)" -o $(CLI_BIN) ./cmd/drive9
build-cli-release:
@set -euo pipefail; \
mkdir -p $(DIST_DIR); \
for target in $(CLI_TARGETS); do \
os="$${target%/*}"; \
arch="$${target#*/}"; \
ext=""; \
if [ "$$os" = "windows" ]; then \
ext=".exe"; \
fi; \
out="$(DIST_DIR)/$(CLI_NAME)-$${os}-$${arch}$$ext"; \
echo "Building $$(basename "$$out")..."; \
$(MAKE) --no-print-directory build-cli GOOS="$$os" GOARCH="$$arch" CLI_BIN="$$out" VERSION="$(VERSION)"; \
done; \
cd $(DIST_DIR) && sha256sum $(CLI_NAME)-* > checksums.txt && printf '%s\n' "$(VERSION)" > version
DOCKER_BUILD_ARGS ?=
docker-build: build-server
$(DOCKER) build $(DOCKER_BUILD_ARGS) -t $(IMAGE) .