Fix getcomposer fallback url for specific versions

This commit is contained in:
Shivam Mathur
2025-11-21 01:02:19 +05:30
parent 4eb1b49da1
commit 2c40db3599
3 changed files with 8 additions and 7 deletions

View File

@ -383,8 +383,8 @@ describe('Tools tests', () => {
${'preview'} | ${'7.1'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.1-preview.phar'} | ${'https://getcomposer.org/download/latest-2.2.x/composer.phar'} ${'preview'} | ${'7.1'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.1-preview.phar'} | ${'https://getcomposer.org/download/latest-2.2.x/composer.phar'}
${'1'} | ${'7.1'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.1-1.phar'} | ${'https://getcomposer.org/composer-1.phar'} ${'1'} | ${'7.1'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.1-1.phar'} | ${'https://getcomposer.org/composer-1.phar'}
${'2'} | ${'7.1'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.1-2.phar'} | ${'https://getcomposer.org/download/latest-2.2.x/composer.phar'} ${'2'} | ${'7.1'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.1-2.phar'} | ${'https://getcomposer.org/download/latest-2.2.x/composer.phar'}
${'1.2.3'} | ${'7.4'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3/composer.phar'} | ${'https://getcomposer.org/composer-1.2.3.phar'} ${'1.2.3'} | ${'7.4'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3/composer.phar'} | ${'https://getcomposer.org/download/1.2.3/composer.phar'}
${'1.2.3-RC1'} | ${'7.4'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3-RC1/composer.phar'} | ${'https://getcomposer.org/composer-1.2.3-RC1.phar'} ${'1.2.3-RC1'} | ${'7.4'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3-RC1/composer.phar'} | ${'https://getcomposer.org/download/1.2.3-RC1/composer.phar'}
`( `(
'checking addComposer: $version, $php_version, $no_tool_cache', 'checking addComposer: $version, $php_version, $no_tool_cache',
async ({version, php_version, no_tool_cache, cache_url, source_url}) => { async ({version, php_version, no_tool_cache, cache_url, source_url}) => {

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -290,7 +290,8 @@ export async function addComposer(data: RS): Promise<string> {
const spc_url = `${spc}/composer/${filename}`; const spc_url = `${spc}/composer/${filename}`;
const lts_url = `${getcomposer}/download/latest-2.2.x/composer.phar`; const lts_url = `${getcomposer}/download/latest-2.2.x/composer.phar`;
const is_lts = /^5\.[3-6]$|^7\.[0-1]$/.test(data['php_version']); const is_lts = /^5\.[3-6]$|^7\.[0-1]$/.test(data['php_version']);
const version_source_url = `${getcomposer}/composer-${channel}.phar`; const channel_source_url = `${getcomposer}/composer-${channel}.phar`;
const version_source_url = `${getcomposer}/download/${channel}/composer.phar`;
let cache_url = `${releases_url},${spc_url},${cds_url}`; let cache_url = `${releases_url},${spc_url},${cds_url}`;
let source_url = `${getcomposer}/composer.phar`; let source_url = `${getcomposer}/composer.phar`;
switch (true) { switch (true) {
@ -298,17 +299,17 @@ export async function addComposer(data: RS): Promise<string> {
source_url = is_lts ? lts_url : source_url; source_url = is_lts ? lts_url : source_url;
break; break;
case /^preview$|^2$/.test(channel): case /^preview$|^2$/.test(channel):
source_url = is_lts ? lts_url : version_source_url; source_url = is_lts ? lts_url : channel_source_url;
break; break;
case /^1$/.test(channel): case /^1$/.test(channel):
source_url = version_source_url; source_url = channel_source_url;
break; break;
case /^\d+\.\d+\.\d+[\w-]*$/.test(data['version']): case /^\d+\.\d+\.\d+[\w-]*$/.test(data['version']):
cache_url = `${github}/${data['repository']}/releases/download/${data['version']}/composer.phar`; cache_url = `${github}/${data['repository']}/releases/download/${data['version']}/composer.phar`;
source_url = version_source_url; source_url = version_source_url;
break; break;
default: default:
source_url = is_lts ? lts_url : version_source_url; source_url = is_lts ? lts_url : channel_source_url;
} }
const use_cache: boolean = (await utils.readEnv('NO_TOOLS_CACHE')) !== 'true'; const use_cache: boolean = (await utils.readEnv('NO_TOOLS_CACHE')) !== 'true';
data['url'] = use_cache ? `${cache_url},${source_url}` : source_url; data['url'] = use_cache ? `${cache_url},${source_url}` : source_url;