From 48f537d6d0f72b88bff65151ba5129e46b1f87c8 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Fri, 30 Oct 2020 11:15:26 +0100 Subject: [PATCH] Allow installing a specific Composer version --- __tests__/tools.test.ts | 9 +++++++++ dist/index.js | 4 ++++ src/tools.ts | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 36360496..9f512a9f 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -285,6 +285,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 () => { diff --git a/dist/index.js b/dist/index.js index 96c74204..d94e575f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1930,6 +1930,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'; } } diff --git a/src/tools.ts b/src/tools.ts index d39baf0c..c63e3dbe 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -321,6 +321,12 @@ export async function getComposerUrl(version: string): Promise { 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'; } }