This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 345
/
Makefile
77 lines (62 loc) · 2.57 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
.PHONY: test format vet staticcheck magneticod magneticow image image-magneticow image-magneticod
all: test magneticod magneticow
magneticod:
go install --tags fts5 "-ldflags=-s -w -X main.compiledOn=`date -u +%Y-%m-%dT%H:%M:%SZ`" ./cmd/magneticod
magneticow:
# TODO: minify files!
# https://github.com/kevinburke/go-bindata
go-bindata -pkg "main" -o="cmd/magneticow/bindata.go" -prefix="cmd/magneticow/data/" cmd/magneticow/data/...
# Prepend the linter instruction to the beginning of the file
sed -i '1s;^;//lint:file-ignore * Ignore file altogether\n;' cmd/magneticow/bindata.go
go install --tags fts5 "-ldflags=-s -w -X main.compiledOn=`date -u +%Y-%m-%dT%H:%M:%SZ`" ./cmd/magneticow
.PHONY: docker
docker: docker_up docker_logs
.PHONY: docker_up
docker_up:
docker-compose up -d
.PHONY: docker_down
docker_down:
docker-compose down
.PHONY: docker_logs
docker_logs:
docker-compose logs -ft --tail=10
image-magneticod:
docker build -t boramalper/magneticod -f Dockerfile.magneticod .
image-magneticow:
docker build -t boramalper/magneticow -f Dockerfile.magneticow .
image: image-magneticod image-magneticow
vet:
go vet ./...
staticcheck:
./misc/staticcheck/staticcheck -fail all ./...
test:
go test ./...
format:
gofmt -w ./cmd/
gofmt -w ./pkg/
# Formatting Errors
# Since gofmt returns zero even if there are files to be formatted, we use:
#
# ! gofmt -d ${GOPATH}/path/ 2>&1 | read
#
# to return 1 if there are files to be formatted, and 0 if not.
# https://groups.google.com/forum/#!topic/Golang-Nuts/pdrN4zleUio
#
# How can I use Bash syntax in Makefile targets?
# Because `read` is a bash command.
# https://stackoverflow.com/a/589300/4466589
#
# How to ignore bindata.go
# Due to irrational insistence of some Go developers, gofmt, like many
# other tools of Go ecosystem, does not have flags for common scenarios
# such as ignoring certain files by pattern etc. Thus we use `go list`
# and grep together to achieve the desired result.
#
# The original query is this:
# gofmt -l $(go list -f $'{{range .GoFiles}}{{$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go)
#
# The original query is then escaped for Makefile (by repeating dollar signs $ -> $$).
check-formatting: SHELL:=/bin/bash # HERE: this is setting the shell for check-formatting only
check-formatting:
! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read
! gofmt -l $$(go list -f $$'{{range .GoFiles}}{{$$.Dir}}/{{.}}\n{{end}}' ./... | grep -v bindata.go) 2>&1 | tee /dev/fd/2 | read