-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (90 loc) · 4.67 KB
/
Makefile
File metadata and controls
110 lines (90 loc) · 4.67 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# ── project metadata ────────────────────────────────────────────────────────────
name := gitr
pkg := github.com/swarupdonepudi/gitr
build_dir := dist
LDFLAGS := -ldflags "-X $(pkg)/cmd/gitr/root.VersionLabel=$$(git describe --tags --always --dirty)"
# ── helper vars ────────────────────────────────────────────────────────────────
build_cmd := go build $(LDFLAGS)
# ── quality / housekeeping ─────────────────────────────────────────────────────
.PHONY: deps vet fmt test clean
deps: ## download & tidy modules
go mod download
go mod tidy
vet: ## go vet
go vet ./...
fmt: ## go fmt
go fmt ./...
test: vet ## run tests with race detector
go test -race -v -count=1 ./...
clean: ## remove build artifacts
rm -rf $(build_dir)
# ── build ─────────────────────────────────────────────────────────────────────
.PHONY: build build-cli build-site
build: build-cli build-site ## build CLI and website
build-cli: deps fmt vet ## build the Go CLI binary
$(build_cmd) -o $(build_dir)/$(name) .
build-site: ## build the website
cd site && NODE_NO_WARNINGS=1 yarn install
cd site && NODE_NO_WARNINGS=1 yarn build
# ── local utility ──────────────────────────────────────────────────────────────
.PHONY: snapshot local
snapshot: deps ## build a local snapshot using GoReleaser
goreleaser release --snapshot --clean --skip=publish
local: deps fmt vet ## build and install binary to ~/bin
$(build_cmd) -o $(build_dir)/$(name) .
install -m 0755 $(build_dir)/$(name) $(HOME)/bin/$(name)
# ── release tagging ────────────────────────────────────────────────────────────
.PHONY: release build-check next-version
build-check: ## quick compile to verify build
go build -o /dev/null .
# bump: major, minor, or patch (default)
bump ?= patch
# Detect if version was explicitly provided on command line
ifeq ($(origin version),command line)
VERSION_EXPLICIT := true
else
VERSION_EXPLICIT := false
endif
next-version: ## show what the next version would be
@latest=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
major=$$(echo $$latest | sed 's/v//' | cut -d. -f1); \
minor=$$(echo $$latest | sed 's/v//' | cut -d. -f2); \
patch=$$(echo $$latest | sed 's/v//' | cut -d. -f3); \
case "$(bump)" in \
major) major=$$((major + 1)); minor=0; patch=0 ;; \
minor) minor=$$((minor + 1)); patch=0 ;; \
patch) patch=$$((patch + 1)) ;; \
*) echo "Invalid bump type: $(bump). Use major, minor, or patch"; exit 1 ;; \
esac; \
echo "v$$major.$$minor.$$patch"
release: test build-check ## auto-bump version, tag & push (bump=major|minor|patch, default: patch). Override with version=vX.Y.Z
@if [ "$(VERSION_EXPLICIT)" = "true" ]; then \
rel_version="$(version)"; \
echo "Releasing: $$rel_version (explicit version)"; \
else \
latest=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
major=$$(echo $$latest | sed 's/v//' | cut -d. -f1); \
minor=$$(echo $$latest | sed 's/v//' | cut -d. -f2); \
patch=$$(echo $$latest | sed 's/v//' | cut -d. -f3); \
case "$(bump)" in \
major) major=$$((major + 1)); minor=0; patch=0 ;; \
minor) minor=$$((minor + 1)); patch=0 ;; \
patch) patch=$$((patch + 1)) ;; \
*) echo "Invalid bump type: $(bump). Use major, minor, or patch"; exit 1 ;; \
esac; \
rel_version="v$$major.$$minor.$$patch"; \
echo "Current version: $$latest"; \
echo "Releasing: $$rel_version ($(bump) bump)"; \
fi; \
git tag -a $$rel_version -m "$$rel_version"; \
git push origin $$rel_version
# ── default target ─────────────────────────────────────────────────────────────
.DEFAULT_GOAL := test
.PHONY: develop-site
develop-site:
cd site && NODE_NO_WARNINGS=1 yarn install
cd site && NODE_NO_WARNINGS=1 yarn dev
.PHONY: preview-site
preview-site:
cd site && NODE_NO_WARNINGS=1 yarn install
cd site && NODE_NO_WARNINGS=1 yarn build:serve