-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
63 lines (48 loc) · 1.72 KB
/
Makefile
File metadata and controls
63 lines (48 loc) · 1.72 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
SHELL := /bin/bash
.DEFAULT_GOAL := build
.PHONY: build placeholder-cli help fmt fmt-check lint test ci tools
BIN_DIR := $(CURDIR)/bin
BIN := $(BIN_DIR)/placeholder-cli
CMD := ./cmd/placeholder
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT := $(shell git rev-parse --short=12 HEAD 2>/dev/null || echo "")
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -X github.com/builtbyrobben/cli-template/internal/cmd.version=$(VERSION) -X github.com/builtbyrobben/cli-template/internal/cmd.commit=$(COMMIT) -X github.com/builtbyrobben/cli-template/internal/cmd.date=$(DATE)
TOOLS_DIR := $(CURDIR)/.tools
GOFUMPT := $(TOOLS_DIR)/gofumpt
GOIMPORTS := $(TOOLS_DIR)/goimports
GOLANGCI_LINT := $(TOOLS_DIR)/golangci-lint
ifneq ($(filter placeholder-cli,$(MAKECMDGOALS)),)
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)
endif
build:
@mkdir -p $(BIN_DIR)
@go build -ldflags "$(LDFLAGS)" -o $(BIN) $(CMD)
placeholder-cli: build
@if [ -n "$(RUN_ARGS)" ]; then \
$(BIN) $(RUN_ARGS); \
elif [ -z "$(ARGS)" ]; then \
$(BIN) --help; \
else \
$(BIN) $(ARGS); \
fi
help: build
@$(BIN) --help
tools:
@mkdir -p $(TOOLS_DIR)
@GOBIN=$(TOOLS_DIR) go install mvdan.cc/[email protected]
@GOBIN=$(TOOLS_DIR) go install golang.org/x/tools/cmd/[email protected]
@GOBIN=$(TOOLS_DIR) go install github.com/golangci/golangci-lint/cmd/[email protected]
fmt: tools
@$(GOIMPORTS) -local github.com/builtbyrobben/cli-template -w .
@$(GOFUMPT) -w .
fmt-check: tools
@$(GOIMPORTS) -local github.com/builtbyrobben/cli-template -w .
@$(GOFUMPT) -w .
@git diff --exit-code -- '*.go' go.mod go.sum
lint: tools
@$(GOLANGCI_LINT) run
test:
@go test ./...
ci: fmt-check lint test