-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.mk
48 lines (35 loc) · 1.37 KB
/
go.mk
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
GO ?= go
LINTER ?= golangci-lint
GO_TESTSUM ?= gotestsum
GIT_DIRTY := $(shell git diff --quiet || echo '-dirty')
VERSION := $(shell [ -z $$(git tag --points-at HEAD) ] && echo "unknown" || echo $$(git tag --points-at HEAD))
COMMIT := $(shell git rev-parse --short HEAD)$(GIT_DIRTY)
LDFLAGS += -ldflags '-extldflags "-static" -s -w -X=main.GitTag=$(VERSION) -X=main.GitCommit=$(COMMIT)' # -s -w reduces binary size by removing some debug information
BUILDFLAGS += -installsuffix cgo --tags release
BUILD_PATH ?= $(shell pwd)
CMD = $(BUILD_PATH)/o-neko-catnip
CMD_SRC = cmd/*.go
all: test lint build
.PHONY: build test test-ci lint lint-ci clean prepare build-for-docker
clean:
rm -f $(CMD)
run:
$(GO) run $(LDFLAGS) $(CMD_SRC) $(ARGS)
test:
$(GO) test -v ./pkg/... -coverprofile cover.out
test-ci:
$(GO_TESTSUM) --format testname --junitfile test_results.xml -- -v ./pkg/... -coverprofile cover.out
lint:
$(GO) mod verify
$(LINTER) run -v
lint-ci:
$(GO) mod verify
$(LINTER) run -v --out-format=junit-xml > linter_results.xml
prepare:
$(GO) mod download
build:
$(GO) build -o $(CMD) -a $(BUILDFLAGS) $(LDFLAGS) $(CMD_SRC)
build-for-docker:
CGO_ENABLED=0 GOOS=linux $(GO) build -o $(CMD) -a $(BUILDFLAGS) $(LDFLAGS) $(CMD_SRC)
mod-outdated: # needs https://github.com/psampaz/go-mod-outdated
$(GO) list -u -m -json all | go-mod-outdated -update -direct