Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ci: add benchmark-regression-check
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
  • Loading branch information
nodece committed Jul 22, 2020
commit cd27295683f28ffca17f5ff38b5436a6a9c7e06f
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ go:

script:
- make test
- bash ./.travis/benchmark-regressions-check.sh
58 changes: 58 additions & 0 deletions .travis/benchmark-regressions-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

# visit https://docs.travis-ci.com/user/environment-variables/#default-environment-variables for details

version=$(go version | grep -Eo '[0-9]+\.[0-9]+')

# check environment
if [[ $TRAVIS_PULL_REQUEST == "false" ]] || [[ $version != "1.14" ]] || [[ $TRAVIS != "true" ]]; then
echo "The script runs only on Travis-CI PR events with Golang 1.14"
exit 0
fi

# install jq 1.6
curl -s -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 >./jq
chmod +x ./jq

# install benchstat
go get -u golang.org/x/perf/cmd/benchstat

remote_repo="https://github.com/$TRAVIS_REPO_SLUG"

echo "git clone --single-branch --branch ""$TRAVIS_BRANCH"" ""$remote_repo"" old_repo"
git clone --single-branch --branch "$TRAVIS_BRANCH" "$remote_repo" old_repo

cd old_repo || exit 1
go test -bench=. -count=3 | tee output.txt
cd - || exit 1

go test -bench=. -count=3 | tee output.txt

cat <<EOF >body.md
The computes and compares statistics about benchmarks for ${TRAVIS_PULL_REQUEST_SHA} by [benchstat](https://github.com/golang/perf/tree/master/cmd/benchstat) on Golang 1.14:

\`\`\`
$(benchstat old_repo/output.txt output.txt | tee benchstat.log)
\`\`\`
EOF

URL="https://api.github.com/repos/$TRAVIS_REPO_SLUG/issues/$TRAVIS_PULL_REQUEST/comments"

data='{ "body": '"$(./jq -R -s <body.md)"' }'

echo "request - $URL"

res=$(curl -s \
-X POST \
"$URL" \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data "$data")

echo "$res"

url=$(echo "$res" | ./jq -r '.url')

if [[ -z $url || $url == null ]]; then
exit 1
fi