From 3a1f376c2970b81e0b84a6697c8f332f0bad5f6f Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Thu, 13 Aug 2015 11:37:02 +0000 Subject: [PATCH] Use tools.git --- bin/lint | 133 ----------------------------------------------------- bin/test | 43 ----------------- circle.yml | 15 +++--- 3 files changed, 8 insertions(+), 183 deletions(-) delete mode 100755 bin/lint delete mode 100755 bin/test diff --git a/bin/lint b/bin/lint deleted file mode 100755 index f3a2560f8..000000000 --- a/bin/lint +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash -# This scipt lints go files for common errors. -# -# Its runs gofmt and go vet, and optionally golint and -# gocyclo, if they are installed. -# -# With no arguments, it lints the current files staged -# for git commit. Or you can pass it explicit filenames -# (or directories) and it will lint them. -# -# To use this script automatically, run: -# ln -s ../../bin/lint .git/hooks/pre-commit - -set -eu - -function spell_check { - filename="$1" - local lint_result=0 - - if grep -iH --color=always psueod "${filename}"; then - echo "${filename}: spelling mistake" - lint_result=1 - fi - - return $lint_result -} - -function test_mismatch { - filename="$1" - package=$(grep '^package ' $filename | awk '{print $2}') - local lint_result=0 - - if [[ $package == "main" ]]; then - continue # in package main, all bets are off - fi - - if [[ $filename == *"_internal_test.go" ]]; then - if [[ $package == *"_test" ]]; then - lint_result=1 - echo "${filename}: should not be part of a _test package" - fi - else - if [[ ! $package == *"_test" ]]; then - lint_result=1 - echo "${filename}: should be part of a _test package" - fi - fi - - return $lint_result -} - -function lint_go { - filename="$1" - local lint_result=0 - - if [ -n "$(gofmt -s -l "${filename}")" ]; then - lint_result=1 - echo "${filename}: run gofmt -s -w ${filename}!" - fi - - go tool vet "${filename}" || lint_result=$? - - # golint is completely optional. If you don't like it - # don't have it installed. - if type golint >/dev/null 2>&1; then - # golint doesn't set an exit code it seems - lintoutput=$(golint "${filename}") - if [ "$lintoutput" != "" ]; then - lint_result=1 - echo "$lintoutput" - fi - fi - - # gocyclo is completely optional. If you don't like it - # don't have it installed. Also never blocks a commit, - # it just warns. - if type gocyclo >/dev/null 2>&1; then - gocyclo -over 25 "${filename}" | while read line; do - echo "${filename}": higher than 25 cyclomatic complexity - "${line}" - done - fi - - return $lint_result -} - -function lint { - filename="$1" - ext="${filename##*\.}" - local lint_result=0 - - # Don't lint deleted files - if [ ! -f "$filename" ]; then - return - fi - - # Don't lint this script or static.go - case "${filename}" in - ./bin/lint) return;; - ./app/static.go) return;; - ./coverage.html) return;; - esac - - case "$ext" in - go) lint_go "${filename}" || lint_result=1 - ;; - esac - - if [[ $filename == *"_test.go" ]]; then - test_mismatch "${filename}" || lint_result=1 - fi - - spell_check "${filename}" || lint_result=1 - - return $lint_result -} - -function lint_files { - local lint_result=0 - while read filename; do - lint "${filename}" || lint_result=1 - done - exit $lint_result -} - -function list_files { - if [ $# -gt 0 ]; then - find "$@" -type f | grep -vE '^\./\.git/' - else - git diff --cached --name-only - fi -} - -list_files "$@" | lint_files diff --git a/bin/test b/bin/test deleted file mode 100755 index b3b41153f..000000000 --- a/bin/test +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -set -eu - -GO_TEST_ARGS="-cpu 4 -timeout 10s -tags netgo" -SLOW="" -if [ $# -eq 1 ] && [ "$1" = "-slow" ]; then - GO_TEST_ARGS="$GO_TEST_ARGS -race -covermode=atomic" - SLOW="yes" -fi - -echo "mode: count" > profile.cov -fail=0 -for dir in $(find . -type f -name '*_test.go' | grep -v '^./.git/' | grep -v '^./experimental/' | grep -v '^./releases/' | xargs -n1 dirname | sort -u); do - - if [ "$SLOW" = "yes" ]; then - go get -t $dir - - if ! errcheck -ignore 'Close' $dir ; then - fail=1 - fi - - output=$(mktemp cover.XXXXXXXXXX) - GO_TEST_ARGS_RUN="$GO_TEST_ARGS -coverprofile=$output" - else - GO_TEST_ARGS_RUN="$GO_TEST_ARGS" - fi - - if ! go test $GO_TEST_ARGS_RUN $dir ; then - fail=1 - fi - - if [ "$SLOW" = "yes" ] && [ -f $output ]; then - tail -n +2 <$output >>profile.cov - rm $output - fi -done - -if [ "$SLOW" = "yes" ]; then - go tool cover -html=profile.cov -o=coverage.html -fi - -exit $fail diff --git a/circle.yml b/circle.yml index 530adc839..5fe87d6d3 100644 --- a/circle.yml +++ b/circle.yml @@ -8,6 +8,7 @@ machine: - docker environment: GOPATH: /home/ubuntu:$GOPATH + TOOLS: /home/ubuntu/src/github.com/weaveworks/tools SRCDIR: /home/ubuntu/src/github.com/weaveworks/scope PATH: $PATH:$HOME/.local/bin CLOUDSDK_CORE_DISABLE_PROMPTS: 1 @@ -18,30 +19,30 @@ machine: dependencies: cache_directories: - "~/docker" - override: + post: + - mkdir -p $TOOLS + - git clone https://github.com/weaveworks/tools.git $TOOLS - sudo apt-get update - sudo apt-get --only-upgrade install tar libpcap0.8-dev - - bin/rebuild-ui-build-image - - curl https://sdk.cloud.google.com | bash + - sudo apt-get install jq - test -z "$SECRET_PASSWORD" || bin/setup-circleci-secrets "$SECRET_PASSWORD" - post: - go get $WEAVE_REPO/... - make -C $WEAVE_ROOT testing/runner/runner - - sudo apt-get install jq - go version - go clean -i net - go install -tags netgo std - make deps - mkdir -p $(dirname $SRCDIR) - cp -r $(pwd)/ $SRCDIR + - bin/rebuild-ui-build-image test: override: - - cd $SRCDIR; ./bin/lint . + - cd $SRCDIR; $TOOLS/lint . - cd $SRCDIR; make client-test - cd $SRCDIR; make static - cd $SRCDIR; rm -f app/scope-app probe/scope-probe; make - - cd $SRCDIR; ./bin/test -slow + - cd $SRCDIR; $TOOLS/test -slow - cd $SRCDIR/experimental; make - test -z "$SECRET_PASSWORD" || (cd $SRCDIR/integration; ./gce.sh setup) - test -z "$SECRET_PASSWORD" || (cd $SRCDIR/integration; eval $(./gce.sh hosts); ./setup.sh)