Fix composer setup for Composer 2.3 changes

This commit is contained in:
Shivam Mathur 2022-04-09 20:16:48 +05:30
parent aa0ecfbc6f
commit 0e506b34ac
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 27 additions and 24 deletions

View File

@ -198,37 +198,37 @@ describe('Tools tests', () => {
});
it('checking getComposerUrl', async () => {
expect(await tools.getComposerUrl('latest')).toContain(
expect(await tools.getComposerUrl('latest', '7.4')).toContain(
'https://getcomposer.org/composer-stable.phar'
);
expect(await tools.getComposerUrl('stable')).toContain(
expect(await tools.getComposerUrl('stable', '7.4')).toContain(
'https://getcomposer.org/composer-stable.phar'
);
expect(await tools.getComposerUrl('snapshot')).toContain(
expect(await tools.getComposerUrl('snapshot', '7.4')).toContain(
'https://getcomposer.org/composer.phar'
);
expect(await tools.getComposerUrl('preview')).toContain(
expect(await tools.getComposerUrl('preview', '7.4')).toContain(
'https://getcomposer.org/composer-preview.phar'
);
expect(await tools.getComposerUrl('1')).toContain(
expect(await tools.getComposerUrl('1', '7.4')).toContain(
'https://getcomposer.org/composer-1.phar'
);
expect(await tools.getComposerUrl('2')).toContain(
expect(await tools.getComposerUrl('2', '7.4')).toContain(
'https://getcomposer.org/composer-2.phar'
);
expect(await tools.getComposerUrl('1.7.2')).toContain(
expect(await tools.getComposerUrl('1.7.2', '7.4')).toContain(
'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
);
expect(await tools.getComposerUrl('1.7.2')).toContain(
expect(await tools.getComposerUrl('1.7.2', '7.4')).toContain(
'https://getcomposer.org/composer-1.7.2.phar'
);
expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
expect(await tools.getComposerUrl('2.0.0-RC2', '7.4')).toContain(
'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
);
expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
expect(await tools.getComposerUrl('2.0.0-RC2', '7.4')).toContain(
'https://getcomposer.org/composer-2.0.0-RC2.phar'
);
expect(await tools.getComposerUrl('wrong')).toContain(
expect(await tools.getComposerUrl('wrong', '7.4')).toContain(
'https://getcomposer.org/composer-stable.phar'
);
});
@ -347,7 +347,7 @@ describe('Tools tests', () => {
'linux'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer'
);
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
@ -381,7 +381,7 @@ describe('Tools tests', () => {
'darwin'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer'
);
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr'
@ -418,7 +418,7 @@ describe('Tools tests', () => {
'win32'
);
expect(script).toContain(
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer'
);
expect(script).toContain(
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
@ -447,7 +447,7 @@ describe('Tools tests', () => {
'win32'
);
expect(script).toContain(
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer'
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer'
);
expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/');
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
@ -462,12 +462,12 @@ describe('Tools tests', () => {
'linux'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer'
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer'
);
script = await tools.addTools('composer:preview', '7.4', 'linux');
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar,https://getcomposer.org/composer-preview.phar composer'
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-preview.phar,https://getcomposer.org/composer-preview.phar composer'
);
script = await tools.addTools(
'composer:v1, composer:preview, composer:snapshot',
@ -475,7 +475,7 @@ describe('Tools tests', () => {
'linux'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar,https://getcomposer.org/composer.phar composer'
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-snapshot.phar,https://getcomposer.org/composer.phar composer'
);
});
});

6
dist/index.js vendored
View File

@ -675,8 +675,8 @@ async function addComposer(tools_list) {
return tools_list;
}
exports.addComposer = addComposer;
async function getComposerUrl(version) {
let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace('latest', 'stable')}.phar`;
async function getComposerUrl(version, php_version) {
let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${php_version}-${version.replace('latest', 'stable')}.phar`;
switch (true) {
case /^snapshot$/.test(version):
return `${cache_url},https://getcomposer.org/composer.phar`;
@ -770,7 +770,7 @@ async function addTools(tools_csv, php_version, os_version) {
script += await addArchive(tool, url, os_version);
break;
case 'composer':
url = await getComposerUrl(version);
url = await getComposerUrl(version, php_version);
script += await addArchive('composer', url, os_version);
break;
case 'codeception':

View File

@ -245,8 +245,11 @@ export async function addComposer(tools_list: string[]): Promise<string[]> {
*
* @param version
*/
export async function getComposerUrl(version: string): Promise<string> {
let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace(
export async function getComposerUrl(
version: string,
php_version: string
): Promise<string> {
let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${php_version}-${version.replace(
'latest',
'stable'
)}.phar`;
@ -415,7 +418,7 @@ export async function addTools(
script += await addArchive(tool, url, os_version);
break;
case 'composer':
url = await getComposerUrl(version);
url = await getComposerUrl(version, php_version);
script += await addArchive('composer', url, os_version);
break;
case 'codeception':