Refactor composer setup

This commit is contained in:
Shivam Mathur 2020-10-30 18:29:39 +05:30
parent 5c4074b01a
commit e201830bdd
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
4 changed files with 34 additions and 37 deletions

View File

@ -86,7 +86,8 @@ with:
``` ```
To set up a particular version of a tool, specify it in the form `tool:version`. To set up a particular version of a tool, specify it in the form `tool:version`.
Latest stable version of `composer` is setup by default and accepts `v1`, `v2`, `snapshot` and `preview` as versions.
The latest stable version of `composer` is set up by default. You can set up the required `composer` version by specifying `v1`, `v2`, `snapshot` or `preview` as versions or the exact version in semver format.
```yaml ```yaml
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v1
@ -95,6 +96,8 @@ with:
tools: composer:v2 tools: composer:v2
``` ```
If you have specified composer plugins `prestissimo` or `composer-prefetcher` in tools, the latest stable version of `composer v1` will be setup. Unless some of your packages require `composer v1`, it is recommended to drop `prestissimo` and use `composer v2`.
Version for other tools should be in `semver` format and a valid release of the tool. Version for other tools should be in `semver` format and a valid release of the tool.
```yaml ```yaml

View File

@ -296,9 +296,15 @@ describe('Tools tests', () => {
expect(await tools.getComposerUrl('1.7.2')).toContain( expect(await tools.getComposerUrl('1.7.2')).toContain(
'https://github.com/composer/composer/releases/download/1.7.2/composer.phar' 'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
); );
expect(await tools.getComposerUrl('1.7.2')).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')).toContain(
'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar' 'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
); );
expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
'https://getcomposer.org/composer-2.0.0-RC2.phar'
);
expect(await tools.getComposerUrl('wrong')).toContain( expect(await tools.getComposerUrl('wrong')).toContain(
'https://getcomposer.org/composer-stable.phar' 'https://getcomposer.org/composer-stable.phar'
); );

25
dist/index.js vendored
View File

@ -1919,22 +1919,17 @@ exports.addComposer = addComposer;
* @param version * @param version
*/ */
async function getComposerUrl(version) { async function getComposerUrl(version) {
const cache_url = 'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-' + let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace('latest', 'stable')}.phar`;
version.replace('latest', 'stable') + switch (true) {
'.phar,'; case /^snapshot$/.test(version):
switch (version) { return `${cache_url},https://getcomposer.org/composer.phar`;
case 'snapshot': case /^preview$|^[1-2]$/.test(version):
return cache_url + 'https://getcomposer.org/composer.phar'; return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
case 'preview': case /^\d+\.\d+\.\d+[\w-]*$/.test(version):
case '1': cache_url = `https://github.com/composer/composer/releases/download/${version}/composer.phar`;
case '2': return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
return (cache_url + 'https://getcomposer.org/composer-' + version + '.phar');
default: default:
if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) { return `${cache_url},https://getcomposer.org/composer-stable.phar`;
return (cache_url +
`https://github.com/composer/composer/releases/download/${version}/composer.phar`);
}
return cache_url + 'https://getcomposer.org/composer-stable.phar';
} }
} }
exports.getComposerUrl = getComposerUrl; exports.getComposerUrl = getComposerUrl;

View File

@ -307,27 +307,20 @@ export async function addComposer(tools_list: string[]): Promise<string[]> {
* @param version * @param version
*/ */
export async function getComposerUrl(version: string): Promise<string> { export async function getComposerUrl(version: string): Promise<string> {
const cache_url = let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace(
'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-' + 'latest',
version.replace('latest', 'stable') + 'stable'
'.phar,'; )}.phar`;
switch (version) { switch (true) {
case 'snapshot': case /^snapshot$/.test(version):
return cache_url + 'https://getcomposer.org/composer.phar'; return `${cache_url},https://getcomposer.org/composer.phar`;
case 'preview': case /^preview$|^[1-2]$/.test(version):
case '1': return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
case '2': case /^\d+\.\d+\.\d+[\w-]*$/.test(version):
return ( cache_url = `https://github.com/composer/composer/releases/download/${version}/composer.phar`;
cache_url + 'https://getcomposer.org/composer-' + version + '.phar' return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
);
default: default:
if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) { return `${cache_url},https://getcomposer.org/composer-stable.phar`;
return (
cache_url +
`https://github.com/composer/composer/releases/download/${version}/composer.phar`
);
}
return cache_url + 'https://getcomposer.org/composer-stable.phar';
} }
} }