diff --git a/.gitignore b/.gitignore index d872985e7..de8371fc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +.coverage/ +bin/ vendor/ _proto/*.pb.go diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..13fb3a4bc --- /dev/null +++ b/Makefile @@ -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 + diff --git a/circle.yml b/circle.yml new file mode 100644 index 000000000..2d7c7a450 --- /dev/null +++ b/circle.yml @@ -0,0 +1,31 @@ +machine: + environment: + GLIDE_VERSION: "0.10.1" + GO15VENDOREXPERIMENT: 1 + GOPATH: /usr/local/go_workspace + HOME: /home/ubuntu + IMPORT_PATH: "github.com/deis/tiller" + PATH: $HOME/go/bin:$PATH + GOROOT: $HOME/go + +dependencies: + override: + - mkdir -p $HOME/go + - wget "https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz" + - tar -C $HOME -xzf go1.6.linux-amd64.tar.gz + - go version + - go env + - sudo chown -R $(whoami):staff /usr/local + - cd $GOPATH + - mkdir -p $GOPATH/src/$IMPORT_PATH + - cd $HOME/tiller + - rsync -az --delete ./ "$GOPATH/src/$IMPORT_PATH/" + - wget "https://github.com/Masterminds/glide/releases/download/$GLIDE_VERSION/glide-$GLIDE_VERSION-linux-amd64.tar.gz" + - mkdir -p $HOME/bin + - tar -vxz -C $HOME/bin --strip=1 -f glide-$GLIDE_VERSION-linux-amd64.tar.gz + - export PATH="$HOME/bin:$PATH" GLIDE_HOME="$HOME/.glide" + - cd $GOPATH/src/$IMPORT_PATH + +test: + override: + - cd $GOPATH/src/$IMPORT_PATH && make bootstrap test diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100755 index 000000000..9d6763a1e --- /dev/null +++ b/scripts/coverage.sh @@ -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" diff --git a/scripts/validate-go.sh b/scripts/validate-go.sh new file mode 100755 index 000000000..3c3dd2ae8 --- /dev/null +++ b/scripts/validate-go.sh @@ -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}