mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Merge pull request #321 from mlocati/composer-specific-version
Allow installing a specific Composer version
This commit is contained in:
commit
d1510a82d5
@ -222,9 +222,17 @@ describe('Tools tests', () => {
|
||||
'a',
|
||||
'b'
|
||||
]);
|
||||
expect(await tools.addComposer(['a', 'b', 'composer:1.2'])).toStrictEqual([
|
||||
'composer',
|
||||
'a',
|
||||
'b'
|
||||
]);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'composer:1.2.3'])
|
||||
).toStrictEqual(['composer', 'a', 'b']);
|
||||
).toStrictEqual(['composer:1.2.3', 'a', 'b']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'composer:v1.2.3'])
|
||||
).toStrictEqual(['composer:1.2.3', 'a', 'b']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'composer:snapshot'])
|
||||
).toStrictEqual(['composer:snapshot', 'a', 'b']);
|
||||
@ -267,6 +275,15 @@ describe('Tools tests', () => {
|
||||
expect(await tools.getComposerUrl('2')).toContain(
|
||||
'https://getcomposer.org/composer-2.phar'
|
||||
);
|
||||
expect(await tools.getComposerUrl('1.7.2')).toContain(
|
||||
'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
|
||||
);
|
||||
expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
|
||||
'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
|
||||
);
|
||||
expect(await tools.getComposerUrl('wrong')).toContain(
|
||||
'https://getcomposer.org/composer-stable.phar'
|
||||
);
|
||||
});
|
||||
|
||||
it('checking getSymfonyUri', async () => {
|
||||
@ -295,7 +312,7 @@ describe('Tools tests', () => {
|
||||
|
||||
it('checking getCleanedToolsList', async () => {
|
||||
const tools_list: string[] = await tools.getCleanedToolsList(
|
||||
'tool, composer:1.2.3, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex'
|
||||
'tool, composer:1.2, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex'
|
||||
);
|
||||
expect(tools_list).toStrictEqual([
|
||||
'composer',
|
||||
|
8
dist/index.js
vendored
8
dist/index.js
vendored
@ -2022,7 +2022,7 @@ exports.getWpCliUrl = getWpCliUrl;
|
||||
*/
|
||||
async function addComposer(tools_list) {
|
||||
const regex_any = /^composer($|:.*)/;
|
||||
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
|
||||
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
||||
const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/;
|
||||
const matches = tools_list.filter(tool => regex_valid.test(tool));
|
||||
let composer = 'composer';
|
||||
@ -2034,7 +2034,7 @@ async function addComposer(tools_list) {
|
||||
case matches[0] == undefined:
|
||||
break;
|
||||
default:
|
||||
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
|
||||
composer = matches[matches.length - 1].replace(/v(\d\S*)/, '$1');
|
||||
break;
|
||||
}
|
||||
tools_list.unshift(composer);
|
||||
@ -2058,6 +2058,10 @@ async function getComposerUrl(version) {
|
||||
case '2':
|
||||
return (cache_url + 'https://getcomposer.org/composer-' + version + '.phar');
|
||||
default:
|
||||
if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) {
|
||||
return (cache_url +
|
||||
`https://github.com/composer/composer/releases/download/${version}/composer.phar`);
|
||||
}
|
||||
return cache_url + 'https://getcomposer.org/composer-stable.phar';
|
||||
}
|
||||
}
|
||||
|
10
src/tools.ts
10
src/tools.ts
@ -305,7 +305,7 @@ export async function getWpCliUrl(version: string): Promise<string> {
|
||||
*/
|
||||
export async function addComposer(tools_list: string[]): Promise<string[]> {
|
||||
const regex_any = /^composer($|:.*)/;
|
||||
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
|
||||
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
||||
const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/;
|
||||
const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
|
||||
let composer = 'composer';
|
||||
@ -317,7 +317,7 @@ export async function addComposer(tools_list: string[]): Promise<string[]> {
|
||||
case matches[0] == undefined:
|
||||
break;
|
||||
default:
|
||||
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
|
||||
composer = matches[matches.length - 1].replace(/v(\d\S*)/, '$1');
|
||||
break;
|
||||
}
|
||||
tools_list.unshift(composer);
|
||||
@ -344,6 +344,12 @@ export async function getComposerUrl(version: string): Promise<string> {
|
||||
cache_url + 'https://getcomposer.org/composer-' + version + '.phar'
|
||||
);
|
||||
default:
|
||||
if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) {
|
||||
return (
|
||||
cache_url +
|
||||
`https://github.com/composer/composer/releases/download/${version}/composer.phar`
|
||||
);
|
||||
}
|
||||
return cache_url + 'https://getcomposer.org/composer-stable.phar';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user