Skip to content

Commit

Permalink
ISSUE-370: composer configuration checks
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-aveiga committed Oct 1, 2024
1 parent d21f9a2 commit de7e0a9
Showing 1 changed file with 68 additions and 16 deletions.
84 changes: 68 additions & 16 deletions src/ScaffoldInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,69 @@ public static function getSubscribedEvents()
];
}

/**
* Composer configuration advice: "composer-exit-on-patch-failure": true
*
* @return void
*/
private function _checkComposerBreaksIfPatchesDoNotApply()
{
$composerExitsOnPatchFailure = $this->extra['composer-exit-on-patch-failure']
?? false;
$composerExitsOnPatchFailureBool = is_bool($composerExitsOnPatchFailure);
$condition1 = !$composerExitsOnPatchFailure ||
!$composerExitsOnPatchFailureBool;
$condition2 = $composerExitsOnPatchFailureBool
&& $composerExitsOnPatchFailure !== true;
$warn = $condition1 && $condition2;

if (!$warn) {
return;
}

$msg = 'Break Composer install if patches don\'t apply. See ';
$link = 'https://architecture.lullabot.com/adr/20220429-composer-exit-failure/';
$this->io->warning("{$msg} {$link}");
}

/**
* Composer configuration advice: "patchLevel": {"drupal/core": "-p2"}
*
* @return void
*/
private function _checkDrupalCoreComposerPatchesLevel()
{
$patchLevel = $this->extra['patchLevel']['drupal/core'] ?? false;
$patchLevelIsString = is_string($patchLevel);
$warn = (!$patchLevel || !$patchLevelIsString)
|| ($patchLevelIsString && $patchLevel != '-p2');

if (!$warn) {
return;
}

$msg = 'Configure Composer patches to Use `-p2`
as `patchLevel` for Drupal core. See ';
$link = 'https://architecture.lullabot.com/adr/20220429-composer-patchlevel/';
$this->io->warning("{$msg} {$link}");
}

/**
* Composer configuration advice: "patches-file" is not set/used.
*
* @return void
*/
private function _checkPatchesStoredInComposerJson()
{
if (!isset($this->extra['patches-file'])) {
return;
}

$msg = 'Store Composer patches configuration in `composer.json`. See ';
$link = 'https://architecture.lullabot.com/adr/20220429-composer-patches-inline/';
$this->io->warning("{$msg} {$link}");
}

/**
* Handle post install command events.
*
Expand All @@ -84,6 +147,11 @@ public function onPostInstallCmd(Event $event)
$this->installDdevCommand();
$this->installCICommands();
$this->installEnvSupport();

// Composer checks.
$this->_checkDrupalCoreComposerPatchesLevel();
$this->_checkComposerBreaksIfPatchesDoNotApply();
$this->_checkPatchesStoredInComposerJson();
}

/**
Expand Down Expand Up @@ -260,10 +328,6 @@ private function installGitlabCI(string $scaffoldPath): void {
$fs->copy("$scaffoldPath/gitlab/Common.gitlab-ci.yml", ".drainpipe/gitlab/Common.gitlab-ci.yml");
$this->io->write("🪠 [Drainpipe] .drainpipe/gitlab/Common.gitlab-ci.yml installed");
}

$fs->copy("$scaffoldPath/gitlab/Nightwatch.gitlab-ci.yml", ".drainpipe/gitlab/Nightwatch.gitlab-ci.yml");
$this->io->write("🪠 [Drainpipe] .drainpipe/gitlab/Nightwatch.gitlab-ci.yml installed");

foreach ($this->extra['drainpipe']['gitlab'] as $gitlab) {
$file = "gitlab/$gitlab.gitlab-ci.yml";
if (file_exists("$scaffoldPath/$file")) {$fs->ensureDirectoryExists('./.drainpipe/gitlab');
Expand Down Expand Up @@ -337,18 +401,6 @@ private function installGitHubActions(string $scaffoldPath): void {
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/workflows/ComposerLockDiff.yml", './.github/workflows/ComposerLockDiff.yml');
}
else if ($github === 'Security') {
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/workflows/Security.yml", './.github/workflows/Security.yml');
}
else if ($github === 'TestStatic') {
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/workflows/TestStatic.yml", './.github/workflows/TestStatic.yml');
}
else if ($github === 'TestFunctional') {
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/workflows/TestFunctional.yml", './.github/workflows/TestFunctional.yml');
}
}
}

Expand Down

0 comments on commit de7e0a9

Please sign in to comment.