-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI script from the main tyk repo
On top of 'go test', this now enforces 'go vet', 'gofmt' and 'goimports'. Fixes #25.
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |