Add no_tools_cache flag

This commit is contained in:
Shivam Mathur 2021-07-23 13:59:16 +05:30
parent 0b38e86c65
commit 7bd9f10bef
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 23 additions and 15 deletions

View File

@ -256,26 +256,32 @@ describe('Tools tests', () => {
}); });
it.each` it.each`
version | cache_url | source_url version | no_tool_cache | cache_url | source_url
${'latest'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar'} | ${'https://getcomposer.org/composer-stable.phar'} ${'latest'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar'} | ${'https://getcomposer.org/composer-stable.phar'}
${'stable'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar'} | ${'https://getcomposer.org/composer-stable.phar'} ${'stable'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar'} | ${'https://getcomposer.org/composer-stable.phar'}
${'snapshot'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar'} | ${'https://getcomposer.org/composer.phar'} ${'snapshot'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar'} | ${'https://getcomposer.org/composer.phar'}
${'preview'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar'} | ${'https://getcomposer.org/composer-preview.phar'} ${'preview'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar'} | ${'https://getcomposer.org/composer-preview.phar'}
${'1'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar'} | ${'https://getcomposer.org/composer-1.phar'} ${'1'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar'} | ${'https://getcomposer.org/composer-1.phar'}
${'2'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-2.phar'} | ${'https://getcomposer.org/composer-2.phar'} ${'2'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-2.phar'} | ${'https://getcomposer.org/composer-2.phar'}
${'1.2.3'} | ${'https://github.com/composer/composer/releases/download/1.2.3/composer.phar'} | ${'https://getcomposer.org/composer-1.2.3.phar'} ${'1.2.3'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3/composer.phar'} | ${'https://getcomposer.org/composer-1.2.3.phar'}
${'1.2.3-RC1'} | ${'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'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3-RC1/composer.phar'} | ${'https://getcomposer.org/composer-1.2.3-RC1.phar'}
`( `(
'checking addComposer: $version', 'checking addComposer: $version, $no_tool_cache',
async ({version, cache_url, source_url}) => { async ({version, no_tool_cache, cache_url, source_url}) => {
const data = getData({ const data = getData({
tool: 'composer', tool: 'composer',
domain: 'https://getcomposer.org', domain: 'https://getcomposer.org',
repository: 'composer/composer', repository: 'composer/composer',
version: version version: version
}); });
expect(await tools.addComposer(data)).toContain(cache_url); process.env['no_tools_cache'] = no_tool_cache;
expect(await tools.addComposer(data)).toContain(source_url); if (no_tool_cache !== 'true') {
expect(await tools.addComposer(data)).toContain(
`${cache_url},${source_url}`
);
} else {
expect(await tools.addComposer(data)).toContain(source_url);
}
} }
); );

3
dist/index.js vendored
View File

@ -638,7 +638,8 @@ async function addComposer(data) {
default: default:
source_url = `${getcomposer}/composer-stable.phar`; source_url = `${getcomposer}/composer-stable.phar`;
} }
data['url'] = `${cache_url},${source_url}`; const use_cache = (await utils.readEnv('NO_TOOLS_CACHE')) !== 'true';
data['url'] = use_cache ? `${cache_url},${source_url}` : source_url;
data['version_parameter'] = data['version']; data['version_parameter'] = data['version'];
return await addArchive(data); return await addArchive(data);
} }

View File

@ -212,7 +212,8 @@ export async function addComposer(data: RS): Promise<string> {
default: default:
source_url = `${getcomposer}/composer-stable.phar`; source_url = `${getcomposer}/composer-stable.phar`;
} }
data['url'] = `${cache_url},${source_url}`; const use_cache: boolean = (await utils.readEnv('NO_TOOLS_CACHE')) !== 'true';
data['url'] = use_cache ? `${cache_url},${source_url}` : source_url;
data['version_parameter'] = data['version']; data['version_parameter'] = data['version'];
return await addArchive(data); return await addArchive(data);
} }