feat(Makefile): add Makefile

pull/613/head
Adam Reese 9 years ago
parent d081e39d17
commit 6092f01fac

2
.gitignore vendored

@ -1 +1,3 @@
.coverage/
bin/
vendor/ vendor/

@ -0,0 +1,44 @@
GO ?= go
PKG := $(shell glide novendor)
TAGS :=
TESTS := .
TESTFLAGS :=
LDFLAGS :=
BINARIES := helm tiller
.PHONY: all
all: build
.PHONY: build
build:
@for i in $(BINARIES); do \
$(GO) build -o ./bin/$$i -v $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$$i || exit 1; \
done
.PHONY: test
test: TESTFLAGS += -race -v
test: test-style
test: test-unit
.PHONY: test-unit
test-unit:
$(GO) test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS)
.PHONY: test-style
test-style:
@scripts/validate-go.sh
.PHONY: clean
clean:
rm -rf ./bin
.PHONY: coverage
coverage:
@scripts/coverage.sh
.PHONY: bootstrap
bootstrap:
glide install

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
COVERDIR=${COVERDIR:-.coverage}
COVERMODE=${COVERMODE:-atomic}
PACKAGES=($(go list $(glide novendor)))
if [[ ! -d "$COVERDIR" ]]; then
mkdir -p "$COVERDIR"
fi
echo "mode: ${COVERMODE}" > "${COVERDIR}/coverage.out"
for d in "${PACKAGES[@]}"; do
go test -coverprofile=profile.out -covermode="$COVERMODE" "$d"
if [ -f profile.out ]; then
sed "/mode: $COVERMODE/d" profile.out >> "${COVERDIR}/coverage.out"
rm profile.out
fi
done
go tool cover -html "${COVERDIR}/coverage.out" -o "${COVERDIR}/coverage.html"

@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
readonly reset=$(tput sgr0)
readonly red=$(tput bold; tput setaf 1)
readonly green=$(tput bold; tput setaf 2)
readonly yellow=$(tput bold; tput setaf 3)
exit_code=0
find_go_files() {
find . -type f -name "*.go" | grep -v vendor
}
hash golint 2>/dev/null || go get -u github.com/golang/lint/golint
hash go vet 2>/dev/null || go get -u golang.org/x/tools/cmd/vet
echo "==> Running golint..."
for pkg in $(glide nv); do
if golint_out=$(golint "$pkg" 2>&1); then
echo "${yellow}${golint_out}${reset}"
fi
done
echo "==> Running go vet..."
echo -n "$red"
go vet $(glide nv) 2>&1 | grep -v "^exit status " || exit_code=${PIPESTATUS[0]}
echo -n "$reset"
echo "==> Running gofmt..."
failed_fmt=$(find_go_files | xargs gofmt -s -l)
if [[ -n "${failed_fmt}" ]]; then
echo -n "${red}"
echo "gofmt check failed:"
echo "$failed_fmt"
gofmt -s -d "${failed_fmt}"
echo -n "${reset}"
exit_code=1
fi
exit ${exit_code}
Loading…
Cancel
Save