Skip to content

Commit 3e3ea6c

Browse files
Install specific Composer version (#4159)
1 parent 263c290 commit 3e3ea6c

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

docs/recipe/deploy/vendors.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require 'recipe/deploy/vendors.php';
2323

2424

2525
### composer_options
26-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/vendors.php#L7)
26+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/vendors.php#L6)
2727

2828

2929

@@ -32,12 +32,20 @@ require 'recipe/deploy/vendors.php';
3232
```
3333

3434

35+
### composer_version
36+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/vendors.php#L7)
37+
38+
39+
40+
```php title="Default value"
41+
null
42+
```
43+
44+
3545
### bin/composer
36-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/vendors.php#L12)
46+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/vendors.php#L10)
3747

38-
Returns Composer binary path in found. Otherwise try to install latest
39-
composer version to `.dep/composer.phar`. To use specific composer version
40-
download desired phar and place it at `.dep/composer.phar`.
48+
Returns Composer binary path if found. Otherwise, tries to install composer to `.dep/composer.phar`.
4149
:::info Autogenerated
4250
The value of this configuration is autogenerated on access.
4351
:::
@@ -49,7 +57,7 @@ The value of this configuration is autogenerated on access.
4957
## Tasks
5058

5159
### deploy\:vendors {#deploy-vendors}
52-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/vendors.php#L28)
60+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/vendors.php#L32)
5361

5462
Installs vendors.
5563

recipe/deploy/vendors.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@
33
namespace Deployer;
44

55
set('composer_action', 'install');
6-
76
set('composer_options', '--verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');
7+
set('composer_version', null);
88

9-
// Returns Composer binary path in found. Otherwise try to install latest
10-
// composer version to `.dep/composer.phar`. To use specific composer version
11-
// download desired phar and place it at `.dep/composer.phar`.
9+
// Returns Composer binary path if found. Otherwise, tries to install composer to `.dep/composer.phar`.
1210
set('bin/composer', function () {
1311
if (test('[ -f {{deploy_path}}/.dep/composer.phar ]')) {
14-
return '{{bin/php}} {{deploy_path}}/.dep/composer.phar';
12+
if (empty(get('composer_version')) || preg_match(parse('/Composer.*{{composer_version}}/'), run('{{bin/php}} {{deploy_path}}/.dep/composer.phar --version'))) {
13+
return '{{bin/php}} {{deploy_path}}/.dep/composer.phar';
14+
}
1515
}
1616

1717
if (commandExist('composer')) {
18-
return '{{bin/php}} ' . which('composer');
18+
if (empty(get('composer_version')) || preg_match(parse('/Composer.*{{composer_version}}/'), run('{{bin/php}} ' . which('composer') . ' --version'))) {
19+
return '{{bin/php}} ' . which('composer');
20+
}
1921
}
2022

21-
warning("Composer binary wasn't found. Installing latest composer to \"{{deploy_path}}/.dep/composer.phar\".");
22-
run("cd {{deploy_path}} && curl -sS https://getcomposer.org/installer | {{bin/php}}");
23+
$versionAsName = get('composer_version') ? ' {{composer_version}}' : '';
24+
$versionAsOption = get('composer_version') ? ' -- --version={{composer_version}}' : '';
25+
warning("Composer{$versionAsName} wasn't found. Installing to \"{{deploy_path}}/.dep/composer.phar\".");
26+
run("cd {{deploy_path}} && curl -sS https://getcomposer.org/installer | {{bin/php}}{$versionAsOption}");
2327
run('mv {{deploy_path}}/composer.phar {{deploy_path}}/.dep/composer.phar');
2428
return '{{bin/php}} {{deploy_path}}/.dep/composer.phar';
2529
});

0 commit comments

Comments
 (0)