LionsAd / drupal_ti

Drupal - Travis Integration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different DRUPAL_TI_SIMPLETEST_GROUP depending on TRAVIS_PULL_REQUEST

yanniboi opened this issue · comments

Hi, this might be me not entirely understanding the travis test stack properly, but I have a request.

I would like to be able to run all drupal simpletests with my module enabled when I push code to a repo. This is so as to make sure that my module does not break core functionality.

As this takes hours however, I would like to only run tests that my module provides when creating pull requests, so that we don't have to spend hours waiting for tests before merging code.

Drupal_ti uses the DRUPAL_TI_SIMPLETEST_GROUP variable to tell the simpletest runner which tests to limit by, and TRAVIS_PULL_REQUEST tells me whether on not I want the runner to filter tests.

I've attempted to change the variable like this:

if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
  echo 'Scheduling all simpletests to be run.'
else
  echo 'Scheduling my_module simpletests to be run.'
  export DRUPAL_TI_SIMPLETEST_GROUP='my_module'
fi

But this doesn't seem to work as by the time the simpltest runner 'script.sh' runs, it has reset DRUPAL_TI_SIMPLETEST_GROUP to whatever is set in the .travis.yml.

Is there any way that I can achieve this without patching the runner script as part of my environment setup?

I am currently solving this issue by applying the following patch as part of my before-script tasks, but this is obviously not a stable solution as I clone the dev-master drupal_ti repo to stay up to date with changes to drupal 8 core...

diff --git a/runners/simpletest/script.sh b/runners/simpletest/script.sh
index a9f0bf9..2f5c240 100755
--- a/runners/simpletest/script.sh
+++ b/runners/simpletest/script.sh
@@ -11,6 +11,16 @@ then
         ARGS=( "${ARGS[@]}" "$DRUPAL_TI_SIMPLETEST_GROUP" )
 fi

+# Hack by yanniboi to allow different filters on pull request.
+if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
+        echo 'Scheduling all simpletests to be run.'
+        ARGS=( "${ARGS[@]}" "$DRUPAL_TI_NON_PULL_SIMPLETEST_GROUP" )
+else
+        echo 'Scheduling decoupled_auth simpletests to be run.'
+        ARGS=( "${ARGS[@]}" "$DRUPAL_TI_PULL_SIMPLETEST_GROUP" )
+fi
+
+echo ${ARGS[@]}

 cd "$DRUPAL_TI_DRUPAL_DIR"
 { php "$DRUPAL_TI_SIMPLETEST_FILE" --php $(which php) "${ARGS[@]}" || echo "1 fails"; } | tee /tmp/simpletest-result.txt

drupal_ti is module, which means you can just define a .before directory then add:

.drupal_ti/before/runners/simpletest/script.sh

and there you can change your code to use:

if [ "${TRAVIS_PULL_REQUEST}" = "false" ]
then
  echo 'Scheduling all simpletests to be run.'
  DRUPAL_TI_SIMPLETEST_GROUP="$DRUPAL_TI_NON_PULL_SIMPLETEST_GROUP"
else
  echo 'Scheduling decoupled_auth simpletests to be run.'
  DRUPAL_TI_SIMPLETEST_GROUP="$DRUPAL_TI_PULL_SIMPLETEST_GROUP"
fi

but the same should also work somewhere in travis.yml - if you source the script e.g. with '. myscript.sh'.