diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 59c4b08d..f1b91637 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -42,6 +42,8 @@ jobs: php${{ matrix.php }}-composer- - name: Install dependencies with composer + env: + COMPOSER_DEV_MODE=1 run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - name: Collect code coverage with PHPUnit diff --git a/.laminas-ci/pre-run.sh b/.laminas-ci/pre-run.sh index 3a38c16a..34626d54 100755 --- a/.laminas-ci/pre-run.sh +++ b/.laminas-ci/pre-run.sh @@ -2,14 +2,13 @@ JOB=$3 PHP_VERSION=$4 COMMAND=$(echo "${JOB}" | jq -r '.command') -echo "Running $COMMAND" +echo "Running pre-run $COMMAND" if [[ ${COMMAND} =~ phpunit ]];then apt-get install php"${PHP_VERSION}"-sqlite3 cp config/autoload/local.php.dist config/autoload/local.php - cp config/autoload/mail.global.php.dist config/autoload/mail.global.php cp config/autoload/local.test.php.dist config/autoload/local.test.php fi diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php index af2e8a93..c453f961 100644 --- a/bin/composer-post-install-script.php +++ b/bin/composer-post-install-script.php @@ -2,34 +2,57 @@ declare(strict_types=1); +require_once 'vendor/autoload.php'; + +const ENVIRONMENT_DEVELOPMENT = 'development'; +const ENVIRONMENT_PRODUCTION = 'production'; + // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols function copyFile(array $file): void { + if (! in_array(getEnvironment(), $file['environment'])) { + echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL; + return; + } + if (is_readable($file['destination'])) { - echo "File {$file['destination']} already exists." . PHP_EOL; + echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL; + return; + } + + if (! copy($file['source'], $file['destination'])) { + echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; } else { - if (! copy($file['source'], $file['destination'])) { - echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; - } else { - echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; - } + echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; } } +function getEnvironment(): string +{ + return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION; +} + +// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder +// the `environment` key will indicate on what environments the file will be copied, $files = [ [ 'source' => 'config/autoload/local.php.dist', 'destination' => 'config/autoload/local.php', + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], ], [ 'source' => 'config/autoload/local.test.php.dist', 'destination' => 'config/autoload/local.test.php', + 'environment' => [ENVIRONMENT_DEVELOPMENT], ], [ 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', 'destination' => 'config/autoload/mail.global.php', + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], ], ]; +echo "Using environment setting: " . getEnvironment() . PHP_EOL; + array_walk($files, 'copyFile'); diff --git a/composer.json b/composer.json index 5bdc09c6..3f9c0510 100644 --- a/composer.json +++ b/composer.json @@ -103,7 +103,7 @@ } }, "scripts": { - "post-install-cmd": [ + "post-create-project-cmd": [ "@development-enable" ], "post-update-cmd": [