Create a customized myers diff based system for snip content

This commit is contained in:
Tim
2025-04-14 23:25:11 +02:00
parent a18eda6748
commit 2db9c5f1d9
8 changed files with 317 additions and 88 deletions

View File

@ -3,6 +3,7 @@
namespace Deployer;
require_once 'recipe/common.php';
require_once 'deploy/git.php';
// Project name
set('application', 'snips');
@ -13,82 +14,48 @@ set('repository', 'git@git.loken.nl:ardent/Snips.git');
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);
// Shared files/dirs between deploys
// Shared files/dirs between deploys
set('shared_dirs', ['var/log', 'var/sessions']);
set('shared_files', ['.env.local']);
//set('writable_dirs', ['var']);
set('migrations_config', '');
set('allow_anonymous_stats', false);
set('console_options', fn() => '--no-interaction');
set('bin/console', fn() => parse('{{release_path}}/bin/console'));
// Hosts
host('snips.loken.nl')
->setRemoteUser('www-data')
->set('branch', function () {
return input()->getOption('branch') ?: 'master';
})
->set('deploy_path', '~/snips.loken.nl');
set('bin/console', function () {
return parse('{{release_path}}/bin/console');
});
set('console_options', function () {
return '--no-interaction';
});
->set('deploy_path', '~/snips.loken.nl')
;
desc('Clear cache');
task('cache:clear', function () {
run('{{bin/php}} {{bin/console}} cache:clear {{console_options}} --no-warmup');
});
task('cache:clear', fn() => run('{{bin/php}} {{bin/console}} cache:clear {{console_options}} --no-warmup'));
desc('Warm up cache');
task('cache:warmup', function () {
run('{{bin/php}} {{bin/console}} cache:warmup {{console_options}}');
});
task('cache:warmup', fn() => run('{{bin/php}} {{bin/console}} cache:warmup {{console_options}}'));
desc('Migrate database');
task('database:migrate', function () {
// $options = '--allow-no-migration';
// if (get('migrations_config') !== '') {
// $options = sprintf('%s --configuration={{release_path}}/{{migrations_config}}', $options);
// }
//
// run(sprintf('{{bin/php}} {{bin/console}} doctrine:migrations:migrate %s {{console_options}}', $options));
run('{{bin/php}} {{bin/console}} doctrine:schema:update --force');
$options = '--allow-no-migration';
if (get('migrations_config') !== '') {
$options = sprintf('%s --configuration={{release_path}}/{{migrations_config}}', $options);
}
run(sprintf('{{bin/php}} {{bin/console}} doctrine:migrations:migrate %s {{console_options}}', $options));
});
task('deployment:log', function () { //https://stackoverflow.com/questions/59686270/how-to-log-deployments-in-deployer
$branch = parse('{{branch}}');
$date = date('Y-m-d H:i:s');
$commitHashShort = runLocally('git rev-parse --short HEAD');
// $commitHash = runLocally('git rev-parse HEAD');
$commit = explode(PHP_EOL, runLocally('git log -1 --pretty="%H%n%ci"'));
$commitHash = $commit[0];
$commitDate = $commit[1];
// $line = sprintf('%s %s branch="%s" hash="%s"', $date, $commitHashShort, $branch, $commitHash);
$projectUrlBase = 'https://git.loken.nl/ardent/Snips';
$array = [
'branch' => $branch,
'branchUrl' => sprintf('%s/src/branch/%s', $projectUrlBase, $branch),
'date' => $date,
'commitHashShort' => $commitHashShort,
'commitHashLong' => $commitHash,
'commitDate' => $commitDate,
'commitUrl' => sprintf('%s/commit/%s', $projectUrlBase, $commitHash),
'projectUrl' => $projectUrlBase,
];
$json = json_encode($array, JSON_PRETTY_PRINT);
runLocally("echo '$json' > release.json");
upload('release.json', '{{release_path}}/release.json');
desc('Shows current deployed version');
task('deploy:current', function () {
$current = run('readlink {{deploy_path}}/current');
writeln("Current deployed version: $current");
});
//desc('Deploy project');
//task('deploy', [
// 'deployment:log',
//]);
desc('Deploy project');
task('deploy', [
'deploy:prepare',
@ -100,9 +67,9 @@ task('deploy', [
'deploy:symlink',
'deploy:unlock',
'deploy:cleanup',
'deploy:current',
]);
after('deploy', 'deploy:success');
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
after('deploy:failed', 'deploy:unlock');