Skip to content

Commit 7627f9b

Browse files
authored
Add and use new release_or_current_path (deployphp#2486)
* Add release_or_current_path option * Use new path in platform-specific recipes * Update CHANGELOG.md
1 parent 34dade5 commit 7627f9b

13 files changed

+75
-49
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- Added support for PHP8.
2323
- Added slack_channel option to Slack recipe.
2424
- Chatwork contrib recipe.
25+
- Added `release_or_current_path` option that fallbacks to the `current_path` when the `release_path` does not exist. [#2486]
2526

2627
### Changed
2728
- Refactored executor engine, up to 2x faster than before.
@@ -602,6 +603,7 @@
602603
- Fixed `DotArray` syntax in `Collection`.
603604

604605

606+
[#2486]: https://github.com/deployphp/deployer/pull/2486
605607
[#2425]: https://github.com/deployphp/deployer/pull/2425
606608
[#2423]: https://github.com/deployphp/deployer/issues/2423
607609
[#2393]: https://github.com/deployphp/deployer/pull/2393

Diff for: docs/recipe/deploy/release.md

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [`releases_metainfo`](#releases_metainfo)
1414
* [`releases_list`](#releases_list)
1515
* [`release_path`](#release_path)
16+
* [`release_or_current_path`](#release_or_current_path)
1617
* Tasks
1718
* [`deploy:release`](#deployrelease) — Prepare release. Clean up unfinished releases and prepare next release
1819

@@ -37,6 +38,12 @@ Return list of releases on host.
3738

3839
Return release path.
3940

41+
### release_or_current_path
42+
[Source](https://github.com/deployphp/deployer/search?q=%22release_or_current_path%22+in%3Afile+language%3Aphp+path%3Arecipe%2Fdeploy+filename%3Arelease.php)
43+
44+
Return the release path during a deployment
45+
but fallback to the current path otherwise.
46+
4047

4148
## Tasks
4249
### deploy:release

Diff for: recipe/cakephp.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
* Create plugins' symlinks
2626
*/
2727
task('deploy:init', function () {
28-
run('{{release_path}}/bin/cake plugin assets symlink');
28+
run('{{release_or_current_path}}/bin/cake plugin assets symlink');
2929
})->desc('Initialization');
3030

3131
/**
3232
* Run migrations
3333
*/
3434
task('deploy:run_migrations', function () {
35-
run('{{release_path}}/bin/cake migrations migrate');
36-
run('{{release_path}}/bin/cake schema_cache clear');
37-
run('{{release_path}}/bin/cake schema_cachebuild');
35+
run('{{release_or_current_path}}/bin/cake migrations migrate');
36+
run('{{release_or_current_path}}/bin/cake schema_cache clear');
37+
run('{{release_or_current_path}}/bin/cake schema_cachebuild');
3838
})->desc('Run migrations');
3939

4040
/**

Diff for: recipe/deploy/release.php

+9
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@
8989
}
9090
});
9191

92+
/**
93+
* Return the release path during a deployment
94+
* but fallback to the current path otherwise.
95+
*/
96+
set('release_or_current_path', function () {
97+
$releaseExists = test('[ -h {{deploy_path}}/release ]');
98+
99+
return $releaseExists ? get('release_path') : get('current_path');
100+
});
92101

93102
desc('Prepare release. Clean up unfinished releases and prepare next release');
94103
task('deploy:release', function () {

Diff for: recipe/deploy/vendors.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
if (!commandExist('unzip')) {
3030
warning('To speed up composer installation setup "unzip" command with PHP zip extension.');
3131
}
32-
run('cd {{release_path}} && {{bin/composer}} {{composer_action}} {{composer_options}} 2>&1');
32+
run('cd {{release_or_current_path}} && {{bin/composer}} {{composer_action}} {{composer_options}} 2>&1');
3333
});

Diff for: recipe/flow_framework.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
*/
2424
desc('Apply database migrations');
2525
task('deploy:run_migrations', function () {
26-
run('FLOW_CONTEXT={{flow_context}} {{bin/php}} {{release_path}}/{{flow_command}} doctrine:migrate');
26+
run('FLOW_CONTEXT={{flow_context}} {{bin/php}} {{release_or_current_path}}/{{flow_command}} doctrine:migrate');
2727
});
2828

2929
/**
3030
* Publish resources
3131
*/
3232
desc('Publish resources');
3333
task('deploy:publish_resources', function () {
34-
run('FLOW_CONTEXT={{flow_context}} {{bin/php}} {{release_path}}/{{flow_command}} resource:publish');
34+
run('FLOW_CONTEXT={{flow_context}} {{bin/php}} {{release_or_current_path}}/{{flow_command}} resource:publish');
3535
});
3636

3737
/**

Diff for: recipe/laravel.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
]);
2121
set('log_files', 'storage/logs/*.log');
2222
set('laravel_version', function () {
23-
$result = run('{{bin/php}} {{release_path}}/artisan --version');
23+
$result = run('{{bin/php}} {{release_or_current_path}}/artisan --version');
2424
preg_match_all('/(\d+\.?)+/', $result, $matches);
2525
return $matches[0][0] ?? 5.5;
2626
});
@@ -43,6 +43,8 @@
4343
function artisan($command, $options = [])
4444
{
4545
return function () use ($command, $options) {
46+
47+
// Ensure the artisan command is available on the current version.
4648
$versionTooEarly = array_key_exists('min', $options)
4749
&& laravel_version_compare($options['min'], '<');
4850

@@ -52,20 +54,26 @@ function artisan($command, $options = [])
5254
if ($versionTooEarly || $versionTooLate) {
5355
return;
5456
}
55-
if (in_array('failIfNoEnv', $options) && !test('[ -s {{release_path}}/.env ]')) {
57+
58+
// Ensure we warn or fail when a command relies on the ".env" file.
59+
if (in_array('failIfNoEnv', $options) && !test('[ -s {{release_or_current_path}}/.env ]')) {
5660
throw new \Exception('Your .env file is empty! Cannot proceed.');
5761
}
58-
if (in_array('skipIfNoEnv', $options) && !test('[ -s {{release_path}}/.env ]')) {
62+
63+
if (in_array('skipIfNoEnv', $options) && !test('[ -s {{release_or_current_path}}/.env ]')) {
5964
warning("Your .env file is empty! Skipping...</>");
6065
return;
6166
}
6267

68+
// Use the release_path by default unless it does not exist or specified otherwise.
6369
$artisan = in_array('runInCurrent', $options)
6470
? '{{current_path}}/artisan'
65-
: '{{release_path}}/artisan';
71+
: '{{release_or_current_path}}/artisan';
6672

73+
// Run the artisan command.
6774
$output = run("{{bin/php}} $artisan $command");
6875

76+
// Output the results when appropriate.
6977
if (in_array('showOutput', $options)) {
7078
writeln("<info>$output</info>");
7179
}
@@ -166,13 +174,13 @@ function laravel_version_compare($version, $comparator)
166174
desc('Make symlink for public disk');
167175
task('deploy:public_disk', function () {
168176
// Remove from source.
169-
run('if [ -d $(echo {{release_path}}/public/storage) ]; then rm -rf {{release_path}}/public/storage; fi');
177+
run('if [ -d $(echo {{release_or_current_path}}/public/storage) ]; then rm -rf {{release_or_current_path}}/public/storage; fi');
170178

171179
// Create shared dir if it does not exist.
172180
run('mkdir -p {{deploy_path}}/shared/storage/app/public');
173181

174182
// Symlink shared dir to release dir
175-
run('{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_path}}/public/storage');
183+
run('{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_or_current_path}}/public/storage');
176184
});
177185

178186
/**

Diff for: recipe/magento.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
*/
2424
desc('Clear cache');
2525
task('deploy:cache:clear', function () {
26-
run("cd {{release_path}} && php -r \"require_once 'app/Mage.php'; umask(0); Mage::app()->cleanCache();\"");
26+
run("cd {{release_or_current_path}} && php -r \"require_once 'app/Mage.php'; umask(0); Mage::app()->cleanCache();\"");
2727
});
2828

2929
/**
3030
* Remove files that can be used to compromise Magento
3131
*/
3232
task('deploy:clear_version', function () {
33-
run("rm -f {{release_path}}/LICENSE.html");
34-
run("rm -f {{release_path}}/LICENSE.txt");
35-
run("rm -f {{release_path}}/LICENSE_AFL.txt");
36-
run("rm -f {{release_path}}/RELEASE_NOTES.txt");
33+
run("rm -f {{release_or_current_path}}/LICENSE.html");
34+
run("rm -f {{release_or_current_path}}/LICENSE.txt");
35+
run("rm -f {{release_or_current_path}}/LICENSE_AFL.txt");
36+
run("rm -f {{release_or_current_path}}/RELEASE_NOTES.txt");
3737
})->hidden();
3838

3939
after('deploy:update_code', 'deploy:clear_version');

Diff for: recipe/magento2.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
set('magento_version', function () {
6060
// detect version
61-
$versionOutput = run('{{bin/php}} {{release_path}}/bin/magento --version');
61+
$versionOutput = run('{{bin/php}} {{release_or_current_path}}/bin/magento --version');
6262
preg_match('/(\d+\.?)+$/', $versionOutput, $matches);
6363
return $matches[0] ?? "2.0";
6464
});
@@ -72,14 +72,14 @@
7272
// Tasks
7373
desc('Compile magento di');
7474
task('magento:compile', function () {
75-
run('cd {{release_path}} && {{bin/composer}} dump-autoload -o');
76-
run("{{bin/php}} {{release_path}}/bin/magento setup:di:compile");
77-
run('cd {{release_path}} && {{bin/composer}} dump-autoload -o');
75+
run('cd {{release_or_current_path}} && {{bin/composer}} dump-autoload -o');
76+
run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:di:compile");
77+
run('cd {{release_or_current_path}} && {{bin/composer}} dump-autoload -o');
7878
});
7979

8080
desc('Deploy assets');
8181
task('magento:deploy:assets', function () {
82-
run("{{bin/php}} {{release_path}}/bin/magento setup:static-content:deploy --content-version={{content_version}} {{static_content_locales}}");
82+
run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy --content-version={{content_version}} {{static_content_locales}}");
8383
});
8484

8585
desc('Sync content version');
@@ -114,7 +114,7 @@
114114
$configImportNeeded = true;
115115
} else {
116116
try {
117-
run('{{bin/php}} {{release_path}}/bin/magento app:config:status');
117+
run('{{bin/php}} {{release_or_current_path}}/bin/magento app:config:status');
118118
} catch (RunException $e) {
119119
if ($e->getExitCode() == CONFIG_IMPORT_NEEDED_EXIT_CODE) {
120120
$configImportNeeded = true;
@@ -129,7 +129,7 @@
129129
invoke('magento:maintenance:enable');
130130
}
131131

132-
run('{{bin/php}} {{release_path}}/bin/magento app:config:import --no-interaction');
132+
run('{{bin/php}} {{release_or_current_path}}/bin/magento app:config:import --no-interaction');
133133

134134
if (!get('maintenance_mode_status_active')) {
135135
invoke('magento:maintenance:disable');
@@ -142,7 +142,7 @@
142142
$databaseUpgradeNeeded = false;
143143

144144
try {
145-
run('{{bin/php}} {{release_path}}/bin/magento setup:db:status');
145+
run('{{bin/php}} {{release_or_current_path}}/bin/magento setup:db:status');
146146
} catch (RunException $e) {
147147
if ($e->getExitCode() == DB_UPDATE_NEEDED_EXIT_CODE) {
148148
$databaseUpgradeNeeded = true;
@@ -156,7 +156,7 @@
156156
invoke('magento:maintenance:enable');
157157
}
158158

159-
run("{{bin/php}} {{release_path}}/bin/magento setup:upgrade --keep-generated");
159+
run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:upgrade --keep-generated");
160160

161161
if (!get('maintenance_mode_status_active')) {
162162
invoke('magento:maintenance:disable');
@@ -166,7 +166,7 @@
166166

167167
desc('Flush Magento Cache');
168168
task('magento:cache:flush', function () {
169-
run("{{bin/php}} {{release_path}}/bin/magento cache:flush");
169+
run("{{bin/php}} {{release_or_current_path}}/bin/magento cache:flush");
170170
});
171171

172172
desc('Magento2 deployment operations');

Diff for: recipe/shopware.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,32 @@
3737
set('static_folders', []);
3838

3939
task('sw:update_code', static function () {
40-
run('git clone {{repository}} {{release_path}}');
40+
run('git clone {{repository}} {{release_or_current_path}}');
4141
});
4242
task('sw:system:install', static function () {
43-
run('cd {{release_path}} && bin/console system:install');
43+
run('cd {{release_or_current_path}} && bin/console system:install');
4444
});
4545
task('sw:build', static function () {
46-
run('cd {{release_path}}/bin && bash build.sh');
46+
run('cd {{release_or_current_path}}/bin && bash build.sh');
4747
});
4848
task('sw:system:setup', static function () {
49-
run('cd {{release_path}} && bin/console system:setup');
49+
run('cd {{release_or_current_path}} && bin/console system:setup');
5050
});
5151
task('sw:theme:compile', static function () {
52-
run('cd {{release_path}} && bin/console theme:compile');
52+
run('cd {{release_or_current_path}} && bin/console theme:compile');
5353
});
5454
task('sw:cache:clear', static function () {
55-
run('cd {{release_path}} && bin/console cache:clear');
55+
run('cd {{release_or_current_path}} && bin/console cache:clear');
5656
});
5757
task('sw:cache:warmup', static function () {
58-
run('cd {{release_path}} && bin/console cache:warmup');
59-
run('cd {{release_path}} && bin/console http:cache:warm:up');
58+
run('cd {{release_or_current_path}} && bin/console cache:warmup');
59+
run('cd {{release_or_current_path}} && bin/console http:cache:warm:up');
6060
});
6161
task('sw:database:migrate', static function () {
62-
run('cd {{release_path}} && bin/console database:migrate --all');
62+
run('cd {{release_or_current_path}} && bin/console database:migrate --all');
6363
});
6464
task('sw:plugin:refresh', function () {
65-
run('cd {{release_path}} && bin/console plugin:refresh');
65+
run('cd {{release_or_current_path}} && bin/console plugin:refresh');
6666
});
6767
/**
6868
* @return array
@@ -71,7 +71,7 @@
7171
*/
7272
function getSortedPlugins(): array
7373
{
74-
cd('{{release_path}}');
74+
cd('{{release_or_current_path}}');
7575
$plugins = explode("\n", run('bin/console plugin:list'));
7676

7777
// take line over headlines and count "-" to get the size of the cells
@@ -146,7 +146,7 @@ static function ($composerName) use ($pluginMapping) {
146146
] = $pluginInfo;
147147

148148
if ($installed === 'No' || $active === 'No') {
149-
run("cd {{release_path}} && bin/console plugin:install --activate $plugin");
149+
run("cd {{release_or_current_path}} && bin/console plugin:install --activate $plugin");
150150
}
151151
}
152152
});
@@ -166,7 +166,7 @@ static function ($composerName) use ($pluginMapping) {
166166
] = $pluginInfo;
167167

168168
if ($installed === 'Yes' || $active === 'Yes') {
169-
run("cd {{release_path}} && bin/console database:migrate --all $plugin || true");
169+
run("cd {{release_or_current_path}} && bin/console database:migrate --all $plugin || true");
170170
}
171171
}
172172
});

Diff for: recipe/silverstripe.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
set('shared_assets', function () {
13-
if (test('[ -d {{release_path}}/public ]') || test('[ -d {{deploy_path}}/shared/public ]')) {
13+
if (test('[ -d {{release_or_current_path}}/public ]') || test('[ -d {{deploy_path}}/shared/public ]')) {
1414
return 'public/assets';
1515
}
1616
return 'assets';
@@ -34,7 +34,7 @@
3434
'vendor/silverstripe/framework/cli-script.php'
3535
];
3636
foreach ($paths as $path) {
37-
if (test('[ -f {{release_path}}/'.$path.' ]')) {
37+
if (test('[ -f {{release_or_current_path}}/'.$path.' ]')) {
3838
return $path;
3939
}
4040
}
@@ -45,12 +45,12 @@
4545
*/
4646
desc('Run /dev/build');
4747
task('silverstripe:build', function () {
48-
return run('{{bin/php}} {{release_path}}/{{silverstripe_cli_script}} /dev/build');
48+
return run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build');
4949
});
5050

5151
desc('Run /dev/build?flush=all');
5252
task('silverstripe:buildflush', function () {
53-
return run('{{bin/php}} {{release_path}}/{{silverstripe_cli_script}} /dev/build flush=all');
53+
return run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build flush=all');
5454
});
5555

5656
/**

Diff for: recipe/sulu.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
add('writable_dirs', ['public/uploads']);
1212

1313
set('bin/websiteconsole', function () {
14-
return parse('{{bin/php}} {{release_path}}/bin/websiteconsole --no-interaction');
14+
return parse('{{bin/php}} {{release_or_current_path}}/bin/websiteconsole --no-interaction');
1515
});
1616

1717
desc('Migrate PHPCR');

Diff for: recipe/symfony.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
set('migrations_config', '');
2929

30-
set('bin/console', '{{bin/php}} {{release_path}}/bin/console');
30+
set('bin/console', '{{bin/php}} {{release_or_current_path}}/bin/console');
3131

3232
set('console_options', function () {
3333
return '--no-interaction';
@@ -37,10 +37,10 @@
3737
task('database:migrate', function () {
3838
$options = '--allow-no-migration';
3939
if (get('migrations_config') !== '') {
40-
$options = "$options --configuration={{release_path}}/{{migrations_config}}";
40+
$options = "$options --configuration={{release_or_current_path}}/{{migrations_config}}";
4141
}
4242

43-
run("cd {{release_path}} && {{bin/console}} doctrine:migrations:migrate $options {{console_options}}");
43+
run("cd {{release_or_current_path}} && {{bin/console}} doctrine:migrations:migrate $options {{console_options}}");
4444
});
4545

4646
desc('Clear cache');

0 commit comments

Comments
 (0)