-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
99 lines (78 loc) · 3.03 KB
/
Makefile
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
PROJECT_BASE_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
# prepend the project-local bin/ folder to $PATH so that we find build-time tools there
PATH := ${PROJECT_BASE_DIR}/bin:${PATH}
TEST_RACE ?= -race
TEST_OPTS ?=
.PHONY: all
all: protos bin
$(info TODO)
.PHONY: check
check: lint check-goreleaser-config test
.PHONY: protos
protos: install-tools install-buf
$(info Generating Go code from Protobuf definitions...)
@buf generate
@buf build -o perseusapi/perseusapi.protoset
.PHONY: test
test:
@go test ${TEST_OPTS} ${TEST_RACE} ./...
BUILD_TIME_TOOLS =\
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
connectrpc.com/connect/cmd/protoc-gen-connect-go
BUF_VERSION := v1.32.0
.PHONY: install-tools
install-tools: ensure-local-bin-dir
@GOBIN=${PROJECT_BASE_DIR}/bin go install ${BUILD_TIME_TOOLS}
.PHONY: install-buf
install-buf: ensure-local-bin-dir
@GOBIN=${PROJECT_BASE_DIR}/bin go install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION)
.PHONY: ensure-local-bin-dir
ensure-local-bin-dir:
@mkdir -p ${PROJECT_BASE_DIR}/bin/
.PHONY: bin
bin: ensure-local-bin-dir
@go build -o ${PROJECT_BASE_DIR}/bin/perseus -ldflags='-X main.BuildDate=$(shell date -u +'%FT%R:%S') -X main.BuildVersion=v0.0.0-localdev.$(shell whoami).$(shell date -u +'%Y%m%d%H%M%S')' .
.PHONY: install
install:
@go install -ldflags='-X main.BuildDate=$(shell date -u +'%FT%R:%S') -X main.BuildVersion=v0.0.0-localdev.$(shell whoami).$(shell date -u +'%Y%m%d%H%M%S')' .
.PHONY: lint
lint: lint-protos lint-go
.PHONY: lint-go
lint-go: check-golangci-lint-install
$(info Linting Go code ...)
@golangci-lint run ./...
.PHONY: lint-protos
lint-protos: install-buf
$(info Linting Protobuf files ...)
@buf lint ./perseusapi
.PHONY: check-goreleaser-config
check-goreleaser-config:
$(info Validating goreleaser config ...)
@goreleaser check
.PHONY: snapshot
snapshot: check-goreleaser-install
@goreleaser release --snapshot --rm-dist --skip-publish
.PHONY: update-changelog
update-changelog: check-git-cliff-install
ifeq ("${NEXT_VERSION}", "")
$(error Must specify the next version via $$NEXT_VERSION)
else
$(info Generating change log for ${NEXT_VERSION} ...)
@git cliff --unreleased --ignore-tags 'v\d+\.\d+\.\d+-.+' --tag ${NEXT_VERSION} --prepend CHANGELOG.md
endif
.PHONY: check-golangci-lint-install
check-golangci-lint-install:
ifeq ("$(shell command -v golangci-lint)", "")
$(error golangci-lint was not found. Please install it using the method of your choice. (https://golangci-lint.run/usage/install/#local-installation))
endif
.PHONY: check-goreleaser-install
check-goreleaser-install:
ifeq ("$(shell command -v goreleaser)", "")
$(error goreleaser was not found. Please install it using the method of your choice. (https://goreleaser.com/install))
endif
.PHONY: check-git-cliff-install
check-git-cliff-install:
ifeq ("$(shell command -v git-cliff)", "")
$(error git-cliff was not found. Please install it using the method of your choice. (https://git-cliff.org/docs/installation/))
endif