Skip to content

Commit 7868cc9

Browse files
authored
Merge pull request #373 from dotkernel/issue-327
Ignore development files on production env
2 parents 9ab2885 + 5e68754 commit 7868cc9

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

.github/workflows/codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
php${{ matrix.php }}-composer-
4343
4444
- name: Install dependencies with composer
45+
env:
46+
COMPOSER_DEV_MODE=1
4547
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
4648

4749
- name: Collect code coverage with PHPUnit

.laminas-ci/pre-run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ JOB=$3
22
PHP_VERSION=$4
33
COMMAND=$(echo "${JOB}" | jq -r '.command')
44

5-
echo "Running $COMMAND"
5+
echo "Running pre-run $COMMAND"
66

77
if [[ ${COMMAND} =~ phpunit ]];then
88

99
apt-get install php"${PHP_VERSION}"-sqlite3
1010

1111
cp config/autoload/local.php.dist config/autoload/local.php
12-
cp config/autoload/mail.global.php.dist config/autoload/mail.global.php
1312
cp config/autoload/local.test.php.dist config/autoload/local.test.php
1413

1514
fi

bin/composer-post-install-script.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,57 @@
22

33
declare(strict_types=1);
44

5+
require_once 'vendor/autoload.php';
6+
7+
const ENVIRONMENT_DEVELOPMENT = 'development';
8+
const ENVIRONMENT_PRODUCTION = 'production';
9+
510
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
611

712
function copyFile(array $file): void
813
{
14+
if (! in_array(getEnvironment(), $file['environment'])) {
15+
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
16+
return;
17+
}
18+
919
if (is_readable($file['destination'])) {
10-
echo "File {$file['destination']} already exists." . PHP_EOL;
20+
echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL;
21+
return;
22+
}
23+
24+
if (! copy($file['source'], $file['destination'])) {
25+
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
1126
} else {
12-
if (! copy($file['source'], $file['destination'])) {
13-
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
14-
} else {
15-
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
16-
}
27+
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
1728
}
1829
}
1930

31+
function getEnvironment(): string
32+
{
33+
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
34+
}
35+
36+
// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder
37+
// the `environment` key will indicate on what environments the file will be copied,
2038
$files = [
2139
[
2240
'source' => 'config/autoload/local.php.dist',
2341
'destination' => 'config/autoload/local.php',
42+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
2443
],
2544
[
2645
'source' => 'config/autoload/local.test.php.dist',
2746
'destination' => 'config/autoload/local.test.php',
47+
'environment' => [ENVIRONMENT_DEVELOPMENT],
2848
],
2949
[
3050
'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist',
3151
'destination' => 'config/autoload/mail.global.php',
52+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
3253
],
3354
];
3455

56+
echo "Using environment setting: " . getEnvironment() . PHP_EOL;
57+
3558
array_walk($files, 'copyFile');

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
}
104104
},
105105
"scripts": {
106-
"post-install-cmd": [
106+
"post-create-project-cmd": [
107107
"@development-enable"
108108
],
109109
"post-update-cmd": [

0 commit comments

Comments
 (0)