Skip to content

Commit

Permalink
Do not use {{stage}}
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 15, 2024
1 parent bfafa14 commit d2c5137
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/task/setono_dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@
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');

/**
* 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');

/**
Expand Down Expand Up @@ -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
Expand All @@ -126,7 +130,7 @@
*
* @var array<string, string> $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
Expand All @@ -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 <<EOT > {{release_path}}/.env.{{stage}}.local\n";
$command = sprintf("cat <<EOT > {{release_path}}/.env.%s.local\n", $stage);
foreach ($overriddenValues as $key => $val) {
$command .= $key . '=' . $val . "\n";
}
Expand Down

0 comments on commit d2c5137

Please sign in to comment.