From b17d8005e62b288108b8aba258aee12ad7d1f3bc Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Wed, 27 Nov 2019 16:46:04 -0500 Subject: [PATCH 1/9] Add composer install test to github actions. --- .github/workflows/php.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 00000000..0a1a8c03 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,30 @@ +name: Composer + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Save Composer Cache + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest From 25f2af9e19062943069e224ce71e4e2670a030f3 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 09:43:06 -0400 Subject: [PATCH 2/9] composer sha --- composer.lock | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.lock b/composer.lock index 36a45659..d0706c9f 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9a25b24761df3282da478cb6fb3b3358", + "content-hash": "6a400e5fb91da8b6c869dcb854344cff", "packages": [ { "name": "consolidation/annotated-command", @@ -2309,5 +2309,6 @@ "platform-dev": [], "platform-overrides": { "php": "5.5.9" - } + }, + "plugin-api-version": "2.3.0" } From 9df6212ec52ef9241d77a103f1cb45cbae360dec Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 09:47:38 -0400 Subject: [PATCH 3/9] Move bins to better dir --- composer.json | 2 +- bin/provision => provision | 0 bin/provision-robo.php => provision-robo.php | 0 bin/provision.php => provision.php | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename bin/provision => provision (100%) rename bin/provision-robo.php => provision-robo.php (100%) rename bin/provision.php => provision.php (100%) diff --git a/composer.json b/composer.json index 3630331f..6cec07c9 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "url": "git@github.com:provision4/Robo.git" } ], - "bin": ["bin/provision"], + "bin": ["provision"], "authors": [ { "name": "Provision Contributors", diff --git a/bin/provision b/provision similarity index 100% rename from bin/provision rename to provision diff --git a/bin/provision-robo.php b/provision-robo.php similarity index 100% rename from bin/provision-robo.php rename to provision-robo.php diff --git a/bin/provision.php b/provision.php similarity index 100% rename from bin/provision.php rename to provision.php From 5ef62f02e00ea7aae2b51a3d798bc0e50e03ccc1 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 10:16:32 -0400 Subject: [PATCH 4/9] Revert "If there was no command run, make sure to still append the command to argv" This reverts commit 75c67396883ec951f572f9fff64eafa45388f9ee. --- bin/provision-robo.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bin/provision-robo.php b/bin/provision-robo.php index a3a80494..159a34e8 100644 --- a/bin/provision-robo.php +++ b/bin/provision-robo.php @@ -53,15 +53,9 @@ $io->warningLite(' Running `provision setup` command to fix the problems... '); } - // Replace given command with "setup", unless there is no command, then append to argv. $command = $input->getFirstArgument(); $command_key = array_search($input->getFirstArgument(), $argv); - if (empty($command_key)) { - $argv[] = 'setup'; - } - else { - $argv[$command_key] = 'setup'; - } + $argv[$command_key] = 'setup'; $input = new ArgvInput($argv); $io = new ProvisionStyle($input, $output); $config = new Config($io, FALSE); From b0b4061c986e1d0837f08a81e2fb1a76303a614f Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 10:16:32 -0400 Subject: [PATCH 5/9] Revert "Fixing $argv transformation to ensure replacement of command so that options still go through (mainly used so we can use -n on first run to have non-interactive setup.)" This reverts commit 2a6ce77482ea8a36be441800a5da1922df28e7e7. --- bin/provision-robo.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/provision-robo.php b/bin/provision-robo.php index 159a34e8..283222f1 100644 --- a/bin/provision-robo.php +++ b/bin/provision-robo.php @@ -53,9 +53,8 @@ $io->warningLite(' Running `provision setup` command to fix the problems... '); } - $command = $input->getFirstArgument(); - $command_key = array_search($input->getFirstArgument(), $argv); - $argv[$command_key] = 'setup'; + + $argv = [$argv[0], 'setup']; $input = new ArgvInput($argv); $io = new ProvisionStyle($input, $output); $config = new Config($io, FALSE); From 56b7c41c6e53f966795fbb8d4c93233fc9a3f727 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 10:21:59 -0400 Subject: [PATCH 6/9] Reverting commit that broke first timers wizard. --- bin/provision-robo.php | 28 ++-------- src/Provision/Application.php | 1 - src/Provision/Common/NotSetupException.php | 7 --- src/Provision/Console/Config.php | 62 +++++++++++++++------- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/bin/provision-robo.php b/bin/provision-robo.php index 283222f1..f9a22f42 100644 --- a/bin/provision-robo.php +++ b/bin/provision-robo.php @@ -18,7 +18,6 @@ use Aegir\Provision\Console\ConsoleOutput; use Aegir\Provision\Console\Config; -use Aegir\Provision\Common\NotSetupException; use Aegir\Provision\Console\ProvisionStyle; use Robo\Common\TimeKeeper; @@ -35,30 +34,9 @@ $input = new ArgvInput($argv); $output = new ConsoleOutput(); $io = new ProvisionStyle($input, $output); - - // Try to load config. If there are no files detected, Config::__construct() - // will throw a NotSetupException. - // When that happens, run the 'setup' command instead of whatever command was run by overriding $argv. - try { - // Create a config object. - $config = new Config($io); - } - catch (NotSetupException $e) { - - if ($e->getMessage()) { - $io->warningLite('There were problems detected with your system: '); - - $io->outputBlock($e->getMessage()); - - $io->warningLite(' Running `provision setup` command to fix the problems... '); - } - - - $argv = [$argv[0], 'setup']; - $input = new ArgvInput($argv); - $io = new ProvisionStyle($input, $output); - $config = new Config($io, FALSE); - } + + // Create a config object. + $config = new Config($io); // Create the app. $provision = new \Aegir\Provision\Provision($config, $input, $output); diff --git a/src/Provision/Application.php b/src/Provision/Application.php index 44267eb7..3e2f5552 100644 --- a/src/Provision/Application.php +++ b/src/Provision/Application.php @@ -6,7 +6,6 @@ use Aegir\Provision\Command\EditCommand; use Aegir\Provision\Command\SaveCommand; use Aegir\Provision\Command\ServicesCommand; -use Aegir\Provision\Command\SetupCommand; use Aegir\Provision\Command\ShellCommand; use Aegir\Provision\Command\StatusCommand; use Aegir\Provision\Command\Ui\CreateUiCommand; diff --git a/src/Provision/Common/NotSetupException.php b/src/Provision/Common/NotSetupException.php index 727d1ef3..e69de29b 100644 --- a/src/Provision/Common/NotSetupException.php +++ b/src/Provision/Common/NotSetupException.php @@ -1,7 +0,0 @@ -io = $io; @@ -84,9 +81,7 @@ public function __construct(ProvisionStyle $io = null, $validate = TRUE) $this->extend(new DotEnvConfig(getcwd())); $this->extend(new EnvConfig()); - if ($validate) { - $this->validateConfig(); - } + $this->validateConfig(); } /** @@ -115,14 +110,39 @@ protected function validateConfig() { ); } - // Check for missing everything. Tell the user to run the setup command. - // @TODO: Run the setup command here instead. I poked and prodded but could not get it to work. Config is instantiated before Application -// if ( -// !file_exists($this->get('config_path')) && -// !file_exists($this->get('console_config_file')) -// ) { -// throw new NotSetupException(); -// } + // If config_path or contexts_path does not exist... + if (!file_exists($this->get('config_path')) || !file_exists($this->get('contexts_path'))) { + + // START: New User! + // @TODO: Break this out into it's own method or class. + $this->io->title("Welcome to Provision!"); + $this->io->block([ + "It looks like this is your first time running Provision, because the config directory is missing. This is the place Provision stores your metadata and server configuration.", + ]); + + // Tell the user how to change the config path. Change language if they already have the .provision.yml file. + if (file_exists($this->get('console_config_path'))) { + $this->io->commentBlock([ + 'If you would like to change the default Config Path, create a file ' . $this->get('console_config_file') . ' and add:', + ' config_path: /path/to/my/provision/config' + ]); + } + else { + $this->io->block([ + 'Tip: If you would like to change the default Config Path, add the following to the file ' . $this->get('console_config_file'), + ' config_path: /path/to/my/provision/config' + ], NULL, 'fg=blue'); + } + + // Offer to create the folder for the user. + if ($this->input()->hasParameterOption(array('--no-interaction', '-n'), false) || $this->io->confirm('Should I create the folders ' . $this->get('config_path') . ' and ' . $this->get('contexts_path') . ' ?')) { + $this->fs->mkdir($this->get('config_path'), 0700); + $this->fs->mkdir($this->get('contexts_path'), 0700); + + $this->io->successLite('Created paths successfully.'); + $this->io->writeln(''); + } + } // Check for paths that need to be writable. @@ -132,15 +152,21 @@ protected function validateConfig() { foreach ($writable_paths as $name => $path) { if (!file_exists($path)) { - $errors[] = "The '$name' folder ($path) does not exist. You must create it or change the value for '$name' in the file {$this->get('console_config_file')}."; + if ($this->io()->confirm("The folder set to '$name' ($path) does not exist. Would you like to create it?")) { + Provision::fs()->mkdir($path); + } + else { + $errors[] = "The folder set to '$name' ($path) does not exist. You must create it or change the $name value in the file {$this->get('console_config_file')}."; + } + $errors[] = "The folder set to '$name' ($path) does not exist. Fix this or change the $name value in the file {$this->get('console_config_file')}."; } elseif (!is_writable($path)) { - $errors[] = "The '$name' folder ($path) is not writable. Fix this or change the value for '$name' in the file {$this->get('console_config_file')}."; + $errors[] = "The folder set to '$name' ($path) is not writable. Fix this or change the $name value in the file {$this->get('console_config_file')}."; } } if ($errors) { - throw new Exception(implode("\n\n", $errors)); + throw new InvalidOptionException(implode("\n\n", $errors)); } // Ensure that script_user is the user. From e4902e580836c3cc6976752c81fc2db88e97f1c8 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 10:43:08 -0400 Subject: [PATCH 7/9] Comment out setup command for now. --- src/Provision/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Provision/Application.php b/src/Provision/Application.php index 3e2f5552..85b6002f 100644 --- a/src/Provision/Application.php +++ b/src/Provision/Application.php @@ -152,7 +152,8 @@ protected function getDefaultCommands() $commands[] = new ListCommand(); $commands[] = new SaveCommand(); $commands[] = new EditCommand(); - $commands[] = new SetupCommand(); + // @TODO: Decide if we want to fix setup command. + // $commands[] = new SetupCommand(); $commands[] = new ServicesCommand(); $commands[] = new ShellCommand(); $commands[] = new StatusCommand(); From 1f140c298993e743afdb827baff12c244a885318 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 10:43:43 -0400 Subject: [PATCH 8/9] Fix checks for console_config_file. --- src/Provision/Command/StatusCommand.php | 2 +- src/Provision/Console/Config.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Provision/Command/StatusCommand.php b/src/Provision/Command/StatusCommand.php index 15f06206..8021fda2 100644 --- a/src/Provision/Command/StatusCommand.php +++ b/src/Provision/Command/StatusCommand.php @@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->io->table($headers, $rows); $this->getProvision()->getLogger()->info('You can modify your console configuration using the file {path}', [ - 'path ' => $this->getProvision()->getConfig()->get('console_config_path'), + 'path ' => $this->getProvision()->getConfig()->get('console_config_file'), ]); } diff --git a/src/Provision/Console/Config.php b/src/Provision/Console/Config.php index 91e57e8b..1ceafc0e 100644 --- a/src/Provision/Console/Config.php +++ b/src/Provision/Console/Config.php @@ -121,17 +121,17 @@ protected function validateConfig() { ]); // Tell the user how to change the config path. Change language if they already have the .provision.yml file. - if (file_exists($this->get('console_config_path'))) { - $this->io->commentBlock([ - 'If you would like to change the default Config Path, create a file ' . $this->get('console_config_file') . ' and add:', - ' config_path: /path/to/my/provision/config' + if (file_exists($this->get('console_config_file'))) { + $this->get('config_path'); + $this->io->commentBlock([ + 'You already have a provision config file: ' . $this->get('console_config_file'), + ' config_path: ' . $this->get('config_path'), + 'If needed, change the config_path to your desired location.' ]); } else { - $this->io->block([ - 'Tip: If you would like to change the default Config Path, add the following to the file ' . $this->get('console_config_file'), - ' config_path: /path/to/my/provision/config' - ], NULL, 'fg=blue'); + $this->config->set('config_path', $this->io()->ask('Where would you like to store Provision config?', $this->get('config_path'))); + $this->config->set('contexts_path', $this->io()->ask('Where would you like to store Provision context data?', $this->get('contexts_path'))); } // Offer to create the folder for the user. From 3ad8c20f0ba89034b6b2cb8fbf88eb31bfcff5fd Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Sun, 2 Apr 2023 10:44:33 -0400 Subject: [PATCH 9/9] Fix logic check for php 8 --- src/Provision/Context.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Provision/Context.php b/src/Provision/Context.php index 2da53cc3..8e9b185b 100644 --- a/src/Provision/Context.php +++ b/src/Provision/Context.php @@ -1013,10 +1013,10 @@ public function shell_exec($command, $dir = NULL, $return = 'stdout', $force_ver $tmp_output_file = tempnam($tmpdir, 'task.' . $datestamp . '.output.'); $tmp_error_file = tempnam($tmpdir, 'task.' . $datestamp . '.error.'); - $effective_wd = $dir? $dir: + $effective_wd = $dir ?? ( $this->type == 'server'? $this->getProperty('server_config_path'): $this->getProperty('root') - ; + ); if ($this->getProvision()->getOutput()->isVerbose() || $force_verbose) { $this->getProvision()->io()->commandBlock($command, $effective_wd);