forked from pr8kerl/f5er
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
71 lines (57 loc) · 2.05 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
.PHONY: deps vet format test publish clena
SHELL = bash
GOPATH ?= $(HOME)/.go
GOBIN := $(GOPATH)/bin
PATH := $(GOPATH)/bin:$(PATH)
PROJ := f5er
DOCKER_USERNAME ?= Monkey
DOCKER_PASSWORD ?= Magic
LDFLAGS := -ldflags "-X main.commit=$$(git rev-parse HEAD)"
.ONESHELL:
all: vet format test $(PROJ) publish
deps:
@echo "--- collecting ingredients :bento:"
GOPATH=$(GOPATH) dep ensure
vet: deps
@export GOPATH=$(GOPATH)
go list -f '{{.Dir}}' ./... | grep -vP '(/vendor/|f5er$$)' | xargs go tool vet -all
format:
@echo "--- checking for dirty ingredients :mag_right:"
export GOPATH=$(GOPATH)
declare -a files
files=( $$(gofmt -l $$(find . -name '*.go' -a -not -regex '.+/vendor/.+' | xargs)) )
if [[ $${#files[@]} -ge 1 ]]; then
[[ $${#files[@]} -eq 1 ]] && s= || s=s
echo "Found $${#files[@]} dirty ingredient$${s} :face_nose: - cleaning..."
for ((i = 0; i < $${#files[@]}; i++)); do
echo -en "\t$${files[$$i]} -> "
if gofmt -w "$${files[$$i]}" >&-; then
echo "cleaned :sparkles:"
else
echo "still dirty :slightly_frowning_face: - manual intervention required."
fi
done
fi
test: format vet deps
@echo "+++ Is this thing working? :hammer_and_wrench:"
GOPATH=$(GOPATH) go test -cover -v
$(PROJ): deps
CGO_ENABLED=0 GOPATH=$(GOPATH) go build $(LDFLAGS) -o $@ -v
touch $@ && chmod 755 $@
linux: deps
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPATH=$(GOPATH) go build $(LDFLAGS) -o $(PROJ)-linux-amd64 -v
touch $(PROJ)-linux-amd64 && chmod 755 $(PROJ)-linux-amd64
windows: deps
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 GOPATH=$(GOPATH) go build $(LDFLAGS) -o $(PROJ)-windows-amd64.exe -v
touch $(PROJ)-windows-amd64.exe
darwin: deps
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 GOPATH=$(GOPATH) go build -o $(PROJ)-darwin-amd64 -v
touch $(PROJ)-darwin-amd64 && chmod 755 $(PROJ)-darwin-amd64
ifdef TRAVIS_TAG
publish: deps
@echo "+++ release :octocat:"
docker login -u "$(DOCKER_USERNAME)" -p "$(DOCKER_PASSWORD)"
goreleaser --skip-validate --rm-dist
endif
clean:
rm -rf $(PROJ) $(PROJ)-windows-amd64.exe $(PROJ)-linux-amd64 $(PROJ)-darwin-amd64 dist