-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMakefile
More file actions
57 lines (45 loc) · 1.97 KB
/
Makefile
File metadata and controls
57 lines (45 loc) · 1.97 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
.PHONY: help fmt test install tag release check-clean check-version install-hooks
SHELL := /bin/sh
# Set VERSION on the command line, e.g.:
# make release VERSION=v0.2.0
VERSION ?=
# A helpful dev version string (used by install-dev)
GIT_DESCRIBE := $(shell git describe --tags --always --dirty 2>/dev/null)
help:
@printf "%s\n" \
"Targets:" \
" make fmt # gofmt -w ." \
" make install-hooks # install git pre-commit hook" \
" make test # go test ./..." \
" make install # build and install with version from git" \
" make tag VERSION=vX.Y.Z # create annotated git tag (requires clean tree)" \
" make release VERSION=vX.Y.Z # tag + push (triggers GoReleaser via GitHub Actions)"
fmt:
gofmt -w .
test:
go test ./...
install:
@V="$(GIT_DESCRIBE)"; V=$${V:-dev}; \
echo "Installing td $$V"; \
go install -ldflags "-X main.Version=$$V" .
check-clean:
@git diff --quiet && git diff --cached --quiet || (echo "Error: working tree is not clean" && exit 1)
check-version:
@test -n "$(VERSION)" || (echo "Error: VERSION is required (e.g. VERSION=v0.2.0)" && exit 1)
@echo "$(VERSION)" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+' || (echo "Error: VERSION should look like vX.Y.Z" && exit 1)
tag: check-clean check-version
@git rev-parse -q --verify "refs/tags/$(VERSION)" >/dev/null && (echo "Error: tag $(VERSION) already exists" && exit 1) || true
git tag -a "$(VERSION)" -m "$(VERSION)"
repo=$$(git remote get-url origin 2>/dev/null || true); \
if [ -n "$$repo" ]; then \
echo "Created tag $(VERSION)"; \
else \
echo "Created tag $(VERSION) (no 'origin' remote found)"; \
fi
release: tag
@git remote get-url origin >/dev/null 2>&1 || (echo "Error: no 'origin' remote configured" && exit 1)
git push origin "$(VERSION)"
install-hooks:
@echo "Installing git pre-commit hook..."
@ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit
@echo "Done. Hook installed at .git/hooks/pre-commit"