-
Notifications
You must be signed in to change notification settings - Fork 7
/
MakeFile
75 lines (62 loc) · 3.35 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
BIN="./bin"
SRC=$(shell find . -name "*.go")
CURRENT_TAG=$(shell git describe --tags --abbrev=0)
GOLANGCI := $(shell command -v golangci-lint 2>/dev/null)
RICHGO := $(shell command -v richgo 2>/dev/null)
GOTESTFMT := $(shell command -v gotestfmt 2>/dev/null)
MIN_GOLANGCI_LINT_VERSION := 001043000
.PHONY: fmt lint build test clean compile compress
default: all
all: fmt lint build test release
release: clean build compile compress
fmt:
$(info ******************** checking formatting ********************)
@test -z $(shell gofmt -l $(SRC)) || (gofmt -d $(SRC); exit 1)
.PHONY: golangci-lint-check
golangci-lint-check:
$(eval GOLANGCI_LINT_VERSION := $(shell printf "%03d%03d%03d" $(shell golangci-lint --version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
$(eval MIN_GOLANGCI_LINT_VER_FMT := $(shell printf "%g.%g.%g" $(shell echo $(MIN_GOLANGCI_LINT_VERSION) | grep -o ...)))
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
echo "Downloading golangci-lint v${MIN_GOLANGCI_LINT_VER_FMT}"; \
export BINARY="golangci-lint"; \
curl -sfL "https://raw.githubusercontent.com/golangci/golangci-lint/v${MIN_GOLANGCI_LINT_VER_FMT}/install.sh" | sh -s -- -b $(GOPATH)/bin v$(MIN_GOLANGCI_LINT_VER_FMT); \
elif [ "$(GOLANGCI_LINT_VERSION)" -lt "$(MIN_GOLANGCI_LINT_VERSION)" ]; then \
echo "Downloading newer version of golangci-lint v${MIN_GOLANGCI_LINT_VER_FMT}"; \
export BINARY="golangci-lint"; \
curl -sfL "https://raw.githubusercontent.com/golangci/golangci-lint/v${MIN_GOLANGCI_LINT_VER_FMT}/install.sh" | sh -s -- -b $(GOPATH)/bin v$(MIN_GOLANGCI_LINT_VER_FMT); \
fi
.PHONY: lint
lint: golangci-lint-check
$(info ******************** running lint tools ********************)
golangci-lint run -c .golangci-lint.yml -v ./... --timeout 10m
test:
$(info ******************** running tests ********************)
ifeq ($(GITHUB_ACTIONS), true)
ifndef GOTESTFMT
$(warning "could not find gotestfmt in $(PATH), running: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest")
$(shell go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest)
endif
go test -json -v ./... 2>&1 | tee coverage/gotest.log | gotestfmt
else
ifndef RICHGO
$(warning "could not find richgo in $(PATH), running: go install github.com/kyoh86/richgo@latest")
$(shell go install github.com/kyoh86/richgo@latest)
endif
richgo test -v ./...
endif
clean:
rm -rf $(BIN) 2>/dev/null
build:
go env -w GOFLAGS=-mod=mod
go mod tidy
go build -v -trimpath -ldflags="-s -w" .
compile:
GOOS=linux GOARCH=amd64 go build -o bin/linux/amd64/pimp-my-shell-$(CURRENT_TAG)-linux-amd64 -trimpath -ldflags="-s -w" main.go
GOOS=linux GOARCH=arm64 go build -o bin/linux/arm64/pimp-my-shell-$(CURRENT_TAG)-linux-arm64 -trimpath -ldflags="-s -w" main.go
GOOS=darwin GOARCH=amd64 go build -o bin/darwin/amd64/pimp-my-shell-$(CURRENT_TAG)-x86_64-apple-darwin_amd64 -trimpath -ldflags="-s -w" main.go
GOOS=darwin GOARCH=arm64 go build -o bin/darwin/arm64/pimp-my-shell-$(CURRENT_TAG)-x86_64-apple-darwin_arm64 -trimpath -ldflags="-s -w" main.go
compress:
gzip -9 bin/linux/amd64/pimp-my-shell-$(CURRENT_TAG)-linux-amd64
gzip -9 bin/linux/arm64/pimp-my-shell-$(CURRENT_TAG)-linux-arm64
gzip -9 bin/darwin/amd64/pimp-my-shell-$(CURRENT_TAG)-x86_64-apple-darwin_amd64
gzip -9 bin/darwin/arm64/pimp-my-shell-$(CURRENT_TAG)-x86_64-apple-darwin_arm64