Skip to content

Commit

Permalink
Add CI script from the main tyk repo
Browse files Browse the repository at this point in the history
On top of 'go test', this now enforces 'go vet', 'gofmt' and
'goimports'.

Fixes #25.
  • Loading branch information
mvdan authored and buger committed Apr 4, 2017
1 parent dc17f8b commit bac316d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ matrix:
include:
- go: 1.7.x
- go: 1.8.x
env: LATEST_GO=true # run linters and report coverage

install:
- go install ./...

script:
- go test ./...
- ./utils/ci-test.sh
54 changes: 54 additions & 0 deletions utils/ci-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

set -e

MATRIX=(
""
)

# print a command and execute it
show() {
echo "$@" >&2
eval "$@"
}

fatal() {
echo "$@" >&2
exit 1
}

PKGS="$(go list ./... | grep -v /vendor/)"

i=0
# need to do per-pkg because go test doesn't support a single coverage
# profile for multiple pkgs
for pkg in $PKGS; do
for opts in "${MATRIX[@]}"; do
show go test -timeout 30s -v -coverprofile=test-$i.cov $opts $pkg \
|| fatal "go test errored"
let i++ || true
done
done

if [[ ! $LATEST_GO ]]; then
echo "Skipping linting and coverage report"
exit 0
fi

for opts in "${MATRIX[@]}"; do
show go vet -v $opts $PKGS || fatal "go vet errored"
done

# Includes all top-level files and dirs that don't start with a dot
# (hidden). Also excludes all of vendor/.
GOFILES=$(find * -name '*.go' -not -path 'vendor/*')

FMT_FILES="$(gofmt -s -l $GOFILES)"
if [[ -n $FMT_FILES ]]; then
fatal "Run 'gofmt -s -w' on these files:\n$FMT_FILES"
fi

IMP_FILES="$(goimports -local github.com/TykTechnologies -l $GOFILES)"
if [[ -n $IMP_FILES ]]; then
fatal "Run 'goimports -local github.com/TykTechnologies -w' on these files:\n$IMP_FILES"
fi

0 comments on commit bac316d

Please sign in to comment.