We should create a Makefile that allows someone to clone the repo and at least do # make binaries and # make test.
Something like:
# 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 packages.
PACKAGES=$(shell go list ./... | grep -v /vendor/)
# Project binaries.
COMMANDS=actuary
BINARIES=$(addprefix bin/,$(COMMANDS))
GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)"
.PHONY: clean all fmt vet build binaries test setup coverage ci check help
.DEFAULT: default
all: check build binaries test ## run fmt, vet, lint, build the binaries and run the tests
# This only needs to be generated by hand when cutting full releases.
version/version.go:
./version/version.sh > $@
setup: ## install dependencies
@go get -u github.com/golang/lint/golint
# Depends on binaries because vet will silently fail if it can't load compiled
# imports
vet: binaries
@test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | grep -v 'timestamp_test.go' | grep -v 'exit status 1' | tee /dev/stderr)"
lint: ## run go lint
@test -z "$$(golint ./... | grep -v vendor/ | tee /dev/stderr)"
build: ## build the go packages
@go build -i -tags "${DOCKER_BUILDTAGS}" -v ${GO_LDFLAGS} ${GO_GCFLAGS} ${PACKAGES}
test: ## run test
@go test -parallel 8 -race -tags "${DOCKER_BUILDTAGS}" ${PACKAGES}
FORCE:
# Build a binary from a cmd.
bin/%: cmd/% FORCE
@go build -i -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./$<
binaries: $(BINARIES) ## build binaries
clean: ## clean up binaries
@rm -f $(BINARIES)
install: $(BINARIES) ## install binaries
@mkdir -p $(DESTDIR)/bin
@install $(BINARIES) $(DESTDIR)/bin
uninstall:
@rm -f $(addprefix $(DESTDIR)/bin/,$(notdir $(BINARIES)))
We should create a
Makefile
that allows someone to clone the repo and at least do# make binaries
and# make test
.Something like: