Commit bc6326d6 authored by Jon Pugh's avatar Jon Pugh

Issue #2937147 by Jon Pugh: Add Composer support directly to Provision:

 - Wrap the whole thing in a check for a drush option `provision_composer_install_platforms`. If set to FALSE, don't even check for composer.json.
 - Make `provision_composer_install_command` a variable, allowing customization.
 - Rename the variable `provision_composer_install_platforms`.
parent 93f34077
......@@ -80,47 +80,50 @@ function drush_provision_drupal_pre_provision_verify() {
}
}
// Detect composer-based platform and run composer install if it has not been run yet.
// Step 1: Look for composer directory. Could be Drupal root. Could be the git repo_root.
if (provision_file()->exists(d()->root . DIRECTORY_SEPARATOR . 'composer.json')->status()) {
$composer_directory = d()->root;
}
elseif (provision_file()->exists(d()->repo_path . DIRECTORY_SEPARATOR . 'composer.json')->status()) {
$composer_directory = d()->repo_path;
}
// Step 2: Run composer install if composer.json is present.
// If drush option provision-composer-install-on-every-verify is set to
// false, only run `composer-install` if ./vendor directory is missing.
if (isset($composer_directory) && (!file_exists($composer_directory . DIRECTORY_SEPARATOR . 'vendor') || drush_get_option('provision-composer-install-on-every-verify', TRUE))) {
// @TODO: We should make this command more dynamic. For example, if we know the platform is for production, we should use --no-dev option.
// Composer Install command: Do not interact, do not show download progress.
$composer_command = 'composer install --no-interaction --no-progress';
drush_log(dt("Running command @command", array(
'@command' => $composer_command
)), 'ok');
$start = time();
// @TODO: Implement Symfony Process component for line-by-line output logging.
if (drush_shell_cd_and_exec($composer_directory, $composer_command)) {
$stop = time();
$output = implode("\n", drush_shell_exec_output());
$log_status = strpos($output, 'Warning:') === FALSE? 'success': 'warning';
drush_log($output, $log_status);
drush_log(dt(strpos($output, 'Warning:') . "Command ran successfully in @times: @command", array(
'@command' => $composer_command,
'@time' => $stop - $start,
)), $log_status);
// If drush variable provision_composer_install_platforms is not set to FALSE, run composer install.
if (drush_get_option('provision_composer_install_platforms', TRUE)) {
// Detect composer-based platform and run composer install if it has not been run yet.
// Step 1: Look for composer directory. Could be Drupal root. Could be the git repo_root.
if (provision_file()->exists(d()->root . DIRECTORY_SEPARATOR . 'composer.json')->status()) {
$composer_directory = d()->root;
}
else {
drush_log(implode("\n", drush_shell_exec_output()), 'error');
drush_set_error('DRUSH_COMPOSER_ERROR', dt('The composer command failed in @dir: @command', array(
'@dir' => $composer_directory,
'@command' => $composer_command,
)));
elseif (provision_file()->exists(d()->repo_path . DIRECTORY_SEPARATOR . 'composer.json')->status()) {
$composer_directory = d()->repo_path;
}
// Step 2: Run composer install if composer.json is present.
// If drush option provision_composer_install_platforms_verify_always is set to
// false, only run `composer-install` if ./vendor directory is missing.
if (isset($composer_directory) && (!file_exists($composer_directory . DIRECTORY_SEPARATOR . 'vendor') || drush_get_option('provision_composer_install_platforms_verify_always', TRUE))) {
// @TODO: We should make this command more dynamic. For example, if we know the platform is for production, we should use --no-dev option.
// Composer Install command: Do not interact, do not show download progress.
$composer_command = drush_get_option('provision_composer_install_command', 'composer install --no-interaction --no-progress --no-dev');
drush_log(dt("Running command @command", array(
'@command' => $composer_command
)), 'ok');
$start = time();
// @TODO: Implement Symfony Process component for line-by-line output logging.
if (drush_shell_cd_and_exec($composer_directory, $composer_command)) {
$stop = time();
$output = implode("\n", drush_shell_exec_output());
$log_status = strpos($output, 'Warning:') === FALSE? 'success': 'warning';
drush_log($output, $log_status);
drush_log(dt(strpos($output, 'Warning:') . "Command ran successfully in @times: @command", array(
'@command' => $composer_command,
'@time' => $stop - $start,
)), $log_status);
}
else {
drush_log(implode("\n", drush_shell_exec_output()), 'error');
drush_set_error('DRUSH_COMPOSER_ERROR', dt('The composer command failed in @dir: @command', array(
'@dir' => $composer_directory,
'@command' => $composer_command,
)));
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment