From 6e390a6e88509428a38d4c9076f91aef3bc83b65 Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Tue, 28 Sep 2021 09:45:15 -0500 Subject: [PATCH 1/9] Adds a setup codespaces command --- .../Commands/DevelopmentModeCommands.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index d0ded91..39caf62 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -506,4 +506,39 @@ public function frontendDevDisable($siteDir = 'default', array $opts = ['yes|y' ->remove($this->devServicesPath) ->run(); } + + /** + * Setup a site in GitHub Codespaces. + * + * @throws \Robo\Exception\TaskException + */ + public function setupCodespaces() + { + $codespaces_directory = getenv('OLDPWD'); + if (empty($codespaces_directory)) { + throw new TaskException($this, 'Codespaces directory is unavailable.'); + } + $result = $this->taskExec('rm /var/www/html')->run(); + $result = $this->taskExec("ln -s $codespaces_directory /var/www/html")->run(); + + $this->io()->title('Start apache, forwarding port 80.'); + $result = $this->taskExec('service apache2 start')->run(); + + $this->io()->title('Download database.'); + $dbPath = $this->databaseDownload(); + if (empty($dbPath)) { + throw new TaskException($this, 'Database download failed.'); + } + + $this->io()->section('Importing database.'); + $result = $this->taskExec("zcat $dbPath | mysql -h db -u mariadb -pmariadb mariadb")->run(); + $result = $this->taskExec('rm')->args($dbPath)->run(); + + $this->io()->section('Building theme.'); + $result = $this->taskExec('composer robo theme:build')->run(); + + $this->io()->section('Clearing Drupal cache.'); + $result = $this->taskExec('vendor/bin/drush cr')->run(); + return $result; + } } From f79615edf88d6b006f4b860341dc88b56db03635 Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Tue, 28 Sep 2021 09:53:15 -0500 Subject: [PATCH 2/9] Update env variable for default working directory --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index 39caf62..2882329 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -514,7 +514,7 @@ public function frontendDevDisable($siteDir = 'default', array $opts = ['yes|y' */ public function setupCodespaces() { - $codespaces_directory = getenv('OLDPWD'); + $codespaces_directory = getenv('PWD') . '/web'; if (empty($codespaces_directory)) { throw new TaskException($this, 'Codespaces directory is unavailable.'); } From dd3d458b71f8be87f3077411fc2522d0e747a2da Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Wed, 29 Sep 2021 07:27:34 -0500 Subject: [PATCH 3/9] Address feedback, use robo command to delete directory --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index 2882329..e64d2d8 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -514,11 +514,13 @@ public function frontendDevDisable($siteDir = 'default', array $opts = ['yes|y' */ public function setupCodespaces() { - $codespaces_directory = getenv('PWD') . '/web'; + $this->io()->title('Symlinking file system.'); + $docRootDir = Robo::config()->get('drupal_document_root') ?? 'web'; + $codespaces_directory = getenv('PWD') . '/' .$docRootDir; if (empty($codespaces_directory)) { throw new TaskException($this, 'Codespaces directory is unavailable.'); } - $result = $this->taskExec('rm /var/www/html')->run(); + $this->taskDeleteDir('/var/www/html')->run(); $result = $this->taskExec("ln -s $codespaces_directory /var/www/html")->run(); $this->io()->title('Start apache, forwarding port 80.'); From ff093e5100de14ac8262b5946db83d27c65cc996 Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Wed, 29 Sep 2021 17:58:55 -0500 Subject: [PATCH 4/9] Start yarn after codespaces is setup --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index e64d2d8..4972c07 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -541,6 +541,9 @@ public function setupCodespaces() $this->io()->section('Clearing Drupal cache.'); $result = $this->taskExec('vendor/bin/drush cr')->run(); + + $this->io()->section('Starting front-end development.'); + $result = $this->taskExec('yarn --cwd web/themes/chromatic/ start')->run(); return $result; } } From 58d289f05a26e9f33f862342c55df863a63dca2b Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Wed, 29 Sep 2021 18:03:20 -0500 Subject: [PATCH 5/9] Resolve code style error --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index 4972c07..131da23 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -516,7 +516,7 @@ public function setupCodespaces() { $this->io()->title('Symlinking file system.'); $docRootDir = Robo::config()->get('drupal_document_root') ?? 'web'; - $codespaces_directory = getenv('PWD') . '/' .$docRootDir; + $codespaces_directory = getenv('PWD') . '/' . $docRootDir; if (empty($codespaces_directory)) { throw new TaskException($this, 'Codespaces directory is unavailable.'); } From 565142d038f8fba301c9cf212900794758956f14 Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Wed, 29 Sep 2021 18:05:18 -0500 Subject: [PATCH 6/9] remove codespaces yarn start (not reported in terminal in codespaces) --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index 131da23..775e8e0 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -541,9 +541,6 @@ public function setupCodespaces() $this->io()->section('Clearing Drupal cache.'); $result = $this->taskExec('vendor/bin/drush cr')->run(); - - $this->io()->section('Starting front-end development.'); - $result = $this->taskExec('yarn --cwd web/themes/chromatic/ start')->run(); return $result; } } From 9acd9f8c445f65db4705cf8ba049fe70ee72ee63 Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Thu, 30 Sep 2021 08:04:36 -0500 Subject: [PATCH 7/9] Update comments on setupCodespaces, return a result as well --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index 775e8e0..85c5acf 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -510,9 +510,13 @@ public function frontendDevDisable($siteDir = 'default', array $opts = ['yes|y' /** * Setup a site in GitHub Codespaces. * + * @return \Robo\Result + * The result of the set of tasks. + * * @throws \Robo\Exception\TaskException + * */ - public function setupCodespaces() + public function setupCodespaces(): Result { $this->io()->title('Symlinking file system.'); $docRootDir = Robo::config()->get('drupal_document_root') ?? 'web'; From fb75aee1b4ddd1763e61a5b554066a0d58ebe555 Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Thu, 30 Sep 2021 10:55:35 -0500 Subject: [PATCH 8/9] Switch to drush deploy instead of a cache-rebuild --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index 85c5acf..c654a84 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -543,8 +543,8 @@ public function setupCodespaces(): Result $this->io()->section('Building theme.'); $result = $this->taskExec('composer robo theme:build')->run(); - $this->io()->section('Clearing Drupal cache.'); - $result = $this->taskExec('vendor/bin/drush cr')->run(); + $this->io()->section('Drush deploy.'); + $result = $this->taskExec('vendor/bin/drush deploy --yes')->run(); return $result; } } From 686a2fce819bdb91ff745fba60a4c05224e350e0 Mon Sep 17 00:00:00 2001 From: Larry Walangitan Date: Thu, 30 Sep 2021 11:05:34 -0500 Subject: [PATCH 9/9] Import config twice when setting up codespaces --- src/Robo/Plugin/Commands/DevelopmentModeCommands.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php index c654a84..c24f74b 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeCommands.php @@ -544,7 +544,16 @@ public function setupCodespaces(): Result $result = $this->taskExec('composer robo theme:build')->run(); $this->io()->section('Drush deploy.'); - $result = $this->taskExec('vendor/bin/drush deploy --yes')->run(); + $result = $this->taskExecStack() + ->exec("vendor/bin/drush deploy --yes") + // Import the latest configuration again. This includes the latest + // configuration_split configuration. Importing this twice ensures that + // the latter command enables and disables modules based upon the most up + // to date configuration. Additional information and discussion can be + // found here: + // https://github.com/drush-ops/drush/issues/2449#issuecomment-708655673 + ->exec("drush config:import --yes") + ->run(); return $result; } }