Skip to content

Commit

Permalink
Fix missing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 15, 2024
1 parent 0065e9b commit 9fb3501
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
4 changes: 4 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedVariablesAndParams="false"
findUnusedPsalmSuppress="false"
findUnusedCode="false"
findUnusedBaselineEntry="false"
errorLevel="1"
>
<projectFiles>
Expand Down
41 changes: 28 additions & 13 deletions src/task/setono_dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

namespace Setono\Deployer\DotEnv;

use function Deployer\currentHost;
use function Deployer\ask;
use function Deployer\askConfirmation;
use function Deployer\get;
use function Deployer\has;
use function Deployer\input;
use function Deployer\invoke;
use function Deployer\output;
use function Deployer\run;
use function Deployer\task;
use function Deployer\test;
Expand All @@ -23,22 +28,12 @@
* 2. The deploy:update_code step uses git clone to create the release directory and that command expects an empty dir
*/
task('dotenv:prepare', static function (): void {
$stage = get('stage');

// if a stage isn't set, we presume the stage to be prod since you are only deploying to one place
if (null === $stage) {
$stage = 'prod';
$labels = currentHost()->getLabels();
if (null !== $labels && isset($labels['stage'])) {
$stage = $labels['stage'];
}
set('stage', $stage);
}
$stage = getStage();

// this small trick will make sure the environment (i.e. for the console) is set to the expected environment
// when running commands before the generation of the .env.local.php is run
if (!test('[ -f {{release_path}}/.env.local ]')) {
run('echo "APP_ENV={{stage}}" > {{release_path}}/.env.local');
run(sprintf('echo "APP_ENV=%s" > {{release_path}}/.env.local', $stage));
}

if (has('previous_release') && test('[ -f {{previous_release}}/.env.{{stage}}.local ]')) {
Expand Down Expand Up @@ -160,3 +155,23 @@
invoke('dotenv:generate');
}
})->desc('Allows the user to update environment variables');

/**
* Returns the current stage or 'prod' if no stage is set
*/
function getStage(): string
{
/** @var mixed|array $labels */
$labels = get('labels');
Assert::isArray($labels);

// We presume that the stage is prod if it isn't set
if (!isset($labels['stage'])) {
return 'prod';
}

$state = $labels['stage'];
Assert::stringNotEmpty($state);

return $state;
}

0 comments on commit 9fb3501

Please sign in to comment.