-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (50 loc) · 1.92 KB
/
Copy pathMakefile
File metadata and controls
72 lines (50 loc) · 1.92 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
BINARY := fastmail
ALIAS := fm
BUILD_DIR := ./bin
MODULE := github.com/biao29/fastmail-cli
VERSION_PKG := $(MODULE)/internal/version
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -s -w \
-X $(VERSION_PKG).Version=$(VERSION) \
-X $(VERSION_PKG).Commit=$(COMMIT) \
-X $(VERSION_PKG).Date=$(DATE)
BUILD_FLAGS := -trimpath -ldflags "$(LDFLAGS)"
.PHONY: build build-fastmail build-fm test test-unit test-e2e test-race test-coverage fmt fmt-check vet lint clean install tidy tidy-check replace-check release-check release
build: build-fastmail build-fm
build-fastmail:
go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY) ./cmd/fastmail
build-fm:
go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(ALIAS) ./cmd/fm
install:
go install $(BUILD_FLAGS) ./cmd/fastmail
go install $(BUILD_FLAGS) ./cmd/fm
test: test-unit
test-unit:
FASTMAIL_NO_KEYRING=1 go test ./... -count=1
test-race:
FASTMAIL_NO_KEYRING=1 go test ./... -race -count=1
test-coverage:
FASTMAIL_NO_KEYRING=1 go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
fmt:
gofmt -w .
fmt-check:
@test -z "$$(gofmt -l .)" || (echo "Files need formatting:" && gofmt -l . && exit 1)
vet:
go vet ./...
lint: vet fmt-check
clean:
rm -rf $(BUILD_DIR) coverage.out
tidy:
go mod tidy
tidy-check:
@cp go.mod go.mod.bak && cp go.sum go.sum.bak
@(go mod tidy && diff -q go.mod go.mod.bak > /dev/null && diff -q go.sum go.sum.bak > /dev/null && rm -f go.mod.bak go.sum.bak) || \
(echo "go.mod/go.sum not tidy or tidy failed" && mv -f go.mod.bak go.mod && mv -f go.sum.bak go.sum && exit 1)
replace-check:
@if grep -q '^replace' go.mod; then echo "ERROR: go.mod contains replace directives" && exit 1; fi
release-check: fmt-check vet tidy-check replace-check test-unit
release:
@scripts/release.sh $(VERSION)