forked from steipete/gogcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (74 loc) · 2.35 KB
/
Makefile
File metadata and controls
94 lines (74 loc) · 2.35 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
SHELL := /bin/bash
# `make` should build the binary by default.
.DEFAULT_GOAL := build
.PHONY: build gog gogcli gog-help gogcli-help help fmt fmt-check lint test ci tools
.PHONY: worker-ci
BIN_DIR := $(CURDIR)/bin
BIN := $(BIN_DIR)/gog
CMD := ./cmd/gog
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT := $(shell git rev-parse --short=12 HEAD 2>/dev/null || echo "")
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -X github.com/steipete/gogcli/internal/cmd.version=$(VERSION) -X github.com/steipete/gogcli/internal/cmd.commit=$(COMMIT) -X github.com/steipete/gogcli/internal/cmd.date=$(DATE)
TOOLS_DIR := $(CURDIR)/.tools
GOFUMPT := $(TOOLS_DIR)/gofumpt
GOIMPORTS := $(TOOLS_DIR)/goimports
GOLANGCI_LINT := $(TOOLS_DIR)/golangci-lint
# Allow passing CLI args as extra "targets":
# make gogcli -- --help
# make gogcli -- gmail --help
ifneq ($(filter gogcli gog,$(MAKECMDGOALS)),)
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)
endif
build:
@mkdir -p $(BIN_DIR)
@go build -ldflags "$(LDFLAGS)" -o $(BIN) $(CMD)
gog: build
@if [ -n "$(RUN_ARGS)" ]; then \
$(BIN) $(RUN_ARGS); \
elif [ -z "$(ARGS)" ]; then \
$(BIN) --help; \
else \
$(BIN) $(ARGS); \
fi
gogcli: build
@if [ -n "$(RUN_ARGS)" ]; then \
$(BIN) $(RUN_ARGS); \
elif [ -z "$(ARGS)" ]; then \
$(BIN) --help; \
else \
$(BIN) $(ARGS); \
fi
gog-help: build
@$(BIN) --help
gogcli-help: build
@$(BIN) --help
help: gog-help
tools:
@mkdir -p $(TOOLS_DIR)
@GOBIN=$(TOOLS_DIR) go install mvdan.cc/gofumpt@v0.9.2
@GOBIN=$(TOOLS_DIR) go install golang.org/x/tools/cmd/goimports@v0.41.0
@GOBIN=$(TOOLS_DIR) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0
fmt: tools
@$(GOIMPORTS) -local github.com/steipete/gogcli -w .
@$(GOFUMPT) -w .
fmt-check: tools
@$(GOIMPORTS) -local github.com/steipete/gogcli -w .
@$(GOFUMPT) -w .
@git diff --exit-code -- '*.go' go.mod go.sum
lint: tools
@$(GOLANGCI_LINT) run
pnpm-gate:
@if [ -f package.json ] || [ -f package.json5 ] || [ -f package.yaml ]; then \
pnpm lint && pnpm build && pnpm test; \
else \
echo "pnpm gate skipped (no package.json)"; \
fi
test:
@go test ./...
ci: pnpm-gate fmt-check lint test
worker-ci:
@pnpm -C internal/tracking/worker lint
@pnpm -C internal/tracking/worker build
@pnpm -C internal/tracking/worker test