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

Improve logic around major versions #379

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions web/modules/custom/simplytest_tugboat/src/InstanceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ public function launchInstance($submission) {
$project_result = $project_storage->loadByProperties(['shortname' => $submission['project']['shortname']]);
$project = reset($project_result);


$project_version = $submission['project']['version'];
[$major_version, ,] = explode('.', $submission['drupalVersion']);
[$major_version, ] = explode('.', $submission['drupalVersion'], 2);

$additional_projects = array_map(static function(array $data) use ($project_storage) {
$project_result = $project_storage->loadByProperties(['shortname' => $data['shortname']]);
Expand All @@ -148,7 +147,7 @@ public function launchInstance($submission) {
'additionals' => $additional_projects,
'instance_id' => Crypt::randomBytesBase64(),
'hash' => Crypt::randomBytesBase64(),
'major_version' => $major_version,
'major_version' => (int) $major_version,
];

// Make the context and write the record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,11 @@
*/
final class PreviewConfigGenerator {

/**
* The one click demo manager.
*
* @var \Drupal\simplytest_ocd\OneClickDemoPluginManager
*/
private $oneClickDemoManager;

/**
* Constructs a new PreviewConfigGenerator object.
*
* @param \Drupal\simplytest_ocd\OneClickDemoPluginManager $one_click_demo_manager
* The one click demo manager.
*/
public function __construct(OneClickDemoPluginManager $one_click_demo_manager) {
public function __construct(
// @todo what if all builds were a plugin – so D7, D8, D9, Umami, Commerce?
$this->oneClickDemoManager = $one_click_demo_manager;
private readonly OneClickDemoPluginManager $oneClickDemoManager
) {
}

/**
Expand All @@ -42,15 +31,12 @@ public function __construct(OneClickDemoPluginManager $one_click_demo_manager) {
public function generate(array $parameters): array {
// @todo make these configurable in #3236528
// @see https://www.drupal.org/project/simplytest/issues/
if ($parameters['major_version'] === '10') {
$image_name = 'tugboatqa/php:8.1-apache';
}
elseif ($parameters['major_version'] === '9') {
$image_name = 'tugboatqa/php:7.4-apache';
}
else {
$image_name = 'tugboatqa/php:7.4-apache';
}
$image_name = match($parameters['major_version']) {
7, 8 => 'tugboatqa/php:7.4-apache',
9 => 'tugboatqa/php:8.1-apache',
10 => 'tugboatqa/php:8.2-apache',
default => 'tugboatqa/php:apache'
};

// Rename drupal to core so that it becomes drupal/core as a package name.
// Have core version match the selected project version, as they user may
Expand All @@ -74,9 +60,10 @@ public function generate(array $parameters): array {
$this->getPatchingCommands($parameters),
];

if(in_array($parameters['major_version'], ['10', '9'])) {
if ($parameters['major_version'] > 8) {
$build_commands[] = ['cd stm && composer update --no-ansi'];
} else if ($parameters['major_version'] == '8') {
}
else if ($parameters['major_version'] === 8) {
$build_commands[] = ['cd "${DOCROOT}" && composer update --no-ansi'];
}

Expand Down Expand Up @@ -163,7 +150,7 @@ public function oneClickDemo(string $demo_id, array $parameters): array {

private function getSetupCommands(array $parameters) {
$commands = [];
if ($parameters['major_version'] === '10' || $parameters['major_version'] === '9') {
if ($parameters['major_version'] >= 9) {
$commands[] = 'rm -rf "${DOCROOT}"';
$commands[] = sprintf('composer -n create-project drupal/recommended-project:%s stm --no-install', $parameters['drupal_core_version']);
$commands[] = 'cd stm && composer config minimum-stability dev';
Expand All @@ -181,7 +168,7 @@ private function getSetupCommands(array $parameters) {
$commands[] = 'cd stm && composer require --no-update drush/drush';
$commands[] = 'ln -snf "${TUGBOAT_ROOT}/stm/web" "${DOCROOT}"';
}
else if ($parameters['major_version'] === '7' || $parameters['major_version'] === '8') {
else if ($parameters['major_version'] === 7 || $parameters['major_version'] === 8) {
$commands[] = 'cd "${DOCROOT}" && git config core.fileMode false';
$commands[] = 'cd "${DOCROOT}" && git fetch --all';

Expand All @@ -192,6 +179,9 @@ private function getSetupCommands(array $parameters) {
$commands[] = sprintf('cd "${DOCROOT}" && git reset --hard %s', $parameters['drupal_core_version']);
}
}
else {
// @todo log something if unknown.
}

return $commands;
}
Expand All @@ -203,13 +193,13 @@ private function getDownloadCommands(array $parameters) {
$is_core = $parameters['project_type'] === ProjectTypes::CORE;
$is_distro = $parameters['project_type'] === ProjectTypes::DISTRO;

if ($parameters['major_version'] === '10' || $parameters['major_version'] === '9') {
if ($parameters['major_version'] >= 9) {
$commands[] = sprintf('cd stm && composer require drupal/%s:%s --no-update', $parameters['project'], $this->getComposerCompatibleVersionString($parameters['project_version']));
foreach ($parameters['additionals'] as $additional) {
$commands[] = sprintf('cd stm && composer require drupal/%s:%s --no-update', $additional['shortname'], $this->getComposerCompatibleVersionString($additional['version']));
}
}
else if ($parameters['major_version'] === '8') {
else if ($parameters['major_version'] === 8) {
$commands[] = 'cd "${DOCROOT}" && composer require zaporylie/composer-drupal-optimizations:^1.0 --no-update';
$commands[] = 'cd "${DOCROOT}" && composer install --no-ansi';
if (!$is_core) {
Expand All @@ -219,7 +209,7 @@ private function getDownloadCommands(array $parameters) {
$commands[] = sprintf('cd "${DOCROOT}" && composer require drupal/%s:%s --no-update', $additional['shortname'], $this->getComposerCompatibleVersionString($additional['version']));
}
}
else if ($parameters['major_version'] === '7') {
else if ($parameters['major_version'] === 7) {
// @todo this should probably be removed, but it is kept for BC during the
// initial refactor (removing should fix distro instances)
// @note Drupal 7 + distro might be too hard.
Expand Down Expand Up @@ -294,7 +284,7 @@ private function getPatchingCommands(array $parameters) {
}
// perform patching conditionally for major drupal version.
switch ($parameters['major_version']) {
case '7':
case 7:
// Patch Drupal 7 to automatically redirect to the installer.
if ($parameters['perform_install'] === FALSE) {
$commands[] = $this->getLegacyPatchCommand(ProjectTypes::CORE, '', 'https://www.drupal.org/files/issues/2019-12-19/3077423-11.patch');
Expand All @@ -309,7 +299,7 @@ private function getPatchingCommands(array $parameters) {
}
break;
default:
$composerWorkingDir = $parameters['major_version'] !== '8' ? 'stm' : '"${DOCROOT}"';
$composerWorkingDir = $parameters['major_version'] !== 8 ? 'stm' : '"${DOCROOT}"';
$commands[] = 'composer global config --no-interaction allow-plugins.szeidler/composer-patches-cli true';
$commands[] = 'composer global config --no-interaction allow-plugins.cweagans/composer-patches true';
$commands[] = 'composer global require szeidler/composer-patches-cli:~1.0';
Expand Down Expand Up @@ -344,7 +334,7 @@ private function getInstallingCommands(array $parameters): array {

// Provide a hash salt so that installation begins automatically.
// @see install_begin_request
if ($parameters['major_version'] === '10' || $parameters['major_version'] === '9' || $parameters['major_version'] === '8') {
if ($parameters['major_version'] >= 8) {
$commands[] = 'echo "\$settings[\'hash_salt\'] = \'JzbemMqk0y1ALpbGBWhz8N_p9mr7wyYm_AQIpkxH1y-uSIGNTb5EnDwhJygBCyRKJhAOkQ1d7Q\';" >> ${DOCROOT}/sites/default/settings.php';
$commands[] = 'echo "\$settings[\'config_sync_directory\'] = \'sites/default/files/sync\';" >> ${DOCROOT}/sites/default/settings.php';
$commands[] = 'echo \'$settings["file_private_path"] = "sites/default/files/private";\' >> ${DOCROOT}/sites/default/settings.php';
Expand All @@ -363,7 +353,7 @@ private function getInstallingCommands(array $parameters): array {
$install_profile = $parameters['project'];
}

if ($parameters['major_version'] === '10' || $parameters['major_version'] === '9') {
if ($parameters['major_version'] >= 9) {
$commands[] = sprintf('cd "${DOCROOT}" && ../vendor/bin/drush si %s --db-url=mysql://tugboat:tugboat@mysql:3306/tugboat --account-name=admin --account-pass=admin -y', $install_profile);
// Enable verbose error reporting.
$commands[] = 'cd "${DOCROOT}" && ../vendor/bin/drush config-set system.logging error_level verbose -y';
Expand Down Expand Up @@ -391,9 +381,9 @@ private function getInstallingCommands(array $parameters): array {
}
}
}
else if ($parameters['major_version'] === '7' || $parameters['major_version'] === '8') {
else if ($parameters['major_version'] === 7 || $parameters['major_version'] === 8) {
$commands[] = sprintf('drush -r "${DOCROOT}" si %s --account-name=admin --account-pass=admin -y', $install_profile);
if ($parameters['major_version'] === '8') {
if ($parameters['major_version'] === 8) {
$commands[] = 'drush -r "${DOCROOT}" config-set system.logging error_level verbose -y';
}
if (!$is_distro && !$is_core) {
Expand All @@ -403,8 +393,11 @@ private function getInstallingCommands(array $parameters): array {
$commands[] = sprintf('drush -r "${DOCROOT}" en %s -y', $additional['shortname']);
}
}
else {
// @todo do something to note unrecognized core version.
}

if ($parameters['major_version'] === '7') {
if ($parameters['major_version'] === 7) {
$commands[] = 'cd "${DOCROOT}" && echo \'$conf["file_private_path"] = "sites/default/files/private";\' >> sites/default/settings.php';
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testLaunchInstance(): void {
'config' => [
'services' => [
'php' => [
'image' => 'tugboatqa/php:7.4-apache',
'image' => 'tugboatqa/php:8.1-apache',
'default' => true,
'depends' => 'mysql',
'commands' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '10',
'major_version' => 10,
],
[
'php' => [
'image' => 'tugboatqa/php:8.1-apache',
'image' => 'tugboatqa/php:8.2-apache',
'default' => true,
'depends' => 'mysql',
'commands' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '7',
'major_version' => 7,
],
[
'php' => [
Expand Down Expand Up @@ -81,7 +81,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '7',
'major_version' => 7,
],
[
'php' => [
Expand Down Expand Up @@ -132,7 +132,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '7',
'major_version' => 7,
],
[
'php' => [
Expand Down Expand Up @@ -179,7 +179,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '7',
'major_version' => 7,
],
[
'php' => [
Expand Down Expand Up @@ -241,7 +241,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '7',
'major_version' => 7,
],
[
'php' => [
Expand Down Expand Up @@ -288,7 +288,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '7',
'major_version' => 7,
],
[
'php' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '8',
'major_version' => 8,
],
[
'php' => [
Expand Down Expand Up @@ -85,7 +85,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '8',
'major_version' => 8,
],
[
'php' => [
Expand Down Expand Up @@ -144,7 +144,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '8',
'major_version' => 8,
],
[
'php' => [
Expand Down Expand Up @@ -195,7 +195,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '8',
'major_version' => 8,
],
[
'php' => [
Expand Down Expand Up @@ -260,7 +260,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '8',
'major_version' => 8,
],
[
'php' => [
Expand Down Expand Up @@ -322,7 +322,7 @@ public function configData(): \Generator {
],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '8',
'major_version' => 8,
],
[
'php' => [
Expand Down Expand Up @@ -376,7 +376,7 @@ public function configData(): \Generator {
'additionals' => [],
'instance_id' => $instance_id,
'hash' => $hash,
'major_version' => '8',
'major_version' => 8,
],
[
'php' => [
Expand Down