Skip to content

Commit

Permalink
Fix .env support when running from phar archive
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stronk7 committed Sep 15, 2023
1 parent 4d76194 commit 1bb9c4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion bin/moodle-plugin-ci
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt

## [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.

Expand Down
2 changes: 1 addition & 1 deletion src/Command/AbstractPluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1bb9c4e

Please sign in to comment.