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

@ -85,8 +85,9 @@ with:
tools: php-cs-fixer, phpunit
```
To setup 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.
To set up a particular version of a tool, specify it in the form `tool:version`.
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
uses: shivammathur/setup-php@v1
@ -95,6 +96,8 @@ with:
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.
```yaml

View File

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

25
dist/index.js vendored
View File

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

View File

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