This repository has been archived by the owner on Aug 22, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMakefile
111 lines (82 loc) · 3.75 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
# Root directory of the project (absolute path).
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Base path used to install.
DESTDIR=/usr/local
# Used to populate version variable in main package.
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
PROJECT_ROOT=github.com/vdemeester/docker-volume-ipfs
# Race detector is only supported on amd64.
RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race"))
# Project packages.
PACKAGES=$(shell go list ./... | grep -v /vendor/)
INTEGRATION_PACKAGE=${PROJECT_ROOT}/integration
# Project binaries.
COMMANDS=docker-volume-ipfs
BINARIES=$(addprefix bin/,$(COMMANDS))
GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)"
.PHONY: clean all fmt vet lint build binaries test integration setup coverage ci check help install uninstall
.DEFAULT: default
all: check binaries test integration ## run fmt, vet, lint, build the binaries and run the tests
check: fmt vet lint ineffassign ## run fmt, vet, lint, ineffassign
ci: check binaries coverage coverage-integration ## to be used by the CI
setup: ## install dependencies
@echo "🐳 $@"
@go get -u github.com/golang/lint/golint
@go get -u github.com/golang/mock/mockgen
@go get -u github.com/gordonklaus/ineffassign
# Depends on binaries because vet will silently fail if it can't load compiled
# imports
vet: binaries ## run go vet
@echo "🐳 $@"
@test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | egrep -v '(timestamp_test.go|duration_test.go|exit status 1)' | tee /dev/stderr)"
fmt: ## run go fmt
@echo "🐳 $@"
@test -z "$$(gofmt -s -l . | grep -v vendor/ | tee /dev/stderr)" || \
(echo "👹 please format Go code with 'gofmt -s -w'" && false)
lint: ## run go lint
@echo "🐳 $@"
@test -z "$$(golint ./... | grep -v vendor/ | tee /dev/stderr)"
ineffassign: ## run ineffassign
@echo "🐳 $@"
@test -z "$$(ineffassign . | grep -v vendor/ | tee /dev/stderr)"
build: ## build the go packages
@echo "🐳 $@"
@go build -i -tags "${BUILDTAGS}" -v ${GO_LDFLAGS} ${GO_GCFLAGS} ${PACKAGES}
test: ## run tests, except integration tests
@echo "🐳 $@"
@go test -parallel 8 ${RACE} -tags "${BUILDTAGS}" $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
integration: ## run integration tests
@echo "🐳 $@"
@go test -parallel 8 ${RACE} -tags "${BUILDTAGS}" ${INTEGRATION_PACKAGE}
FORCE:
# Build a binary from a cmd.
bin/%: cmd/% FORCE
@test $$(go list) = "${PROJECT_ROOT}" || \
(echo "👹 Please correctly set up your Go build environment. This project must be located at <GOPATH>/src/${PROJECT_ROOT}" && false)
@echo "🐳 $@"
@go build -i -tags "${BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./$<
binaries: $(BINARIES) ## build binaries
@echo "🐳 $@"
clean: ## clean up binaries
@echo "🐳 $@"
@rm -f $(BINARIES)
coverage: ## generate coverprofiles from the unit tests
@echo "🐳 $@"
@for pkg in $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}); do \
go test ${RACE} -tags "${BUILDTAGS}" -test.short -coverprofile="../../../$$pkg/coverage.txt" $${pkg} || exit 1; \
done
coverage-integration: ## generate coverprofiles from the integration tests
@echo "🐳 $@"
go test ${RACE} -tags "${BUILDTAGS}" -test.short -coverprofile="../../../${INTEGRATION_PACKAGE}/coverage.txt" -covermode=atomic ${INTEGRATION_PACKAGE}
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
install: $(BINARIES) ## install binaries
@echo "🐳 $@"
@mkdir -p $(DESTDIR)/bin
@install $(BINARIES) $(DESTDIR)/bin
uninstall:
@echo "🐳 $@"
@rm -f $(addprefix $(DESTDIR)/bin/,$(notdir $(BINARIES)))
# This only needs to be generated by hand when cutting full releases.
version/version.go:
./version/version.sh > $@