consolidation / robo

Modern task runner for PHP
http://robo.li
Other
2.66k stars 305 forks source link

Robo discards .env in taskExec() #1148

Closed hudri closed 1 year ago

hudri commented 1 year ago

Steps to reproduce

What did you do?

Providing environment variables with vlucas/phpdotenv Autoloading .env file similar to drupal-composer/drupal-project

Expected behavior

$_ENV should be available in all scripts executed by Robo

Actual behavior

$_ENV is not available in Drush launched through Robo

RoboFile.php

  function test(ConsoleIO $io) {
    $this->_exec("echo \$DB_NAME");
    $this->_exec("./vendor/bin/drush st");
  }

Drupal settings.php

$databases['default']['default'] = array (
  'database' => $_ENV['DB_NAME'],
  'username' => $_ENV['DB_USER'],
  'password' => $_ENV['DB_PASS'],
  /* etc... */
);

First line correctly outputs the DB_NAME But drush output is DB name : (same for all other .env DB credentials) Any advanced drush commands using the DB credentials from the .env file fail with a message like Command cache:rebuild was not found. Drush was unable to query the database.

Same command directly launched from Bash respect the .env from the autoloader Bash:

user@~/composer_root: ./vendor/bin/drush st

output DB name : MY_DBNAME_FROM_DOTENV

System Configuration

Composer 2.5.8 Robo 4.0.6 Drush 12.1.2.0 PHP 8.1.21 on Fedora

hudri commented 1 year ago

Resolved, was a local mis-configuration, had an incorrect "variables_order" setting in php.ini