Add support for composer packages using tools input

This commit is contained in:
Shivam Mathur 2021-04-17 02:56:47 +05:30
parent 3c6827c2c3
commit 23393c46d7
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 112 additions and 151 deletions

View File

@ -16,7 +16,7 @@ describe('Tools tests', () => {
expect(await tools.getToolVersion('1.2.3-alpha.1')).toBe('1.2.3-alpha.1');
});
it('checking parseToolVersion', async () => {
it('checking parseTool', async () => {
expect(await tools.parseTool('phpunit')).toStrictEqual({
name: 'phpunit',
version: 'latest'
@ -65,6 +65,10 @@ describe('Tools tests', () => {
name: 'phpunit',
version: '1.2.3-alpha.1'
});
expect(await tools.parseTool('phpunit/phpunit:^1.2.3')).toStrictEqual({
name: 'phpunit/phpunit',
version: '^1.2.3'
});
});
it('checking getUri', async () => {
@ -234,22 +238,6 @@ describe('Tools tests', () => {
);
});
it('checking getCleanedToolsList', async () => {
const tools_list: string[] = await tools.getCleanedToolsList(
'tool, composer:1.2, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex'
);
expect(tools_list).toStrictEqual([
'composer',
'tool',
'behat',
'composer-unused',
'vapor-cli',
'phinx',
'phpspec',
'flex'
]);
});
it('checking getWpCliUri', async () => {
expect(await tools.getWpCliUrl('latest')).toBe(
'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true'
@ -548,9 +536,11 @@ describe('Tools tests', () => {
const listOfTools = [
'composer:v1',
'codeception/codeception',
'prestissimo',
'hirak/prestissimo',
'composer-prefetcher',
'narrowspark/automatic-composer-prefetcher',
'robmorgan/phinx'
'robmorgan/phinx: ^1.2'
];
const script: string = await tools.addTools(
@ -563,9 +553,9 @@ describe('Tools tests', () => {
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer'
);
expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/');
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
expect(script).toContain('Add-Composertool phinx phinx:^1.2 robmorgan/');
expect(script).toContain(
'Add-Composertool composer-prefetcher composer-prefetcher narrowspark/automatic-'
'Add-Composertool automatic-composer-prefetcher automatic-composer-prefetcher narrowspark/'
);
});
it('checking composer setup', async () => {

109
dist/index.js vendored
View File

@ -2162,7 +2162,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addTools = exports.addPackage = exports.addDevTools = exports.addArchive = exports.getCleanedToolsList = exports.getComposerUrl = exports.addComposer = exports.getWpCliUrl = exports.getSymfonyUri = exports.getDeployerUrl = exports.getBlackfirePlayerUrl = exports.getPharUrl = exports.addPhive = exports.getUri = exports.parseTool = exports.getToolVersion = void 0;
exports.addTools = exports.addPackage = exports.addDevTools = exports.addArchive = exports.getComposerUrl = exports.addComposer = exports.getWpCliUrl = exports.getSymfonyUri = exports.getDeployerUrl = exports.getBlackfirePlayerUrl = exports.getPharUrl = exports.addPhive = exports.getUri = exports.parseTool = exports.getToolVersion = void 0;
const utils = __importStar(__nccwpck_require__(314));
/**
* Function to get tool version
@ -2194,12 +2194,17 @@ async function parseTool(release) {
const parts = release.split(':');
const tool = parts[0];
const version = parts[1];
switch (version) {
case undefined:
switch (true) {
case version === undefined:
return {
name: tool,
version: 'latest'
};
case /^[\w.-]+\/[\w.-]+$/.test(tool):
return {
name: tool,
version: version
};
default:
return {
name: tool,
@ -2395,24 +2400,6 @@ async function getComposerUrl(version) {
}
}
exports.getComposerUrl = getComposerUrl;
/**
* Function to get Tools list after cleanup
*
* @param tools_csv
*/
async function getCleanedToolsList(tools_csv) {
let tools_list = await utils.CSVArray(tools_csv);
tools_list = await addComposer(tools_list);
tools_list = tools_list
.map(function (extension) {
return extension
.trim()
.replace(/-agent|behat\/|codeception\/|hirak\/|icanhazstring\/|laravel\/|narrowspark\/automatic-|overtrue\/|phpspec\/|robmorgan\/|symfony\//, '');
})
.filter(Boolean);
return [...new Set(tools_list)];
}
exports.getCleanedToolsList = getCleanedToolsList;
/**
* Helper function to get script to setup a tool using a phar url
*
@ -2466,7 +2453,7 @@ exports.addPackage = addPackage;
*/
async function addTools(tools_csv, php_version, os_version) {
let script = '\n' + (await utils.stepLog('Setup Tools', os_version));
const tools_list = await getCleanedToolsList(tools_csv);
const tools_list = await addComposer(await utils.CSVArray(tools_csv));
await utils.asyncForEach(tools_list, async function (release) {
const tool_data = await parseTool(release);
const tool = tool_data.name;
@ -2475,126 +2462,122 @@ async function addTools(tools_csv, php_version, os_version) {
let uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
script += '\n';
let url = '';
switch (tool) {
case 'blackfire':
case 'grpc_php_plugin':
case 'protoc':
switch (true) {
case /^blackfire(-agent)?$/.test(tool):
script += await utils.customPackage('blackfire', 'tools', version, os_version);
break;
case /^grpc_php_plugin$|^protoc$/.test(tool):
script += await utils.customPackage(tool, 'tools', version, os_version);
break;
case 'behat':
case 'codeception':
case 'phpspec':
case /^behat$|^codeception$|^phpspec$/.test(tool):
script += await addPackage(tool, release, tool + '/', os_version);
break;
case 'blackfire-player':
case /^blackfire-player$/.test(tool):
url = await getBlackfirePlayerUrl(version, php_version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'composer':
case /^composer$/.test(tool):
url = await getComposerUrl(version);
script += await addArchive('composer', url, os_version, version);
break;
case 'composer-normalize':
case /^composer-normalize$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
url = github + 'ergebnis/composer-normalize/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'composer-prefetcher':
script += await addPackage(tool, release, 'narrowspark/automatic-', os_version);
case /^composer-prefetcher$/.test(tool):
script += await addPackage('automatic-' + tool, release, 'narrowspark/', os_version);
break;
case 'composer-require-checker':
case /^composer-require-checker$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
url = github + 'maglnet/ComposerRequireChecker/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'composer-unused':
case /^composer-unused$/.test(tool):
script += await addPackage(tool, release, 'icanhazstring/', os_version);
break;
case 'cs2pr':
case /^cs2pr$/.test(tool):
uri = await getUri(tool, '', version, 'releases', '', 'download');
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'deployer':
case /^deployer$/.test(tool):
url = await getDeployerUrl(version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'flex':
case /^flex$/.test(tool):
script += await addPackage(tool, release, 'symfony/', os_version);
break;
case 'infection':
case /^infection$/.test(tool):
url = github + 'infection/infection/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'pecl':
case /^pecl/.test(tool):
script += await utils.getCommand(os_version, 'pecl');
break;
case 'phan':
case /^phan$/.test(tool):
url = github + 'phan/phan/' + uri;
script += await addArchive(tool, url, os_version, '"-v"');
break;
case 'phing':
case /^phing$/.test(tool):
url = 'https://www.phing.info/get/phing-' + version + '.phar';
script += await addArchive(tool, url, os_version, '"-v"');
break;
case 'phinx':
case /^phinx$/.test(tool):
script += await addPackage(tool, release, 'robmorgan/', os_version);
break;
case 'phive':
case /^phive$/.test(tool):
script += await addPhive(version, php_version, os_version);
break;
case 'php-config':
case 'phpize':
case /^php(-config|ize)$/.test(tool):
script += await addDevTools(tool, os_version);
break;
case 'php-cs-fixer':
case /^php-cs-fixer$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'phpcbf':
case 'phpcs':
case /^php(cbf|cs)$/.test(tool):
url = github + 'squizlabs/PHP_CodeSniffer/' + uri;
script += await addArchive(tool, url, os_version, '"--version"');
break;
case 'phpcpd':
case 'phpunit':
case /^php(cpd|unit)$/.test(tool):
url = await getPharUrl('https://phar.phpunit.de', tool, '', version);
script += await addArchive(tool, url, os_version, '"--version"');
break;
case 'phplint':
case /^phplint$/.test(tool):
script += await addPackage(tool, release, 'overtrue/', os_version);
break;
case 'phpmd':
case /^phpmd$/.test(tool):
url = github + 'phpmd/phpmd/' + uri;
script += await addArchive(tool, url, os_version, '"--version"');
break;
case 'phpstan':
case /^phpstan$/.test(tool):
url = github + 'phpstan/phpstan/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'prestissimo':
case /^prestissimo$/.test(tool):
script += await addPackage(tool, release, 'hirak/', os_version);
break;
case 'psalm':
case /^psalm$/.test(tool):
url = github + 'vimeo/psalm/' + uri;
script += await addArchive(tool, url, os_version, '"-v"');
break;
case 'symfony':
case 'symfony-cli':
case /^symfony(-cli)?$/.test(tool):
uri = await getSymfonyUri(version, os_version);
url = github + 'symfony/cli/' + uri;
script += await addArchive('symfony', url, os_version, 'version');
break;
case 'vapor-cli':
case 'vapor':
case /^vapor(-cli)?$/.test(tool):
script += await addPackage('vapor-cli', release, 'laravel/', os_version);
break;
case 'wp':
case 'wp-cli':
case /^wp(-cli)?$/.test(tool):
url = github + (await getWpCliUrl(version));
script += await addArchive('wp-cli', url, os_version, '"--version"');
break;
case /^[\w.-]+\/[\w.-]+$/.test(tool):
script += await addPackage(tool.split('/')[1], release.split('/')[1].replace(/\s+/, ''), tool.split('/')[0] + '/', os_version);
break;
default:
script += await utils.addLog('$cross', tool, 'Tool ' + tool + ' is not supported', os_version);
break;

View File

@ -32,12 +32,17 @@ export async function parseTool(
const parts: string[] = release.split(':');
const tool: string = parts[0];
const version: string | undefined = parts[1];
switch (version) {
case undefined:
switch (true) {
case version === undefined:
return {
name: tool,
version: 'latest'
};
case /^[\w.-]+\/[\w.-]+$/.test(tool):
return {
name: tool,
version: version
};
default:
return {
name: tool,
@ -283,29 +288,6 @@ export async function getComposerUrl(version: string): Promise<string> {
}
}
/**
* Function to get Tools list after cleanup
*
* @param tools_csv
*/
export async function getCleanedToolsList(
tools_csv: string
): Promise<string[]> {
let tools_list: string[] = await utils.CSVArray(tools_csv);
tools_list = await addComposer(tools_list);
tools_list = tools_list
.map(function (extension: string) {
return extension
.trim()
.replace(
/-agent|behat\/|codeception\/|hirak\/|icanhazstring\/|laravel\/|narrowspark\/automatic-|overtrue\/|phpspec\/|robmorgan\/|symfony\//,
''
);
})
.filter(Boolean);
return [...new Set(tools_list)];
}
/**
* Helper function to get script to setup a tool using a phar url
*
@ -387,7 +369,7 @@ export async function addTools(
os_version: string
): Promise<string> {
let script = '\n' + (await utils.stepLog('Setup Tools', os_version));
const tools_list: Array<string> = await getCleanedToolsList(tools_csv);
const tools_list = await addComposer(await utils.CSVArray(tools_csv));
await utils.asyncForEach(tools_list, async function (release: string) {
const tool_data: {name: string; version: string} = await parseTool(release);
const tool: string = tool_data.name;
@ -403,124 +385,123 @@ export async function addTools(
);
script += '\n';
let url = '';
switch (tool) {
case 'blackfire':
case 'grpc_php_plugin':
case 'protoc':
switch (true) {
case /^blackfire(-agent)?$/.test(tool):
script += await utils.customPackage(
'blackfire',
'tools',
version,
os_version
);
break;
case /^grpc_php_plugin$|^protoc$/.test(tool):
script += await utils.customPackage(tool, 'tools', version, os_version);
break;
case 'behat':
case 'codeception':
case 'phpspec':
case /^behat$|^codeception$|^phpspec$/.test(tool):
script += await addPackage(tool, release, tool + '/', os_version);
break;
case 'blackfire-player':
case /^blackfire-player$/.test(tool):
url = await getBlackfirePlayerUrl(version, php_version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'composer':
case /^composer$/.test(tool):
url = await getComposerUrl(version);
script += await addArchive('composer', url, os_version, version);
break;
case 'composer-normalize':
case /^composer-normalize$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
url = github + 'ergebnis/composer-normalize/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'composer-prefetcher':
case /^composer-prefetcher$/.test(tool):
script += await addPackage(
tool,
'automatic-' + tool,
release,
'narrowspark/automatic-',
'narrowspark/',
os_version
);
break;
case 'composer-require-checker':
case /^composer-require-checker$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
url = github + 'maglnet/ComposerRequireChecker/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'composer-unused':
case /^composer-unused$/.test(tool):
script += await addPackage(tool, release, 'icanhazstring/', os_version);
break;
case 'cs2pr':
case /^cs2pr$/.test(tool):
uri = await getUri(tool, '', version, 'releases', '', 'download');
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'deployer':
case /^deployer$/.test(tool):
url = await getDeployerUrl(version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'flex':
case /^flex$/.test(tool):
script += await addPackage(tool, release, 'symfony/', os_version);
break;
case 'infection':
case /^infection$/.test(tool):
url = github + 'infection/infection/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'pecl':
case /^pecl/.test(tool):
script += await utils.getCommand(os_version, 'pecl');
break;
case 'phan':
case /^phan$/.test(tool):
url = github + 'phan/phan/' + uri;
script += await addArchive(tool, url, os_version, '"-v"');
break;
case 'phing':
case /^phing$/.test(tool):
url = 'https://www.phing.info/get/phing-' + version + '.phar';
script += await addArchive(tool, url, os_version, '"-v"');
break;
case 'phinx':
case /^phinx$/.test(tool):
script += await addPackage(tool, release, 'robmorgan/', os_version);
break;
case 'phive':
case /^phive$/.test(tool):
script += await addPhive(version, php_version, os_version);
break;
case 'php-config':
case 'phpize':
case /^php(-config|ize)$/.test(tool):
script += await addDevTools(tool, os_version);
break;
case 'php-cs-fixer':
case /^php-cs-fixer$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'phpcbf':
case 'phpcs':
case /^php(cbf|cs)$/.test(tool):
url = github + 'squizlabs/PHP_CodeSniffer/' + uri;
script += await addArchive(tool, url, os_version, '"--version"');
break;
case 'phpcpd':
case 'phpunit':
case /^php(cpd|unit)$/.test(tool):
url = await getPharUrl('https://phar.phpunit.de', tool, '', version);
script += await addArchive(tool, url, os_version, '"--version"');
break;
case 'phplint':
case /^phplint$/.test(tool):
script += await addPackage(tool, release, 'overtrue/', os_version);
break;
case 'phpmd':
case /^phpmd$/.test(tool):
url = github + 'phpmd/phpmd/' + uri;
script += await addArchive(tool, url, os_version, '"--version"');
break;
case 'phpstan':
case /^phpstan$/.test(tool):
url = github + 'phpstan/phpstan/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'prestissimo':
case /^prestissimo$/.test(tool):
script += await addPackage(tool, release, 'hirak/', os_version);
break;
case 'psalm':
case /^psalm$/.test(tool):
url = github + 'vimeo/psalm/' + uri;
script += await addArchive(tool, url, os_version, '"-v"');
break;
case 'symfony':
case 'symfony-cli':
case /^symfony(-cli)?$/.test(tool):
uri = await getSymfonyUri(version, os_version);
url = github + 'symfony/cli/' + uri;
script += await addArchive('symfony', url, os_version, 'version');
break;
case 'vapor-cli':
case 'vapor':
case /^vapor(-cli)?$/.test(tool):
script += await addPackage(
'vapor-cli',
release,
@ -528,11 +509,18 @@ export async function addTools(
os_version
);
break;
case 'wp':
case 'wp-cli':
case /^wp(-cli)?$/.test(tool):
url = github + (await getWpCliUrl(version));
script += await addArchive('wp-cli', url, os_version, '"--version"');
break;
case /^[\w.-]+\/[\w.-]+$/.test(tool):
script += await addPackage(
tool.split('/')[1],
release.split('/')[1].replace(/\s+/, ''),
tool.split('/')[0] + '/',
os_version
);
break;
default:
script += await utils.addLog(
'$cross',