-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
123 lines (104 loc) · 3.18 KB
/
Makefile
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
111
112
113
114
115
116
117
118
119
120
121
122
123
NAME := acli
CGO_ENABLED = 0
BUILD_GOOS = $(shell go env GOOS)
GO := go
BUILD_TARGET = build
COMMIT := $(shell git rev-parse --short HEAD)
VERSION := dev-$(shell git describe --tags $(shell git rev-list --tags --max-count=1) || echo "1.0.0")
BUILD_DATE := $(shell date +'%Y-%m-%d')
BUILD_FLAGS = -ldflags "-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.date=$(BUILD_DATE) -w -s" \
-trimpath
MAIN_SRC_FILE = cmd/articli/main.go
GOARCH = $(shell uname -m)
.PHONY: build
build: pre-build
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=$(BUILD_GOOS) GOARCH=$(GOARCH) $(GO) $(BUILD_TARGET) $(BUILD_FLAGS) -o bin/$(BUILD_GOOS)/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/$(BUILD_GOOS)/$(NAME)
rm -rf $(NAME)
ln -s bin/$(BUILD_GOOS)/$(NAME) $(NAME)
.PHONY: darwin
darwin: pre-build
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=$(GOARCH) $(GO) $(BUILD_TARGET) $(BUILD_FLAGS) -o bin/darwin/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/darwin/$(NAME)
rm -rf $(NAME)
ln -s bin/darwin/$(NAME) $(NAME)
.PHONY: linux
linux: pre-build
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) $(GO) $(BUILD_TARGET) $(BUILD_FLAGS) -o bin/linux/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/linux/$(NAME)
rm -rf $(NAME)
ln -s bin/linux/$(NAME) $(NAME)
.PHONY: win
win: pre-build
go get github.com/inconshreveable/mousetrap
go get github.com/mattn/go-isatty
CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=386 $(GO) $(BUILD_TARGET) $(BUILD_FLAGS) -o bin/windows/$(NAME).exe $(MAIN_SRC_FILE)
.PHONY: build-all
build-all: darwin linux win
.PHONY: release
release: build-all
mkdir -p release
cd ./bin/darwin; upx $(NAME); \
tar -zcvf ../../release/$(NAME)-darwin-amd64.tar.gz $(NAME); \
cd ../../release/; \
shasum -a 256 $(NAME)-darwin-amd64.tar.gz > $(NAME)-darwin-amd64.txt
cd ./bin/linux; upx $(NAME); \
tar -zcvf ../../release/$(NAME)-linux-amd64.tar.gz $(NAME); \
cd ../../release/; \
shasum -a 256 $(NAME)-linux-amd64.tar.gz > $(NAME)-linux-amd64.txt
cd ./bin/windows; \
upx $(NAME).exe; \
tar -zcvf ../../release/$(NAME)-windows-386.tar.gz $(NAME).exe; \
cd ../../release/; \
shasum -a 256 $(NAME)-windows-386.tar.gz > $(NAME)-windows-386.txt
.PHONY: clean
clean:
rm -rf bin release
rm -rf coverage.out
rm -f $(NAME)
.PHONY: get-golint
get-golint:
go get -u golang.org/x/lint/golint
.PHONY: tools
tools: get-golint
brew install goreleaser/tap/goreleaser
#brew install --build-from-source upx
go install honnef.co/go/tools/cmd/staticcheck@latest
.PHONY: verify
verify: dep tools lint
.PHONY: pre-build
pre-build: fmt vet
export GO111MODULE=on
go mod tidy
.PHONY: vet
vet:
go vet ./...
.PHONY: staticcheck
staticcheck:
staticcheck ./...
.PHONY: lint
lint: vet
golint -set_exit_status cmd/...
golint -set_exit_status internal/...
golint -set_exit_status pkg/...
.PHONY: fmt
fmt:
go fmt ./cmd/...
go fmt ./internal/...
go fmt ./pkg/...
gofmt -s -w .
# https://about.codecov.io/blog/getting-started-with-code-coverage-for-golang/
.PHONY: test
test:
go test ./... -race -covermode=atomic -coverprofile=coverage.out -v -count=1
.PHONY: test-release
test-release:
goreleaser release --rm-dist --snapshot --skip-publish
.PHONY: dep
dep:
go mod download
.PHONY: docs
docs:
docsify serve docs