Skip to content
Snippets Groups Projects
Commit 80514f0d authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3409491 by tedbow: Add handling of the Composer dependencies to the conversion script

parent 9405be2e
No related branches found
No related tags found
1 merge request!1001Resolve #3409491 "Gitlab"
......@@ -29,9 +29,9 @@ class ConverterCommand extends Command {
private string $core_dir;
private string $core_branch;
private string|null $core_branch;
private string $contrib_branch;
private string|null $contrib_branch;
private bool $package_manager_only;
......@@ -43,6 +43,20 @@ class ConverterCommand extends Command {
private bool $skipCoreChecks;
/**
* {@inheritdoc}
*/
protected function configure() {
$this->addArgument('core_dir', InputArgument::REQUIRED, 'The path to the root of Drupal Core');
$this->addArgument('core_branch', InputArgument::OPTIONAL, 'The core merge request branch');
$this->addArgument('contrib_branch', InputArgument::OPTIONAL, 'The contrib branch to switch to', '3.0.x');
$this->addOption('package_manager_only', NULL, InputOption::VALUE_NONE, 'Only convert package manager');
$this->addOption('core_target_branch', NULL, InputOption::VALUE_REQUIRED, 'The core target branch', '11.x');
$this->addOption('skip_core_checks', NULL, InputOption::VALUE_NONE, 'Skip core checks');
$this->addOption('no_commit', NULL, InputOption::VALUE_NONE, 'Do not make commit');
$this->addOption('gitlabci', NULL, InputOption::VALUE_NONE, 'Run in Gitlab CI');
}
/**
* {@inheritdoc}
*/
......@@ -55,28 +69,46 @@ class ConverterCommand extends Command {
$this->contrib_dir = realpath(__DIR__ . '/../..');
$this->skipCoreChecks = $input->getOption('skip_core_checks');
$this->no_commit = $input->getOption('no_commit');
$this->gitlabci = $input->getOption('gitlabci');
if (!$this->gitlabci) {
if (empty($this->core_branch)) {
throw new \Exception("core_branch is required if not on gitlabci");
}
}
else {
if (!empty($this->core_branch)) {
throw new \Exception("branches are not allowed on gitlabci");
}
}
// Esnure core_dir is a directory.
if (!is_dir($this->core_dir)) {
throw new \Exception("$this->core_dir is not a directory.");
}
// Switch to core_target_branch to ensure it is clean.
chdir($this->core_dir);
static::switchToBranch($this->core_target_branch);
// Git pull to ensure we are up to date.
static::executeCommand('git pull');
// change back the previous directory.
chdir($this->contrib_dir);
// Ensure we are on the correct branches.
static::switchToBranches($this->core_dir, $this->core_branch, $this->contrib_branch);
// Switch to the core directory and checkout the files and folders that this
// conversion script will automatically update based on our composer.json
// file and our dictionary.txt file.
chdir($this->core_dir);
static::executeCommand("git checkout {$this->core_target_branch} -- composer.json");
static::executeCommand("git checkout {$this->core_target_branch} -- composer.lock");
static::executeCommand("git checkout {$this->core_target_branch} -- composer");
static::executeCommand("git checkout {$this->core_target_branch} -- core/composer.json");
static::executeCommand("git checkout {$this->core_target_branch} -- core/misc/cspell/dictionary.txt");
if ($this->gitlabci) {
$this->no_commit = TRUE;
$this->skipCoreChecks = TRUE;
}
else {
// Ensure the core directory is clean.
static::switchToBranch($this->core_target_branch);
// Git pull to ensure we are up to date.
static::executeCommand('git pull');
// change back the previous directory.
chdir($this->contrib_dir);
// Ensure we are on the correct branches.
static::switchToBranches($this->core_dir, $this->core_branch, $this->contrib_branch);
// Switch to the core directory and checkout the files and folders that this
// conversion script will automatically update based on our composer.json
// file and our dictionary.txt file.
chdir($this->core_dir);
static::executeCommand("git checkout {$this->core_target_branch} -- composer.json");
static::executeCommand("git checkout {$this->core_target_branch} -- composer.lock");
static::executeCommand("git checkout {$this->core_target_branch} -- composer");
static::executeCommand("git checkout {$this->core_target_branch} -- core/composer.json");
static::executeCommand("git checkout {$this->core_target_branch} -- core/misc/cspell/dictionary.txt");
}
// Switch to the core directory and require all of the packages there are in
// this module's composer.json require section.
......@@ -121,19 +153,6 @@ class ConverterCommand extends Command {
}
}
/**
* {@inheritdoc}
*/
protected function configure() {
$this->addArgument('core_dir', InputArgument::REQUIRED, 'The path to the root of Drupal Core');
$this->addArgument('core_branch', InputArgument::REQUIRED, 'The core merge request branch');
$this->addArgument('contrib_branch', InputArgument::OPTIONAL, 'The contrib branch to switch to', '3.0.x');
$this->addOption('package_manager_only', NULL, InputOption::VALUE_NONE, 'Only convert package manager');
$this->addOption('core_target_branch', NULL, InputOption::VALUE_REQUIRED, 'The core target branch', '11.x');
$this->addOption('skip_core_checks', NULL, InputOption::VALUE_NONE, 'Skip core checks');
$this->addOption('no_commit', NULL, InputOption::VALUE_NONE, 'Do not make commit');
}
/**
* Prints message.
*
......@@ -472,7 +491,7 @@ class ConverterCommand extends Command {
chdir($core_dir);
// Make sure ALL files are committed, including the core/modules/package_manager/tests/fixtures/fake_site/core directory!
shell_exec('git add -f core/modules/package_manager');
shell_exec('git add core');
shell_exec('git add .');
shell_exec("git commit -m 'Contrib: $message - https://git.drupalcode.org/project/automatic_updates/-/commit/$hash'");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment