Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (69 loc) · 2.68 KB
/
Copy pathMakefile
File metadata and controls
85 lines (69 loc) · 2.68 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
LINTER = golangci-lint run -v $(LINTER_FLAGS) --timeout $(LINTER_DEADLINE)
LINTER_DEADLINE = 30s
LINTER_FLAGS ?=
ifneq (,$(wildcard /etc/alpine-release))
LINTER_FLAGS += --build-tags=musl
endif
PROTO_DIR=./pkg/protocol/protobuf
PROTO_FILES=$(wildcard $(PROTO_DIR)/*.proto)
# Pinned protoc toolchain. The protoc and protoc-gen-go versions (and the
# protoc archive checksums) are pinned in Dockerfile.protoc, which is the
# single source of truth. Expect a diff in the regenerated *.pb.go files
# when bumping them.
PROTOC_IMAGE=vehicle-command-protoc
PROTOC_DOCKERFILE=Dockerfile.protoc
all: build
linters:
@echo "** Running linters...**"
$(LINTER)
@echo "** SUCCESS **"
set-version:
if TAG=$$(git describe --tags --abbrev=0); then echo "$${TAG}" | sed 's/v//' > pkg/account/version.txt; fi
format: set-version
go fmt ./...
test: install
go test -cover ./...
go vet ./...
build: set-version test
go build ./...
install:
go install ./cmd/...
doc-images:
docker run -v ./:/data plantuml/plantuml "doc"
proto-gen: $(PROTO_FILES)
protoc --proto_path $(PROTO_DIR) --go_out $(PROTO_DIR) --go_opt=module=github.com/teslamotors/vehicle-command/pkg/protocol/protobuf ${PROTO_FILES}
# Build the pinned protoc toolchain image. Cached layers make this fast
# when Dockerfile.protoc has not changed.
proto-builder:
docker build \
-f $(PROTOC_DOCKERFILE) \
-t $(PROTOC_IMAGE) \
.
# Regenerate *.pb.go using the pinned toolchain. Use this instead of
# `proto-gen` to get reproducible output independent of the host's
# installed protoc version.
proto-gen-docker: proto-builder
docker run --rm \
--user "$$(id -u):$$(id -g)" \
-v "$(CURDIR):/workspace" \
-w /workspace \
$(PROTOC_IMAGE) \
--proto_path $(PROTO_DIR) \
--go_out $(PROTO_DIR) \
--go_opt=module=github.com/teslamotors/vehicle-command/pkg/protocol/protobuf \
$(PROTO_FILES)
# Regenerate via Docker and fail if the result differs from what is
# committed, or if regeneration produced files that are not tracked (a new
# .proto whose .pb.go was never committed). Intended for CI to catch
# out-of-date or missing *.pb.go files.
proto-check: proto-gen-docker
@if ! git diff --quiet -- $(PROTO_DIR) || \
[ -n "$$(git ls-files --others --exclude-standard -- $(PROTO_DIR))" ]; then \
echo "ERROR: generated protobuf files are out of date or missing."; \
echo "Run 'make proto-gen-docker' and commit the result."; \
git --no-pager status --short -- $(PROTO_DIR); \
git --no-pager diff -- $(PROTO_DIR); \
exit 1; \
fi
@echo "Generated protobuf files are up to date."
.PHONY: install build linters test format set-version doc-images proto-gen proto-builder proto-gen-docker proto-check