Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (56 loc) · 2.22 KB
/
Copy pathMakefile
File metadata and controls
67 lines (56 loc) · 2.22 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
# Leading "v" is stripped to match goreleaser's {{.Version}}, so `mint --version`
# prints the same string for local builds and released binaries.
VERSION ?= $(shell (git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD) | sed 's/^v//')
COMMIT ?= $(shell git rev-parse HEAD)
LDFLAGS ?= -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT)
NEW_FROM_REV ?= HEAD
.PHONY: build
build:
mkdir -p ./bin/
CGO_ENABLED=0 go build -trimpath -ldflags="$(LDFLAGS)" -o ./bin/ ./cmd/mint
# An unresolvable rev is not silent: golangci-lint warns, reports every issue, and
# exits 1. This guard is for the message, not the exit code.
.PHONY: check-rev
check-rev:
@git rev-parse --verify --quiet '$(NEW_FROM_REV)^{commit}' >/dev/null || \
{ echo "NEW_FROM_REV=$(NEW_FROM_REV) is not a valid revision" >&2; exit 1; }
# Tidy first: a stale go.mod fails typecheck, which is reported past --new-from-rev
# while every other linter falls silent -- so --fix would quietly repair nothing.
# Tidy again after: exptostd rewrites x/exp imports to stdlib and strips a require.
# The closing lint reports whatever --fix could not repair.
.PHONY: fix
fix: check-rev
go mod tidy
golangci-lint run --new-from-rev=$(NEW_FROM_REV) --fix ./...
go mod tidy
@$(MAKE) --no-print-directory lint
.PHONY: lint
lint: check-rev
golangci-lint config verify
golangci-lint run --new-from-rev=$(NEW_FROM_REV) ./...
.PHONY: test
test:
go test -race -failfast ./...
.PHONY: cover
cover:
go test -race -covermode=atomic -coverpkg=./... -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
.PHONY: cover-html
cover-html: cover
go tool cover -html=coverage.out -o coverage.html
.PHONY: check-tidy
check-tidy:
go mod tidy -diff
# The full gate: every hook in .pre-commit-config.yaml -- check-tidy, lint and test
# included -- over every tracked file, i.e. what `git commit` runs but repo-wide.
# NEW_FROM_REV on the command line reaches the nested `make lint` via MAKEFLAGS;
# without it lint falls back to HEAD and reports nothing on CI's clean checkout.
.PHONY: check
check:
prek run --all-files --show-diff-on-failure
.PHONY: release
release:
goreleaser release --clean
.PHONY: release-snapshot
release-snapshot:
goreleaser release --snapshot --clean