Verified Commit eba0136d authored by Dave Long's avatar Dave Long
Browse files

Issue #3476189 by mondrake, cmlara, fjgarlin, murz, longwave, andypost,...

Issue #3476189 by mondrake, cmlara, fjgarlin, murz, longwave, andypost, larowlan: [CI] Use sudo -E to execute run-tests.sh
parent 7ce1914f
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -183,7 +183,6 @@ default:
    _TARGET_PHP: "8.3-ubuntu"
    _TARGET_DB: "mysql-8"
    PERFORMANCE_TEST: $PERFORMANCE_TEST
    OTEL_COLLECTOR: $OTEL_COLLECTOR
  # Run on MR, schedule, push, parent pipeline and performance test.
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_ROOT_NAMESPACE == "project"
+5 −5
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ variables:
.run-tests: &run-tests
  script:
    # Need to pass this along directly.
    - sudo MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php ./core/scripts/run-tests.sh --color --keep-results --types "$TESTSUITE" --concurrency "$CONCURRENCY" --repeat "1" --sqlite "./sites/default/files/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html --all --ci-parallel-node-index $CI_PARALLEL_NODE_INDEX --ci-parallel-node-total $CI_PARALLEL_NODE_TOTAL
    - sudo -u www-data -E -H php ./core/scripts/run-tests.sh --color --keep-results --types "$TESTSUITE" --concurrency "$CONCURRENCY" --repeat "1" --sqlite "./sites/default/files/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html --all --ci-parallel-node-index $CI_PARALLEL_NODE_INDEX --ci-parallel-node-total $CI_PARALLEL_NODE_TOTAL

.run-repeat-class-test: &run-repeat-class-test
  script:
@@ -113,7 +113,7 @@ variables:
        echo '   "Key" to "REPEAT_TEST_CLASS" and "Value" to "Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLinkabilityTest"';
        exit 1;
      else
        sudo MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php ./core/scripts/run-tests.sh --color --keep-results --concurrency "$CONCURRENCY" --repeat "100" --sqlite "./sites/default/files/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html --class $REPEAT_TEST_CLASS
        sudo -u www-data -E -H php ./core/scripts/run-tests.sh --color --keep-results --concurrency "$CONCURRENCY" --repeat "100" --sqlite "./sites/default/files/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html --class $REPEAT_TEST_CLASS
      fi

################
@@ -164,7 +164,7 @@ variables:
    - <<: *with-chrome
  script:
    # Run a small subset of tests to prove non W3C testing still works.
    - sudo MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php ./core/scripts/run-tests.sh --color --keep-results --types "$TESTSUITE" --concurrency "$CONCURRENCY" --repeat "1" --sqlite "./sites/default/files/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html javascript
    - sudo -u www-data -E -H php ./core/scripts/run-tests.sh --color --keep-results --types "$TESTSUITE" --concurrency "$CONCURRENCY" --repeat "1" --sqlite "./sites/default/files/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html javascript

  after_script:
    - sed -i "s#$CI_PROJECT_DIR/##" ./sites/default/files/simpletest/phpunit-*.xml || true
@@ -260,7 +260,7 @@ variables:
    - chown -R www-data:www-data ./sites /var/www
    - cd core
    - corepack enable
    - sudo -u www-data yarn run test:nightwatch --workers=3
    - sudo -u www-data -E -H yarn run test:nightwatch --workers=3
  after_script:
    - cp /builds/chromedriver.log ./
  artifacts:
@@ -307,4 +307,4 @@ variables:
    - mkdir -p ./sites/simpletest ./sites/default/files ./build/logs/junit /var/www/.composer
    - chown -R www-data:www-data ./sites ./build/logs/junit ./vendor /var/www/
    - sudo -u www-data git config --global --add safe.directory $CI_PROJECT_DIR
    - sudo SIMPLETEST_BASE_URL="http://$HOSTNAME/subdirectory" SIMPLETEST_DB="$SIMPLETEST_DB" MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" OTEL_COLLECTOR="$OTEL_COLLECTOR" -u www-data ./vendor/bin/phpunit -c core --group OpenTelemetry --log-junit=./sites/default/files/simpletest/phpunit-performance.xml
    - sudo SIMPLETEST_BASE_URL="http://$HOSTNAME/subdirectory" -u www-data -E -H ./vendor/bin/phpunit -c core --group OpenTelemetry --log-junit=./sites/default/files/simpletest/phpunit-performance.xml
+21 −9
Original line number Diff line number Diff line
@@ -479,23 +479,34 @@ function simpletest_script_init() {
  $host = 'localhost';
  $path = '';
  $port = '80';
  $php = "";

  // Determine location of php command automatically, unless a command line
  // argument is supplied.
  if (!empty($args['php'])) {
    $php = $args['php'];
  }
  elseif ($php_env = getenv('_')) {
  if ($php_env = getenv('_')) {
    // '_' is an environment variable set by the shell. It contains the command
    // that was executed.
    $php = $php_env;
  }
  elseif ($sudo = getenv('SUDO_COMMAND')) {

  if ($sudo = getenv('SUDO_COMMAND')) {
    // 'SUDO_COMMAND' is an environment variable set by the sudo program.
    // Extract only the PHP interpreter, not the rest of the command.
    // This will be set if the script is run directly by sudo or if the
    // script is run under a shell started by sudo.
    if (str_contains($sudo, basename(__FILE__))) {
      // This script may have been directly run by sudo. $php may have the
      // path to sudo from getenv('_') if run with the -E option.
      // Extract what may be the PHP interpreter.
      [$php] = explode(' ', $sudo, 2);
    }
  else {
  }

  if (!empty($args['php'])) {
    // Caller has specified path to php. Override auto-detection.
    $php = $args['php'];
  }

  if ($php == "") {
    simpletest_script_print_error('Unable to automatically determine the path to the PHP interpreter. Supply the --php command line argument.');
    simpletest_script_help();
    exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
@@ -1161,7 +1172,7 @@ function place_tests_into_bins(array $tests, int $bin_count) {
 * Initialize the reporter.
 */
function simpletest_script_reporter_init() {
  global $args, $test_list, $results_map;
  global $args, $test_list, $results_map, $php;

  $results_map = [
    'pass' => 'Pass',
@@ -1171,6 +1182,7 @@ function simpletest_script_reporter_init() {

  echo "\n";
  echo "Drupal test run\n";
  echo "Using PHP Binary: $php\n";
  echo "---------------\n";
  echo "\n";