-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
73 lines (60 loc) · 1.97 KB
/
Makefile
File metadata and controls
73 lines (60 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# refind-btrfs-snapshots Makefile
BINARY := refind-btrfs-snapshots
MODULE := github.com/jmylchreest/refind-btrfs-snapshots
VERSION ?= dev
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GOARCH ?= $(shell go env GOARCH)
GOOS ?= linux
LDFLAGS := -s -w \
-X '$(MODULE)/cmd.Version=$(VERSION)' \
-X '$(MODULE)/cmd.Commit=$(COMMIT)' \
-X '$(MODULE)/cmd.BuildTime=$(DATE)'
.PHONY: build test vet lint clean release tag help
## build: Build the binary for the current platform
build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build -ldflags "$(LDFLAGS)" -o dist/$(BINARY) .
## test: Run tests with race detection
test:
go test -race ./...
## vet: Run go vet
vet:
go vet ./...
## lint: Run staticcheck
lint:
staticcheck ./...
## check: Run vet, lint, and tests
check: vet lint test
## coverage: Run tests with coverage report
coverage:
go test -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
## clean: Remove build artifacts
clean:
rm -rf dist/ coverage.out coverage.html
## release: Create a release tag (usage: make release VERSION=x.y.z)
release:
@if [ "$(VERSION)" = "dev" ]; then \
echo "ERROR: VERSION is required. Usage: make release VERSION=x.y.z"; \
exit 1; \
fi
@if ! echo "$(VERSION)" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \
echo "ERROR: VERSION must be semver (x.y.z), got: $(VERSION)"; \
exit 1; \
fi
@if [ -n "$$(git status --porcelain)" ]; then \
echo "ERROR: Working tree is dirty. Commit or stash changes first."; \
exit 1; \
fi
git tag -a "v$(VERSION)" -m "Release v$(VERSION)"
@echo "Tagged v$(VERSION). Push with: git push origin v$(VERSION)"
## tag: Alias for release
tag: release
## help: Show this help message
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/^## / /' | column -t -s ':'