From d2c51371213b0dce107794da5487eecb60ada194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Thu, 15 Aug 2024 09:36:00 +0200 Subject: [PATCH] Do not use {{stage}} --- src/task/setono_dotenv.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/task/setono_dotenv.php b/src/task/setono_dotenv.php index 7f8a059..2adc757 100644 --- a/src/task/setono_dotenv.php +++ b/src/task/setono_dotenv.php @@ -36,10 +36,10 @@ run(sprintf('echo "APP_ENV=%s" > {{release_path}}/.env.local', $stage)); } - if (has('previous_release') && test('[ -f {{previous_release}}/.env.{{stage}}.local ]')) { - run('cp {{previous_release}}/.env.{{stage}}.local {{release_path}}'); + if (has('previous_release') && test(sprintf('[ -f {{previous_release}}/.env.%s.local ]', $stage))) { + run(sprintf('cp {{previous_release}}/.env.%s.local {{release_path}}', $stage)); } else { - run('touch {{release_path}}/.env.{{stage}}.local'); + run(sprintf('touch {{release_path}}/.env.%s.local', $stage)); } })->desc('Copies .env.[stage].local from previous release folder or creates a new one'); @@ -47,7 +47,9 @@ * This task should be called BEFORE dotenv:update because that task needs the .env.local.php file */ task('dotenv:generate', static function (): void { - run('cd {{release_path}} && {{bin/composer}} symfony:dump-env {{stage}}'); + $stage = getStage(); + + run(sprintf('cd {{release_path}} && {{bin/composer}} symfony:dump-env %s', $stage)); })->desc('Generates the .env.local.php file'); /** @@ -116,6 +118,8 @@ } } + $stage = getStage(); + /** * Notice that this comparison will return false if the two arrays have different key/value pairs * See https://www.php.net/manual/en/language.operators.array.php @@ -126,7 +130,7 @@ * * @var array $overriddenValues */ - $overriddenValues = (new Dotenv())->parse(run('cat {{release_path}}/.env.{{stage}}.local')); + $overriddenValues = (new Dotenv())->parse(run(sprintf('cat {{release_path}}/.env.%s.local', $stage))); /** * The difference between the $variables array and the $initialVariables array @@ -144,7 +148,7 @@ * This will generate a $command variable that will save a multiline text into a file * See https://stackoverflow.com/questions/10969953/how-to-output-a-multiline-string-in-bash */ - $command = "cat < {{release_path}}/.env.{{stage}}.local\n"; + $command = sprintf("cat < {{release_path}}/.env.%s.local\n", $stage); foreach ($overriddenValues as $key => $val) { $command .= $key . '=' . $val . "\n"; }