Skip to content

Commit

Permalink
chore: add ability to reset database on deployment, default no-reset
Browse files Browse the repository at this point in the history
Signed-off-by: Fery Wardiyanto <[email protected]>
  • Loading branch information
feryardiant committed Feb 29, 2024
1 parent 0543ca1 commit 58d67f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
description: Deployment target
required: true
type: environment
reset:
description: Reset database
default: false
type: boolean
workflow_run:
workflows: [Code Quality]
types: [completed]
Expand Down Expand Up @@ -78,8 +82,11 @@ jobs:

- name: Deploy
uses: deployphp/action@master
env:
DB_RESET: ${{ github.event_name == 'workflow_dispatch' && inputs.reset || false }}
DEPLOY_ARGS: --branch ${{ needs.prepare.outputs.target-branch }} --$([ $DB_RESET = true ] && echo 'reset' || echo 'no-reset')
with:
private-key: ${{ secrets.DEPLOY_SSH_RSAKEY }}
ssh-config: ${{ secrets.DEPLOY_SSH_CONFIG }}
verbosity: ''
dep: deploy -f scripts/deploy.php env=staging --branch ${{ needs.prepare.outputs.target-branch }}
dep: deploy -f scripts/deploy.php env=staging $DEPLOY_ARGS
23 changes: 18 additions & 5 deletions scripts/deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Deployer;

use Illuminate\Support\Env;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

$rootDir = \dirname(__DIR__);

Expand All @@ -16,6 +16,8 @@
add('shared_dirs', ['public/build', 'public/vendor']);
add('writable_dirs', []);

option('reset', null, InputOption::VALUE_NEGATABLE, 'Reset database', false);

// Hosts

host('skeleton.creasi.dev')
Expand Down Expand Up @@ -105,6 +107,20 @@
info('database <fg=magenta;options=bold>'.$dbName.'</> created');
})->desc('Setup deployment environment');

task('deploy:database', function () {
if (! input()->getOption('reset')) {
invoke('artisan:migrate');
info('database migrated');
return;
}

invoke('artisan:down');
invoke('artisan:migrate:fresh');
invoke('artisan:db:seed');
invoke('artisan:up');
info('database freshly migrated');
})->desc('Deploy database');

task('deploy:assets', function () {
$config = ['flags' => '-zrtv'];

Expand All @@ -124,9 +140,6 @@
'deploy:assets',
'artisan:storage:link',
'artisan:optimize:clear',
'artisan:down',
'artisan:migrate:fresh',
'artisan:db:seed',
'artisan:up',
'deploy:database',
'deploy:publish',
]);

0 comments on commit 58d67f5

Please sign in to comment.