66# work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
77
88set -u
9- set -x
109
1110if [ $# -ne 2 ]; then
1211 echo " Usage: $0 <test-coordinates> <versions-json-array>"
@@ -23,43 +22,59 @@ VERSIONS_JSON="${VERSIONS_JSON%"${VERSIONS_JSON##*[!\']}"}"
2322
2423# Parse versions with jq
2524readarray -t VERSIONS < <( echo " $VERSIONS_JSON " | jq -r ' .[]' )
25+ export DELIMITER=" ========================================================================================"
2626
27- for VERSION in " ${VERSIONS[@]} " ; do
28- # check if javac works for the new version
29- GVM_TCK_LV=" $VERSION " ./gradlew clean javac -Pcoordinates=" $TEST_COORDINATES "
30- RESULT=$?
31- if [ " $RESULT " -ne 0 ]; then
32- echo " FAILED [javac compile]:$VERSION "
33- break
34- fi
27+ run_multiple_attempts () {
28+ local stage=" $1 "
29+ local max_attempts=" $2 "
30+ local gradle_command=" $3 "
31+
32+ echo " $DELIMITER "
33+ echo " $TEST_COORDINATES :$VERSION stage $stage "
34+ echo " $DELIMITER "
35+
36+ local attempt=0
37+ local result=0
3538
36- # check if native-image can be built
37- GVM_TCK_LV=" $VERSION " ./gradlew clean nativeTestCompile -Pcoordinates=" $TEST_COORDINATES "
38- RESULT=$?
39- if [ " $RESULT " -ne 0 ]; then
40- echo " FAILED [native-image build]:$VERSION "
41- break
39+ while [ $attempt -lt " $max_attempts " ]; do
40+ local cmd_str=" GVM_TCK_LV=\" $VERSION \" ./gradlew clean $gradle_command -Pcoordinates=\" $TEST_COORDINATES \" "
41+ if [ $attempt -gt 0 ]; then
42+ echo " Re-running stage '$stage ' (attempt $(( attempt + 1 )) /$max_attempts )"
4243 fi
4344
44- echo " Running test with GVM_TCK_LV=$VERSION and coordinates=$TEST_COORDINATES "
45- GVM_TCK_LV=" $VERSION " ./gradlew test -Pcoordinates=" $TEST_COORDINATES "
46- RESULT=$?
47- ATTEMPTS=1
48-
49- # maybe we failed because the test was flaky => try two more times to be sure
50- while [ " $RESULT " -ne 0 ] && [ $ATTEMPTS -le 2 ]; do
51- echo " Re-running the test with GVM_TCK_LV=$VERSION and coordinates=$TEST_COORDINATES "
52- GVM_TCK_LV=" $VERSION " ./gradlew clean test -Pcoordinates=" $TEST_COORDINATES "
53- RESULT=$?
54- ATTEMPTS=$(( ATTEMPTS + 1 ))
45+ eval " $cmd_str "
46+ result=$?
47+
48+ if [ " $result " -eq 0 ]; then
49+ return 0
50+ fi
51+
52+ attempt=$(( attempt + 1 ))
5553 done
5654
57- if [ " $RESULT " -eq 0 ]; then
58- echo " PASSED:$VERSION "
59- else
60- echo " FAILED [native-image run]:$VERSION "
55+ echo " FAILED [$stage ][$VERSION ][$cmd_str ]"
56+ return $result
57+ }
58+
59+ for VERSION in " ${VERSIONS[@]} " ; do
60+ echo " $DELIMITER "
61+ echo " Testing $TEST_COORDINATES :$VERSION "
62+ echo " $DELIMITER "
63+
64+
65+ if ! run_multiple_attempts " javac compile" 1 javac; then
66+ break
67+ fi
68+
69+ if ! run_multiple_attempts " native-image build" 1 nativeTestCompile; then
6170 break
6271 fi
72+
73+ if ! run_multiple_attempts " native-image run" 3 test ; then
74+ break
75+ fi
76+
77+ echo " PASSED:$VERSION "
6378done
6479
6580exit 0
0 commit comments