Skip to content

Commit

Permalink
Rerun failed tests once in CI (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slavek Kabrda authored Jun 9, 2020
1 parent 67aa4ff commit 701368e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.travis.yml
git_push.sh
gotestsum.json
coverage.txt
.env*

Expand Down
21 changes: 17 additions & 4 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env sh
set -e
echo "Ensuring all dependencies are present in LICENSE-3rdparty.csv ..."
go mod tidy
ALL_DEPS=`cat go.sum | awk '{print $1}' | uniq | sort | sed "s|^\(.*\)|go.sum,\1,|"`
DEPS_NOT_FOUND=""
for one_dep in `echo $ALL_DEPS`; do
set +e
cat LICENSE-3rdparty.csv | grep "$one_dep" > /dev/null 2>&1
if [ $? -ne 0 ]; then
DEPS_NOT_FOUND="${DEPS_NOT_FOUND}\n${one_dep}<LICENSE>,<COPYRIGHT>"
fi
set -e
done
if [ -n "$DEPS_NOT_FOUND" ]; then
echo "Some dependencies were not found in LICENSE-3rdparty.csv, please add: $DEPS_NOT_FOUND"
Expand All @@ -28,5 +25,21 @@ GO111MODULE=on go get -u gotest.tools/[email protected]
cd -

golint ./...
gotestsum --format testname -- -coverpkg=$(go list ./... | grep -v /test | paste -sd "," -) -coverprofile=coverage.txt -covermode=atomic -v $(go list ./...)
declare -i RESULT=0
gotestsum --jsonfile gotestsum.json --format testname -- -coverpkg=$(go list ./... | grep -v /test | paste -sd "," -) -coverprofile=coverage.txt -covermode=atomic -v $(go list ./...)
RESULT+=$?
if [ "$CI" == "true" -a "$RESULT" -ne 0 ]; then
RESULT=0
echo "\n============= Rerunning failed tests =============\n"
# NOTE: since `go test` (and `gotestsum`) don't allow specifying multiple different test cases
# from different test modules with `-run`, we run them one by one in form of:
# gotestsum <arguments> github.com/DataDog/datadog-api-client-go/tests/api/v<version>/datadog -run ^TestCaseName$
while read -r i ; do
gotestsum --format testname -- -v $i
RESULT+=$?
done <<EOF
`cat gotestsum.json | jq -s -r -c '.[] | select(.Action=="fail") | select (.Test!=null) | "\(.Package) -run ^\(.Test)$"'`
EOF
fi
go mod tidy
exit $RESULT

0 comments on commit 701368e

Please sign in to comment.