-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
131 lines (101 loc) · 3.4 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
124
125
126
127
128
129
130
131
GIT_REF := $(shell git describe --always)
GIT_TAG := $(shell git describe --contains "$(GIT_REF)" 2>/dev/null | \
sed "s/.*~.*//")
VERSION ?= $(if $(GIT_TAG),$(GIT_TAG),$(GIT_REF))
DEV_TOOLS = \
golang.org/x/lint/golint \
github.com/client9/misspell/cmd/misspell \
github.com/kisielk/errcheck \
honnef.co/go/tools/cmd/staticcheck
GOTEST := $(shell if type gotest >/dev/null 2>&1; then echo "gotest -v"; \
else echo "go test -v"; fi)
MIGRATION_DIR ?= migration
DEFAULT_TAG ?= sqlite
TARGETS = $$(go list ./... | grep -v $(MIGRATION_DIR))
.DEFAULT_GOAL = help
# setup {{{
setup\:tools:
@echo "Installing/Updating..."
@for tool in $(DEV_TOOLS); do \
echo " $$tool"; \
GO111MODULE=off go get -u $$tool; \
done
.PHONY: setup\:tools
# }}}
# verify {{{
verify\:fmt: ## Display file names need to be fixed [alias: fmt]
@output=`gofmt -l . 2>&1`; \
if [ "$$output" ]; then \
echo "Run \`gofmt\` on the following files:"; \
echo "$$output"; \
exit 1; \
fi
fmt: verify\:fmt
.PHONY: verify\:fmt fmt
verify\:format: ## Print fix suggestions as diff outputs [alias: format]
@gofmt -d -e `find . -type f -name *.go`
format: verify\:format
.PHONY: verify\:format format
verify\:vet: ## Print filenames reported by go-vet [alias: vet]
@GO111MODULE=on go vet -tags="$(DEFAULT_TAG)" $(TARGETS)
vet: verify\:vet
.PHONY: verify\:vet vet
verify\:lint: ## Verify style using goling [alias: lint]
@golint -set_exit_status $(TARGETS)
lint: verify\:lint
.PHONY: verify\:lint lint
verify\:error: ## Verify errors using errcheck [alias: errcheck]
@GO111MODULE=on errcheck -tags="$(DEFAULT_TAG)" \
-ignoretests $(TARGETS)
errcheck: verify\:error
.PHONY: verify\:error errcheck
verify\:spell: ## Verify spell using misspell [alias: misspell]
@misspell $$(git ls-files)
misspell: verify\:spell
.PHONY: verify\:spell misspell
verify\:code: ## Verify code using staticcheck [alias: staticcheck]
@GO111MODULE=on staticcheck -tags="$(DEFAULT_TAG)" $(TARGETS)
staticcheck: verify\:code
.PHONY: verify\:code staticcheck
verify\:all: fmt vet lint errcheck misspell staticcheck ## Run all verify:xxx checks
.PHONY: verify\:all
# }}}
# test {{{
test: ## Run unit tests
@GO111MODULE=on DATABASE_URL=":memory:" $(GOTEST) -tags="$(DEFAULT_TAG)" \
$(TARGETS)
.PHONY: test
# }}}
# build {{{
__build-%:
tag="$(subst __build-,,$@)" && \
GO111MODULE=on go build -tags="$${tag}" -o bin/gormless \
-ldflags "-X main.version=$(VERSION)" \
gitlab.com/grauwoelfchen/gormless/cmd/gormless
build\:mssql: __build-mssql ## Build cli application for mssql
.PHONY: build\:mssql
build\:mysql: __build-mysql ## Build cli application for mysql
.PHONY: build\:mysql
build\:sqlite: __build-sqlite ## Build cli application for sqlite
.PHONY: build\:sqlite
build\:postgres: __build-postgres ## Build cli application for postgres
.PHONY: build\:postgres
# }}}
# other utilities {{{
migrations: ## Build migrations for development
@for dir in $$(ls migration); do \
cd migration/$$dir; \
GO111MODULE=on go build -buildmode=plugin; \
done
.PHONY: migrations
help: ## Display this message
@grep -E '^[a-z\:\\\-]+: ' $(firstword $(MAKEFILE_LIST)) | \
grep -E ' ## ' | \
sed -e 's/\( \| [ :_0-9a-z\-]*\) / /g' | \
tr -d \\\\ | \
awk 'BEGIN {FS = ": ## "}; {printf "%-16s%s\n", $$1, $$2};'
.PHONY: help
version: ## Print version (with commit counts)
@echo "$(VERSION) ($$(git rev-list HEAD --count) commits)"
.PHONY: version
# }}}