-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (36 loc) · 1.23 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
BINARY=tx-submit-api
# Determine root directory
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# Gather all .go files for use in dependencies below
GO_FILES=$(shell find $(ROOT_DIR) -name '*.go')
# Extract Go module name from go.mod
GOMODULE=$(shell grep ^module $(ROOT_DIR)/go.mod | awk '{ print $$2 }')
# Set version strings based on git tag and current ref
GO_LDFLAGS=-ldflags "-s -w -X '$(GOMODULE)/internal/version.Version=$(shell git describe --tags --exact-match 2>/dev/null)' -X '$(GOMODULE)/internal/version.CommitHash=$(shell git rev-parse --short HEAD)'"
# Alias for building program binary
build: $(BINARY)
mod-tidy:
go mod tidy
# Build our program binary
# Depends on GO_FILES to determine when rebuild is needed
$(BINARY): mod-tidy $(GO_FILES)
CGO_ENABLED=0 go build \
$(GO_LDFLAGS) \
-o $(BINARY) \
./cmd/$(BINARY)
.PHONY: build clean image mod-tidy
clean:
rm -f $(BINARY)
format: mod-tidy
go fmt ./...
gofmt -s -w $(GO_FILES)
golines:
golines -w --ignore-generated --chain-split-dots --max-len=80 --reformat-tags .
swagger:
swag f -g api.go -d internal/api
swag i -g api.go -d internal/api
test: mod-tidy
go test -v -race ./...
# Build docker image
image: build
docker build -t $(BINARY) .