Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
98 lines (77 loc) · 2.88 KB
/
Copy pathMakefile
File metadata and controls
98 lines (77 loc) · 2.88 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
86
87
88
89
90
91
92
93
94
95
96
97
98
PACKAGE = github.com/riptideslabs/keyledger
BINARY_NAME ?= keyledger
BUILD_DIR ?= build
BUILD_PACKAGE = ${PACKAGE}
VERSION ?= $(shell (git symbolic-ref -q --short HEAD || git tag --points-at HEAD | sort | grep '^v' | head -n1) 2>/dev/null || echo "dev")
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
BUILD_DATE ?= $(shell date +%FT%T%z)
GOLANGCI_VERSION = 2.9.0
export CGO_ENABLED ?= 0
export GOOS = $(shell go env GOOS)
export GOARCH = $(shell go env GOARCH)
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: ## Build binary for current platform
@mkdir -p ${BUILD_DIR}
go build ${GOARGS} -o ${BUILD_DIR}/${BINARY_NAME} ${BUILD_PACKAGE}
.PHONY: build-all
build-all: ## Cross-compile for all supported platforms
@mkdir -p ${BUILD_DIR}
GOOS=linux GOARCH=amd64 go build -o ${BUILD_DIR}/${BINARY_NAME}-linux-amd64 ${BUILD_PACKAGE}
GOOS=linux GOARCH=arm64 go build -o ${BUILD_DIR}/${BINARY_NAME}-linux-arm64 ${BUILD_PACKAGE}
GOOS=darwin GOARCH=amd64 go build -o ${BUILD_DIR}/${BINARY_NAME}-darwin-amd64 ${BUILD_PACKAGE}
GOOS=darwin GOARCH=arm64 go build -o ${BUILD_DIR}/${BINARY_NAME}-darwin-arm64 ${BUILD_PACKAGE}
GOOS=windows GOARCH=amd64 go build -o ${BUILD_DIR}/${BINARY_NAME}-windows-amd64.exe ${BUILD_PACKAGE}
.PHONY: run
run: build ## Build and launch the TUI
${BUILD_DIR}/${BINARY_NAME}
.PHONY: run-ci
run-ci: build ## Build and run in non-interactive CI mode
${BUILD_DIR}/${BINARY_NAME} --ci list
.PHONY: install
install: ## Install binary to GOPATH/bin
go install ${BUILD_PACKAGE}
.PHONY: test
test: ## Run tests with coverage
go test ./... \
-coverprofile cover.out \
-v \
-failfast \
-test.paniconexit0
.PHONY: test-short
test-short: ## Run tests without -v
go test ./... -coverprofile cover.out -failfast
.PHONY: fmt
fmt: ## Run go fmt
go fmt ./...
.PHONY: vet
vet: ## Run go vet
go vet ./...
.PHONY: tidy
tidy: ## Run go mod tidy
go mod tidy
bin/golangci-lint-${GOLANGCI_VERSION}:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b bin v${GOLANGCI_VERSION}
@mv bin/golangci-lint $@
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
.PHONY: lint
lint: bin/golangci-lint ## Run golangci-lint
bin/golangci-lint run --timeout 5m
.PHONY: lint-fix
lint-fix: bin/golangci-lint ## Run golangci-lint with auto-fix
bin/golangci-lint run --fix --timeout 5m
.PHONY: check
check: fmt vet lint ## Run fmt, vet, and lint
.PHONY: clean
clean: ## Remove build artifacts
rm -rf ${BUILD_DIR} cover.out
.PHONY: version
version: ## Print version info
@echo "Version: ${VERSION}"
@echo "Commit: ${COMMIT_HASH}"
@echo "Build date: ${BUILD_DATE}"