-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
55 lines (45 loc) · 1.85 KB
/
Makefile
File metadata and controls
55 lines (45 loc) · 1.85 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
BINARY := git-rain
ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
REPO_BIN := $(ROOT)$(BINARY)
USER_BIN := $(abspath $(HOME)/.local/bin)
INSTALL_BIN := $(USER_BIN)/$(BINARY)
# Never pass an empty -X value: shallow CI checkouts can yield a blank describe/go list
# line, which makes Cobra omit --version. Use _VERSION intermediate to guard against that.
_VERSION := $(shell git -C "$(ROOT)" describe --tags --dirty 2>/dev/null || (cd "$(ROOT)" && go list -m -f '{{.Version}}' 2>/dev/null) || echo dev)
VERSION ?= $(if $(strip $(_VERSION)),$(strip $(_VERSION)),dev)
LDFLAGS := -X github.com/git-rain/git-rain/cmd.Version=$(VERSION)
LDFLAGS_RELEASE := $(LDFLAGS) -s -w
.PHONY: all build run test test-race lint clean install help
all: build
## build: compile binary next to this Makefile (./git-rain in repo root)
build:
cd "$(ROOT)" && go build -ldflags "$(LDFLAGS)" -o "$(REPO_BIN)" .
## run: build and run with optional ARGS (e.g. make run ARGS="--dry-run")
run: build
"$(REPO_BIN)" $(ARGS)
## test: run all tests
test:
cd "$(ROOT)" && go test -count=1 ./...
## test-race: run tests with race detector
test-race:
cd "$(ROOT)" && go test -race -count=1 ./...
## lint: vet the code
lint:
cd "$(ROOT)" && go vet ./...
## clean: remove the repo-local built binary
clean:
rm -f "$(REPO_BIN)"
## install: build and copy to ~/.local/bin (overwrites). Invoke from anywhere: make -C /path/to/git-rain install
install:
@mkdir -p "$(USER_BIN)"
cd "$(ROOT)" && go build -ldflags "$(LDFLAGS_RELEASE)" -o "$(INSTALL_BIN)" .
@chmod 755 "$(INSTALL_BIN)"
@echo ""
@echo "Installed: $(INSTALL_BIN)"
@echo "This shell: export PATH=\"$$HOME/.local/bin:$$PATH\" && hash -r"
@echo " (zsh: use rehash instead of hash -r if needed)"
@echo "Permanent: add the export line to ~/.zshrc or ~/.bashrc"
@echo ""
## help: show this help
help:
@grep -E '^##' Makefile | sed 's/## / /'