Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail Drush Deploy if Database Updates Produce a Diff Against Tracked Configuration (#5389) #5713

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Commands/core/DeployCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Consolidation\SiteAlias\SiteAlias;
use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
use Consolidation\SiteProcess\ProcessManager;
use Drush\Drupal\Commands\config\ConfigCommands;
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Drush\SiteAlias\SiteAliasManagerAwareInterface;
Expand Down Expand Up @@ -33,13 +34,31 @@ public function deploy(): void
$redispatchOptions = Drush::redispatchOptions();
$manager = $this->processManager();

// Prepare custom options for checking configuration state.
$configStatusOptions = $redispatchOptions;
$configStatusOptions['format'] = 'json';
// Record the current state of configuration.
$process = $manager->drush($self, 'config:status', [], $configStatusOptions);
$process->mustRun();
$originalConfigDiff = $process->getOutputAsJson();

$this->logger()->notice("Database updates start.");
$options = ['no-cache-clear' => true];
$process = $manager->drush($self, 'updatedb', [], $options + $redispatchOptions);
$process->mustRun($process->showRealtime());

$this->cacheRebuild($manager, $self, $redispatchOptions);

// Record the current state of configuration.
$process = $manager->drush($self, 'config:status', [], $configStatusOptions);
$process->mustRun();
$newConfigDiff = $process->getOutputAsJson();

// Check for new changes to active configuration that would be lost.
if ($originalConfigDiff !== $newConfigDiff) {
throw new \RuntimeException('Update hooks altered config that is about to be reverted during config import. Aborting.');
}

$this->logger()->success("Config import start.");
$process = $manager->drush($self, 'config:import', [], $redispatchOptions);
$process->mustRun($process->showRealtime());
Expand Down