From dd24266c510435f4c3022aad80ac9de816924d28 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 11 Sep 2023 19:31:50 +0200 Subject: [PATCH] Fix .env support when running from phar archive With this changes, the moodle-plugin-ci execution will be able to find a .env file in the same directory that the .phar file containing it. That way install will be able to create that file and the rest of commands will access to that information via dotenv, avoiding to have to export any env variable manually for phar-based executions. --- bin/moodle-plugin-ci | 11 ++++++++++- docs/CHANGELOG.md | 5 +++++ src/Command/AbstractPluginCommand.php | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/moodle-plugin-ci b/bin/moodle-plugin-ci index 4972d49c..386d4787 100755 --- a/bin/moodle-plugin-ci +++ b/bin/moodle-plugin-ci @@ -48,7 +48,16 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) { define('MOODLE_PLUGIN_CI_VERSION', '4.1.3'); define('MOODLE_PLUGIN_CI_BOXED', '@is_boxed@'); -define('ENV_FILE', dirname(__DIR__) . '/.env'); + +// If we are running moodle-plugin-ci within a PHAR, we need to set the +// path to the dotenv file differently. +if (\Phar::running() !== '') { + // The .env file is in the same directory than the phar. + define('ENV_FILE', dirname(\Phar::running(false)) . '/.env'); +} else { + // The .env file is in the root directory of the moodle-plugin-ci project. + define('ENV_FILE', dirname(__DIR__) . '/.env'); +} if (file_exists(ENV_FILE)) { // Use this file because PHP cannot write to the environment. diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 91d43b25..ddd7b8be 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -9,6 +9,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com). ## [Unreleased] +### Fixed +- Fix the `.env` support when running from within the PHAR archive. +- Fix the `mustache` command to work from within the PHAR archive. +- Fix the `phpcs` and `phpcbf` commands to work from within the PHAR archive. + ## [4.1.3] - 2023-09-08 ### Changed - Updated project dependencies to current [moodle-cs](https://github.com/moodlehq/moodle-cs), [moodle-local_moodlecheck](https://github.com/moodlehq/moodle-local_moodlecheck) and [moodle-local_ci](https://github.com/moodlehq/moodle-local_ci) versions. Also, to various internal / development tools. diff --git a/src/Command/AbstractPluginCommand.php b/src/Command/AbstractPluginCommand.php index a166d2d9..4dee6ac0 100644 --- a/src/Command/AbstractPluginCommand.php +++ b/src/Command/AbstractPluginCommand.php @@ -38,7 +38,7 @@ protected function configure(): void protected function initialize(InputInterface $input, OutputInterface $output): void { - if (!isset($this->plugin)) { + if (!isset($this->plugin) && $input->getArgument('plugin') !== null) { $validate = new Validate(); $pluginDir = realpath($validate->directory($input->getArgument('plugin'))); $this->plugin = new MoodlePlugin($pluginDir);