|
3 | 3 | namespace Deployer; |
4 | 4 |
|
5 | 5 | set('composer_action', 'install'); |
6 | | - |
7 | 6 | set('composer_options', '--verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader'); |
| 7 | +set('composer_version', null); |
8 | 8 |
|
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`. |
12 | 10 | set('bin/composer', function () { |
13 | 11 | 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 | + } |
15 | 15 | } |
16 | 16 |
|
17 | 17 | 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 | + } |
19 | 21 | } |
20 | 22 |
|
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}"); |
23 | 27 | run('mv {{deploy_path}}/composer.phar {{deploy_path}}/.dep/composer.phar'); |
24 | 28 | return '{{bin/php}} {{deploy_path}}/.dep/composer.phar'; |
25 | 29 | }); |
|
0 commit comments