2015-08-17 16:30:35 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# This is the Telegraf CircleCI test script. Using this script allows total control
|
|
|
|
# the environment in which the build and test is run, and matches the official
|
|
|
|
# build process for InfluxDB.
|
|
|
|
|
|
|
|
BUILD_DIR=$HOME/telegraf-build
|
2015-08-20 22:09:09 +00:00
|
|
|
VERSION=`git describe --always --tags`
|
2015-08-17 16:30:35 +00:00
|
|
|
|
|
|
|
# Executes the given statement, and exits if the command returns a non-zero code.
|
|
|
|
function exit_if_fail {
|
|
|
|
command=$@
|
|
|
|
echo "Executing '$command'"
|
2015-08-20 22:09:09 +00:00
|
|
|
eval $command
|
2015-08-17 16:30:35 +00:00
|
|
|
rc=$?
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
echo "'$command' returned $rc."
|
|
|
|
exit $rc
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-10-16 18:54:05 +00:00
|
|
|
# Check that go fmt has been run.
|
|
|
|
function check_go_fmt {
|
|
|
|
fmtcount=`git ls-files | grep '.go$' | grep -v Godep | xargs gofmt -l 2>&1 | wc -l`
|
|
|
|
if [ $fmtcount -gt 0 ]; then
|
|
|
|
echo "run 'go fmt ./...' to format your source code."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-08-17 16:30:35 +00:00
|
|
|
# Set up the build directory, and then GOPATH.
|
|
|
|
exit_if_fail mkdir $BUILD_DIR
|
|
|
|
export GOPATH=$BUILD_DIR
|
2015-10-18 20:41:09 +00:00
|
|
|
# Turning off GOGC speeds up build times
|
|
|
|
export GOGC=off
|
2015-08-17 16:30:35 +00:00
|
|
|
export PATH=$GOPATH/bin:$PATH
|
2016-01-20 18:57:35 +00:00
|
|
|
exit_if_fail mkdir -p $GOPATH/src/github.com/influxdata
|
2015-08-17 16:30:35 +00:00
|
|
|
|
|
|
|
# Dump some test config to the log.
|
|
|
|
echo "Test configuration"
|
|
|
|
echo "========================================"
|
|
|
|
echo "\$HOME: $HOME"
|
|
|
|
echo "\$GOPATH: $GOPATH"
|
|
|
|
echo "\$CIRCLE_BRANCH: $CIRCLE_BRANCH"
|
|
|
|
|
|
|
|
# Move the checked-out source to a better location
|
2016-01-20 18:57:35 +00:00
|
|
|
exit_if_fail mv $HOME/telegraf $GOPATH/src/github.com/influxdata
|
|
|
|
exit_if_fail cd $GOPATH/src/github.com/influxdata/telegraf
|
2015-08-17 16:30:35 +00:00
|
|
|
|
2015-10-16 18:54:05 +00:00
|
|
|
# Verify that go fmt has been run
|
|
|
|
check_go_fmt
|
|
|
|
|
2015-10-18 20:41:09 +00:00
|
|
|
# Build the code
|
2015-10-28 17:59:19 +00:00
|
|
|
exit_if_fail make
|
2015-08-17 16:30:35 +00:00
|
|
|
|
|
|
|
# Run the tests
|
2015-12-08 23:18:23 +00:00
|
|
|
exit_if_fail go vet ./...
|
2015-10-27 22:22:21 +00:00
|
|
|
exit_if_fail make docker-run-circle
|
2016-08-24 07:41:12 +00:00
|
|
|
# Sleep for OpenTSDB leadership election, aerospike cluster, etc.
|
|
|
|
exit_if_fail sleep 60
|
2015-12-04 18:44:56 +00:00
|
|
|
exit_if_fail go test -race ./...
|
2015-08-17 16:30:35 +00:00
|
|
|
|
2015-08-20 22:09:09 +00:00
|
|
|
# Simple Integration Tests
|
|
|
|
# check that version was properly set
|
2016-02-18 04:57:33 +00:00
|
|
|
exit_if_fail "telegraf -version | grep $VERSION"
|
2015-08-20 22:09:09 +00:00
|
|
|
# check that one test cpu & mem output work
|
2015-08-20 15:55:19 +00:00
|
|
|
tmpdir=$(mktemp -d)
|
2016-02-18 04:57:33 +00:00
|
|
|
telegraf -sample-config > $tmpdir/config.toml
|
|
|
|
exit_if_fail telegraf -config $tmpdir/config.toml \
|
2016-01-07 20:39:43 +00:00
|
|
|
-test -input-filter cpu:mem
|
2015-08-20 15:55:19 +00:00
|
|
|
|
2016-03-08 10:42:31 +00:00
|
|
|
cat $GOPATH/bin/telegraf | gzip > $CIRCLE_ARTIFACTS/telegraf.gz
|
2016-07-12 21:31:08 +00:00
|
|
|
go build -o telegraf-race -race -ldflags "-X main.version=${VERSION}-RACE" cmd/telegraf/telegraf.go
|
|
|
|
cat telegraf-race | gzip > $CIRCLE_ARTIFACTS/telegraf-race.gz
|
2016-02-02 01:32:01 +00:00
|
|
|
|
2016-02-20 18:52:43 +00:00
|
|
|
eval "git describe --exact-match HEAD"
|
|
|
|
if [ $? -eq 0 ]; then
|
2016-10-25 12:17:27 +00:00
|
|
|
# install fpm (packaging dependency)
|
|
|
|
exit_if_fail gem install fpm
|
|
|
|
# install boto & rpm (packaging & AWS dependencies)
|
|
|
|
exit_if_fail sudo apt-get install -y rpm python-boto
|
2016-02-21 23:00:41 +00:00
|
|
|
unset GOGC
|
2016-02-20 18:52:43 +00:00
|
|
|
tag=$(git describe --exact-match HEAD)
|
|
|
|
echo $tag
|
2016-11-03 17:07:25 +00:00
|
|
|
exit_if_fail ./scripts/build.py --release --package --platform=all --arch=all --upload --bucket=dl.influxdata.com/telegraf/releases
|
2016-02-20 18:52:43 +00:00
|
|
|
mv build $CIRCLE_ARTIFACTS
|
|
|
|
fi
|