-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
86 lines (72 loc) · 2.82 KB
/
Copy pathMakefile
File metadata and controls
86 lines (72 loc) · 2.82 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
BINARY_NAME := worksome
MODULE := github.com/worksome/worksome-cli
SCHEMA := schema/schema.graphql
OVERRIDES := schema/overrides.yaml
GENERATED_DIR := internal/generated
PLATFORM_SCHEMA ?= $(HOME)/Projects/platform/_schema_dump.graphql
INTROSPECT_ENDPOINT ?= https://api.worksome.com/graphql
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
# Both binaries read these from internal/buildinfo, so one set of stamps covers
# every entrypoint. -X addresses the symbol by full import path and is silently
# dropped when that path is wrong, so keep it in step with the package.
BUILDINFO := $(MODULE)/internal/buildinfo
LDFLAGS := -ldflags "-X $(BUILDINFO).Version=$(VERSION) -X $(BUILDINFO).Commit=$(COMMIT)"
.PHONY: build test lint generate sync-schema sync clean verify-generated help
## build: Build the CLI binary
build:
go build $(LDFLAGS) -o $(BINARY_NAME) ./cmd/worksome/
## install: Install the CLI binary to $GOPATH/bin
install:
go install $(LDFLAGS) ./cmd/worksome/
## test: Run all unit tests
test:
go test ./internal/... -v -count=1
## test-short: Run tests without verbose output
test-short:
go test ./internal/... -count=1
## test-integration: Run integration tests (requires WORKSOME_API_TOKEN)
test-integration:
WORKSOME_INTEGRATION_TEST=1 go test ./test/integration/... -v -count=1
## lint: Run linter
lint:
golangci-lint run ./...
## generate: Generate Go code from GraphQL schema
generate:
go run ./cmd/generate/ -schema $(SCHEMA) -overrides $(OVERRIDES) -output $(GENERATED_DIR) -module $(MODULE)
## sync-schema: Sync the GraphQL schema
sync-schema:
ifeq ($(SYNC_MODE),platform)
@if [ -f "$(PLATFORM_SCHEMA)" ]; then \
echo "Syncing schema from platform repo..."; \
cp "$(PLATFORM_SCHEMA)" "$(SCHEMA)"; \
echo "Schema synced successfully."; \
else \
echo "Error: Platform schema not found at $(PLATFORM_SCHEMA)"; \
exit 1; \
fi
else
@echo "Syncing schema via introspection..."
@go run $(LDFLAGS) ./cmd/introspect/ --endpoint $(INTROSPECT_ENDPOINT) > $(SCHEMA).tmp || { rm -f $(SCHEMA).tmp; exit 1; }
@mv $(SCHEMA).tmp $(SCHEMA)
@echo "Schema synced successfully."
endif
## sync: Sync schema and regenerate code
sync: sync-schema generate
## verify-generated: Verify generated code is up to date
verify-generated: generate
@if git diff --quiet $(GENERATED_DIR) README.md; then \
echo "Generated code is up to date."; \
else \
echo "ERROR: Generated code is out of date. Run 'make generate' and commit."; \
git diff --stat $(GENERATED_DIR) README.md; \
exit 1; \
fi
## clean: Remove build artifacts
clean:
rm -f $(BINARY_NAME)
rm -f internal/generated/types/*.unformatted
rm -f internal/generated/commands/*.unformatted
## help: Show this help
help:
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## //' | column -t -s ':'