Skip to content
Snippets Groups Projects

Switch to using sudo -E -H and pass --php to run-tests.sh.

3 unresolved threads

run-tests has a bug in how it locates php binary when called with sudo We pass $(which php) to use the current php interpreter wherever it is located.

Closes #3475974

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Jonathan Smith added 5 commits

    added 5 commits

    Compare with previous version

  • mentioned in merge request scheduler!213 (closed)

  • Jonathan Smith added 4 commits

    added 4 commits

    Compare with previous version

  • Conrad Lara added 1 commit

    added 1 commit

    Compare with previous version

  • Conrad Lara resolved all threads

    resolved all threads

  • Conrad Lara added 1 commit

    added 1 commit

    Compare with previous version

  • Conrad Lara added 1 commit

    added 1 commit

    Compare with previous version

  • 1060 1060 printf "$DIVIDER\n"
    1061 1061 fi
    1062 1062 printf "_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_TESTGROUPS=$_PHPUNIT_TESTGROUPS, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA\nPHPUNIT_OPTIONS=$PHPUNIT_OPTIONS, WHAT_TO_RUN=$WHAT_TO_RUN\n"
    1063 echo "executing: sudo -u www-data -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    1064 sudo -u www-data -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
    1063 echo "executing: sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    1064 sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
    1065 1065 elif [ "$_PHPUNIT_CONCURRENT" == "1" ]; then
    1066 1066 # if _PHPUNIT_TESTGROUPS is blank then do not add anything, because the test group will be handled by the matrix.
    1067 1067 # if _PHPUNIT_TESTGROUPS is --all then add --directory modules/custom/$CI_PROJECT_NAME
    1068 1068 # Otherwise add $_PHPUNIT_TESTGROUPS (without the --group)
    1069 1069 WHAT_TO_RUN=$([[ "$_PHPUNIT_TESTGROUPS" == "" ]] && echo "" || ([[ "$_PHPUNIT_TESTGROUPS" == "--all" ]] && echo "--directory modules/custom/$CI_PROJECT_NAME" || echo "$_PHPUNIT_TESTGROUPS"))
    1070 1070 echo "_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_TESTGROUPS=$_PHPUNIT_TESTGROUPS, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA, WHAT_TO_RUN=$WHAT_TO_RUN"
    1071 echo "executing: sudo SYMFONY_DEPRECATIONS_HELPER='$SYMFONY_DEPRECATIONS_HELPER' MINK_DRIVER_ARGS_WEBDRIVER='$MINK_DRIVER_ARGS_WEBDRIVER' -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    1071 echo "executing: sudo -u www-data -H -E php $_WEB_ROOT/core/scripts/run-tests.sh --php \"$(which php)\" --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    • Suggested change
      1071 echo "executing: sudo -u www-data -H -E php $_WEB_ROOT/core/scripts/run-tests.sh --php \"$(which php)\" --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA"
      1071 echo "executing: sudo -u www-data -H -E php $_WEB_ROOT/core/scripts/run-tests.sh --php '$(which php)' --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA"

      No need to complicate with a backslash, just use single quotes, we do that elsewhere.

    • Author Contributor

      Bash, similar to PHP, single quote means “this is a literal value that will not be expanded”

      Using single quotes in the echo would imply we are passing the literal phrase ‘$(which php)’ into run-tests.sh when we are passing the expanded value.

    • Yes OK. But it does not imply we are passing the literal phrase because in the echo statement the $(which php) gets evaluated and expanded to the actual path and this is displayed in the output. I tested it before I commented, and it shows --php '/usr/local/bin/php' I think its good to show this expanded value, so I was just simplifying the quotes.

      Edited by Jonathan Smith
    • Author Contributor

      Ah nested under a double quote already of course it would expand out and not make it though visible to the user. Fair point.

    • So, should I continue displaying the expanded value?

    • Yes the expanded value should be displayed. You can "apply suggestion" above, using this UI

    • Lavanya Talwar changed this line in version 7 of the diff

      changed this line in version 7 of the diff

    • Please register or sign in to reply
  • 47 47 test=$CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/$file
    48 48 if [ "$_PHPUNIT_CONCURRENT" == "0" ]; then
    49 49 printf "$DIVIDER\n_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA, PHPUNIT_OPTIONS=$PHPUNIT_OPTIONS\n "
    50 printf "executing: sudo -u www-data -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $test --log-junit $CI_PROJECT_DIR/junit.xml $_PHPUNIT_EXTRA\n "
    51 sudo -u www-data -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $test --log-junit $CI_PROJECT_DIR/junit.xml $_PHPUNIT_EXTRA || EXIT_CODE=$?
    50 printf "executing: sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $test --log-junit $CI_PROJECT_DIR/junit.xml $_PHPUNIT_EXTRA\n "
    51 sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $test --log-junit $CI_PROJECT_DIR/junit.xml $_PHPUNIT_EXTRA || EXIT_CODE=$?
    52 52 elif [ "$_PHPUNIT_CONCURRENT" == "1" ]; then
    53 53 printf "$DIVIDER\n_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA\n "
    54 printf "executing: sudo SYMFONY_DEPRECATIONS_HELPER='$SYMFONY_DEPRECATIONS_HELPER' MINK_DRIVER_ARGS_WEBDRIVER='$MINK_DRIVER_ARGS_WEBDRIVER' -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --color --keep-results --concurrency '32' --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html --file $test $_PHPUNIT_EXTRA\n "
    55 sudo SYMFONY_DEPRECATIONS_HELPER="$SYMFONY_DEPRECATIONS_HELPER" MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --color --keep-results --concurrency "32" --repeat "1" --sqlite "sites/default/files/.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html --file $test $_PHPUNIT_EXTRA || EXIT_CODE=$?
    54 printf "executing: sudo -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --php \"$(which php)\" --color --keep-results --concurrency '32' --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html --file $test $_PHPUNIT_EXTRA\n "
    • Suggested change
      54 printf "executing: sudo -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --php \"$(which php)\" --color --keep-results --concurrency '32' --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html --file $test $_PHPUNIT_EXTRA\n "
      54 printf "executing: sudo -u www-data -H -E php $_WEB_ROOT/core/scripts/run-tests.sh --php '$(which php)' --color --keep-results --concurrency '32' --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html --file $test $_PHPUNIT_EXTRA\n "

      Same here, swap \" to '. Also adding -H -E

      Edited by Jonathan Smith
    • Lavanya Talwar changed this line in version 7 of the diff

      changed this line in version 7 of the diff

    • Please register or sign in to reply
  • 1062 1062 printf "_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_TESTGROUPS=$_PHPUNIT_TESTGROUPS, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA\nPHPUNIT_OPTIONS=$PHPUNIT_OPTIONS, WHAT_TO_RUN=$WHAT_TO_RUN\n"
    1063 echo "executing: sudo -u www-data -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    1064 sudo -u www-data -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
    1063 echo "executing: sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    1064 sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
    1065 1065 elif [ "$_PHPUNIT_CONCURRENT" == "1" ]; then
    1066 1066 # if _PHPUNIT_TESTGROUPS is blank then do not add anything, because the test group will be handled by the matrix.
    1067 1067 # if _PHPUNIT_TESTGROUPS is --all then add --directory modules/custom/$CI_PROJECT_NAME
    1068 1068 # Otherwise add $_PHPUNIT_TESTGROUPS (without the --group)
    1069 1069 WHAT_TO_RUN=$([[ "$_PHPUNIT_TESTGROUPS" == "" ]] && echo "" || ([[ "$_PHPUNIT_TESTGROUPS" == "--all" ]] && echo "--directory modules/custom/$CI_PROJECT_NAME" || echo "$_PHPUNIT_TESTGROUPS"))
    1070 1070 echo "_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_TESTGROUPS=$_PHPUNIT_TESTGROUPS, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA, WHAT_TO_RUN=$WHAT_TO_RUN"
    1071 echo "executing: sudo SYMFONY_DEPRECATIONS_HELPER='$SYMFONY_DEPRECATIONS_HELPER' MINK_DRIVER_ARGS_WEBDRIVER='$MINK_DRIVER_ARGS_WEBDRIVER' -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    1071 echo "executing: sudo -u www-data -H -E php $_WEB_ROOT/core/scripts/run-tests.sh --php \"$(which php)\" --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat '1' --sqlite 'sites/default/files/.sqlite' --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA"
    1072 1072 vendor/bin/phpunit --version
    1073 sudo SYMFONY_DEPRECATIONS_HELPER="$SYMFONY_DEPRECATIONS_HELPER" MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat "1" --sqlite "sites/default/files/.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
    1073 sudo -H -E -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --php "$(which php)" --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat "1" --sqlite "sites/default/files/.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
    • Suggested change
      1073 sudo -H -E -u www-data php $_WEB_ROOT/core/scripts/run-tests.sh --php "$(which php)" --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat "1" --sqlite "sites/default/files/.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
      1073 sudo -u www-data -H -E php $_WEB_ROOT/core/scripts/run-tests.sh --php "$(which php)" --color --keep-results --concurrency $_CONCURRENCY_THREADS --repeat "1" --sqlite "sites/default/files/.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --xml $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest --verbose --non-html $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?

      Repeating @mondrake's earlier request "for visibility I'd rather add the -H -E params after the -u www-data"

    • Lavanya Talwar changed this line in version 7 of the diff

      changed this line in version 7 of the diff

    • Please register or sign in to reply
  • added 1 commit

    • 274b4551 - #Issue:3475974-Applied suggested changes.

    Compare with previous version

  • Lavanya Talwar added 6 commits

    added 6 commits

    • 384eee54 - 1 commit from branch project:main
    • 327f5dd5 - Switch to using sudo -E -H and pass --php to run-tests.sh.
    • 6b48be78 - Address MR/issue feedback.
    • 86c7daf1 - Update test only script.
    • c6bbee57 - Shellcheck.
    • ce0fb22b - #Issue:3475974-Applied suggested changes.

    Compare with previous version

  • Please register or sign in to reply
    Loading