@@ -16,12 +16,38 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
1616WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR / wordpress-tests-lib}
1717WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR / wordpress/ }
1818
19+ RETRIES=5
20+ SLEEP=10
21+
22+ # retry_run: run a command and retry on failure
23+ retry_run () {
24+ local n=0
25+ until " $@ " ; do
26+ n=$(( n+ 1 ))
27+ if [ $n -ge $RETRIES ]; then
28+ echo " Command failed after $RETRIES attempts: $@ " >&2
29+ return 1
30+ fi
31+ echo " Command failed. Retrying in $SLEEP seconds... ($n /$RETRIES )" >&2
32+ sleep $SLEEP
33+ done
34+ return 0
35+ }
36+
1937if [[ $WP_VERSION =~ ^[0-9]+\. [0-9]+$ ]]; then
2038 WP_TESTS_TAG=" branches/$WP_VERSION "
2139elif [[ $WP_VERSION == ' trunk' ]]; then
2240 WP_TESTS_TAG=" trunk"
2341else
24- LATEST_VERSION=$( curl -s https://api.wordpress.org/core/version-check/1.1/ | tail -1 )
42+ # fetch the latest version with retries
43+ TMP_VER_FILE=$( mktemp)
44+ if ! retry_run curl -sSL https://api.wordpress.org/core/version-check/1.1/ -o " $TMP_VER_FILE " ; then
45+ echo " Latest WordPress version could not be fetched after $RETRIES attempts" >&2
46+ rm -f " $TMP_VER_FILE "
47+ exit 1
48+ fi
49+ LATEST_VERSION=$( tail -1 " $TMP_VER_FILE " )
50+ rm -f " $TMP_VER_FILE "
2551 if [[ -z " $LATEST_VERSION " ]]; then
2652 echo " Latest WordPress version could not be found"
2753 exit 1
@@ -35,19 +61,22 @@ install_wp_and_test_suite() {
3561 # setup up WordPress
3662 if [ ! -d $WP_CORE_DIR ]; then
3763 mkdir -p $WP_CORE_DIR
38- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /src/ $WP_CORE_DIR
64+ # Retry svn checkout in case of transient network issues
65+ retry_run svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /src/ $WP_CORE_DIR
3966 fi
4067
4168 # set up testing suite if it doesn't yet exist
4269 if [ ! -d $WP_TESTS_DIR ]; then
4370 # set up testing suite
4471 mkdir -p $WP_TESTS_DIR
45- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
46- svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
72+ # Retry svn checkouts for includes and data
73+ retry_run svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/includes/ $WP_TESTS_DIR /includes
74+ retry_run svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG} /tests/phpunit/data/ $WP_TESTS_DIR /data
4775 fi
4876
4977 if [ ! -f wp-tests-config.php ]; then
50- curl -s https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php > " $WP_TESTS_DIR " /wp-tests-config.php
78+ # download wp-tests-config-sample.php with retries
79+ retry_run curl -sSL https://develop.svn.wordpress.org/${WP_TESTS_TAG} /wp-tests-config-sample.php -o " $WP_TESTS_DIR /wp-tests-config.php"
5180 # remove all forward slashes in the end
5281 WP_CORE_DIR=$( echo $WP_CORE_DIR | sed " s:/\+$::" )
5382 sed -i " s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR /':" " $WP_TESTS_DIR " /wp-tests-config.php
@@ -81,4 +110,4 @@ install_db() {
81110}
82111
83112install_wp_and_test_suite
84- install_db
113+ install_db
0 commit comments