-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (68 loc) · 2.6 KB
/
Copy pathMakefile
File metadata and controls
85 lines (68 loc) · 2.6 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
BINARY := vmstat
MODULE := github.com/trentas/vmstat-macos
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)
# Installs into ~/.local/bin by default, which needs no sudo. For a system-wide
# install use: sudo make install PREFIX=/usr/local
PREFIX ?= $(HOME)/.local
BINDIR := $(PREFIX)/bin
.DEFAULT_GOAL := build
.PHONY: build
build: ## Build ./bin/$(BINARY)
@mkdir -p bin
go build -trimpath -ldflags '$(LDFLAGS)' -o bin/$(BINARY) .
@echo "built bin/$(BINARY) ($(VERSION))"
.PHONY: install
install: build ## Install $(BINARY) into $(BINDIR)
@mkdir -p "$(BINDIR)"
install -m 0755 bin/$(BINARY) "$(BINDIR)/$(BINARY)"
@echo "installed $(BINDIR)/$(BINARY)"
@command -v $(BINARY) >/dev/null 2>&1 || \
echo "warning: $(BINDIR) is not on your PATH; add it to run '$(BINARY)' directly"
.PHONY: uninstall
uninstall: ## Remove $(BINARY) from $(BINDIR)
rm -f "$(BINDIR)/$(BINARY)"
@echo "removed $(BINDIR)/$(BINARY)"
.PHONY: test
test: ## Run the test suite
go test ./...
.PHONY: race
race: ## Run the test suite under the race detector
go test -race ./...
.PHONY: vet
vet: ## Run go vet
go vet ./...
.PHONY: fmt
fmt: ## Format the source
gofmt -w .
.PHONY: fmtcheck
fmtcheck: ## Fail if any file is not gofmt-clean
@out=$$(gofmt -l .); \
if [ -n "$$out" ]; then echo "not gofmt-clean:"; echo "$$out"; exit 1; fi
@echo "gofmt ok"
.PHONY: check
check: fmtcheck vet test ## Run every check
.PHONY: run
run: build ## Build and run with a 1s interval
./bin/$(BINARY) 1
# Deploy key with write access to trentas/homebrew-tap. CI supplies the key
# contents through the HOMEBREW_TAP_DEPLOY_KEY secret; locally this is a path.
TAP_KEY ?= $(HOME)/.ssh/vmstat_tap_deploy
.PHONY: snapshot
snapshot: ## Build release artifacts locally without publishing
HOMEBREW_TAP_DEPLOY_KEY=unused goreleaser release --snapshot --clean --skip=publish
.PHONY: release
release: ## Publish the current tag (CI does this on tag push; this is the fallback)
@git describe --exact-match --tags >/dev/null 2>&1 \
|| { echo "HEAD is not tagged; run: git tag -a vX.Y.Z -m ... && git push origin vX.Y.Z"; exit 1; }
@test -f "$(TAP_KEY)" \
|| { echo "missing tap deploy key at $(TAP_KEY); override with TAP_KEY=/path/to/key"; exit 1; }
GITHUB_TOKEN="$$(gh auth token)" HOMEBREW_TAP_DEPLOY_KEY="$(TAP_KEY)" \
goreleaser release --clean
.PHONY: clean
clean: ## Remove build artifacts
rm -rf bin dist
.PHONY: help
help: ## List the available targets
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'