From 385b7468e0006e986894adb933d507a7210f348f Mon Sep 17 00:00:00 2001 From: MarioRadu Date: Thu, 12 Dec 2024 16:16:16 +0200 Subject: [PATCH] ignore development files on production env Signed-off-by: MarioRadu --- .github/workflows/codecov.yml | 4 ---- bin/composer-post-install-script.php | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 77d3bf7..59c4b08 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -44,10 +44,6 @@ jobs: - name: Install dependencies with composer run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi -# - name: Setup project -# run: | -# mv config/autoload/local.test.php.dist config/autoload/local.test.php - - name: Collect code coverage with PHPUnit run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php index 89c3bcd..2c86d7b 100644 --- a/bin/composer-post-install-script.php +++ b/bin/composer-post-install-script.php @@ -26,7 +26,19 @@ function copyFile(array $file): void function getEnvironment(): string { - return file_exists('config/development.config.php') ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION; + $composerInstalledJson = 'vendor/composer/installed.json'; + if (! file_exists($composerInstalledJson)) { + throw new RuntimeException('Composer installed JSON file not found.'); + } + + $data = json_decode(file_get_contents($composerInstalledJson), true); + foreach ($data as $package) { + if (! empty($package['dev'])) { + return ENVIRONMENT_DEVELOPMENT; + } + } + + return ENVIRONMENT_PRODUCTION; } // when adding files to the below array the `source` and `destination` paths must be relative to the project root folder @@ -49,6 +61,6 @@ function getEnvironment(): string ], ]; -echo "Using environment setting : " . getEnvironment() . PHP_EOL; +echo "Using environment setting: " . getEnvironment() . PHP_EOL; array_walk($files, 'copyFile');