mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Add support for updating composer
This commit is contained in:
parent
9dec5892e7
commit
739e40fb5e
@ -219,6 +219,41 @@ describe('Tools tests', () => {
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'composer:1.2.3'])
|
||||
).toStrictEqual(['composer', 'a', 'b']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'composer:snapshot'])
|
||||
).toStrictEqual(['composer:snapshot', 'a', 'b']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'composer:preview'])
|
||||
).toStrictEqual(['composer:preview', 'a', 'b']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'c', 'composer:1'])
|
||||
).toStrictEqual(['composer:1', 'a', 'b', 'c']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'c', 'composer:2'])
|
||||
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'c', 'composer:v1'])
|
||||
).toStrictEqual(['composer:1', 'a', 'b', 'c']);
|
||||
expect(
|
||||
await tools.addComposer(['a', 'b', 'c', 'composer:v2'])
|
||||
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('checking updateComposer', async () => {
|
||||
expect(await tools.updateComposer('latest', 'linux')).toContain('');
|
||||
expect(await tools.updateComposer('stable', 'win32')).toContain('');
|
||||
expect(await tools.updateComposer('snapshot', 'darwin')).toContain(
|
||||
'\ncomposer self-update --snapshot'
|
||||
);
|
||||
expect(await tools.updateComposer('preview', 'linux')).toContain(
|
||||
'\ncomposer self-update --preview'
|
||||
);
|
||||
expect(await tools.updateComposer('1', 'win32')).toContain(
|
||||
'\ncomposer self-update --1'
|
||||
);
|
||||
expect(await tools.updateComposer('2', 'darwin')).toContain(
|
||||
'\ncomposer self-update --2'
|
||||
);
|
||||
});
|
||||
|
||||
it('checking getSymfonyUri', async () => {
|
||||
@ -504,4 +539,24 @@ describe('Tools tests', () => {
|
||||
'Add-Composertool composer-prefetcher composer-prefetcher narrowspark/automatic-'
|
||||
);
|
||||
});
|
||||
it('checking composer setup', async () => {
|
||||
let script: string = await tools.addTools(
|
||||
'composer, composer:v1',
|
||||
'7.4',
|
||||
'linux'
|
||||
);
|
||||
expect(script).toContain(
|
||||
'add_tool https://getcomposer.org/composer-stable.phar composer'
|
||||
);
|
||||
expect(script).toContain('composer self-update --1');
|
||||
|
||||
script = await tools.addTools('composer:preview', '7.4', 'linux');
|
||||
expect(script).toContain('composer self-update --preview');
|
||||
script = await tools.addTools(
|
||||
'composer:v1, composer:preview, composer:snapshot',
|
||||
'7.4',
|
||||
'linux'
|
||||
);
|
||||
expect(script).toContain('composer self-update --snapshot');
|
||||
});
|
||||
});
|
||||
|
44
dist/index.js
vendored
44
dist/index.js
vendored
@ -1610,7 +1610,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.addComposer = exports.getWpCliUrl = exports.getSymfonyUri = exports.getDeployerUrl = exports.getPharUrl = exports.addPhive = exports.getCodeceptionUri = exports.getCodeceptionUriBuilder = exports.getUri = exports.parseTool = exports.getToolVersion = exports.getCommand = void 0;
|
||||
exports.addTools = exports.addPackage = exports.addDevTools = exports.addArchive = exports.getCleanedToolsList = exports.updateComposer = exports.addComposer = exports.getWpCliUrl = exports.getSymfonyUri = exports.getDeployerUrl = exports.getPharUrl = exports.addPhive = exports.getCodeceptionUri = exports.getCodeceptionUriBuilder = exports.getUri = exports.parseTool = exports.getToolVersion = exports.getCommand = void 0;
|
||||
const utils = __importStar(__webpack_require__(163));
|
||||
/**
|
||||
* Function to get command to setup tools
|
||||
@ -1638,8 +1638,10 @@ exports.getCommand = getCommand;
|
||||
async function getToolVersion(version) {
|
||||
// semver_regex - https://semver.org/
|
||||
const semver_regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
||||
const composer_regex = /^stable$|^preview$|^snapshot$|^v?[1|2]$/;
|
||||
version = version.replace(/[><=^]*/, '');
|
||||
switch (true) {
|
||||
case composer_regex.test(version):
|
||||
case semver_regex.test(version):
|
||||
return version;
|
||||
default:
|
||||
@ -1864,19 +1866,42 @@ exports.getWpCliUrl = getWpCliUrl;
|
||||
* @param tools_list
|
||||
*/
|
||||
async function addComposer(tools_list) {
|
||||
const regex = /^composer($|:.*)/;
|
||||
const composer = tools_list.filter(tool => regex.test(tool))[0];
|
||||
switch (composer) {
|
||||
const regex_any = /^composer($|:.*)/;
|
||||
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
|
||||
const matches = tools_list.filter(tool => regex_valid.test(tool));
|
||||
let composer = 'composer';
|
||||
tools_list = tools_list.filter(tool => !regex_any.test(tool));
|
||||
switch (matches[0]) {
|
||||
case undefined:
|
||||
break;
|
||||
default:
|
||||
tools_list = tools_list.filter(tool => !regex.test(tool));
|
||||
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
|
||||
break;
|
||||
}
|
||||
tools_list.unshift('composer');
|
||||
tools_list.unshift(composer);
|
||||
return tools_list;
|
||||
}
|
||||
exports.addComposer = addComposer;
|
||||
/**
|
||||
* Function to get script to update composer
|
||||
*
|
||||
* @param version
|
||||
* @param os_version
|
||||
*/
|
||||
async function updateComposer(version, os_version) {
|
||||
switch (version) {
|
||||
case 'snapshot':
|
||||
case 'preview':
|
||||
case '1':
|
||||
case '2':
|
||||
return ('\ncomposer self-update --' +
|
||||
version +
|
||||
(await utils.suppressOutput(os_version)));
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
exports.updateComposer = updateComposer;
|
||||
/**
|
||||
* Function to get Tools list after cleanup
|
||||
*
|
||||
@ -2007,11 +2032,10 @@ async function addTools(tools_csv, php_version, os_version) {
|
||||
script += await addArchive(tool, version, url, os_version);
|
||||
break;
|
||||
case 'composer':
|
||||
// If RC is released as latest release, switch to getcomposer.
|
||||
// Prefered source is GitHub as it is faster.
|
||||
// url = github + 'composer/composer/releases/latest/download/composer.phar';
|
||||
url = 'https://getcomposer.org/composer-stable.phar';
|
||||
script += await addArchive(tool, version, url, os_version);
|
||||
script +=
|
||||
(await addArchive('composer', version, url, os_version)) +
|
||||
(await updateComposer(version, os_version));
|
||||
break;
|
||||
case 'codeception':
|
||||
url =
|
||||
|
47
src/tools.ts
47
src/tools.ts
@ -33,8 +33,10 @@ export async function getCommand(
|
||||
export async function getToolVersion(version: string): Promise<string> {
|
||||
// semver_regex - https://semver.org/
|
||||
const semver_regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
||||
const composer_regex = /^stable$|^preview$|^snapshot$|^v?[1|2]$/;
|
||||
version = version.replace(/[><=^]*/, '');
|
||||
switch (true) {
|
||||
case composer_regex.test(version):
|
||||
case semver_regex.test(version):
|
||||
return version;
|
||||
default:
|
||||
@ -300,19 +302,47 @@ export async function getWpCliUrl(version: string): Promise<string> {
|
||||
* @param tools_list
|
||||
*/
|
||||
export async function addComposer(tools_list: string[]): Promise<string[]> {
|
||||
const regex = /^composer($|:.*)/;
|
||||
const composer: string = tools_list.filter(tool => regex.test(tool))[0];
|
||||
switch (composer) {
|
||||
const regex_any = /^composer($|:.*)/;
|
||||
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
|
||||
const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
|
||||
let composer = 'composer';
|
||||
tools_list = tools_list.filter(tool => !regex_any.test(tool));
|
||||
switch (matches[0]) {
|
||||
case undefined:
|
||||
break;
|
||||
default:
|
||||
tools_list = tools_list.filter(tool => !regex.test(tool));
|
||||
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
|
||||
break;
|
||||
}
|
||||
tools_list.unshift('composer');
|
||||
tools_list.unshift(composer);
|
||||
return tools_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get script to update composer
|
||||
*
|
||||
* @param version
|
||||
* @param os_version
|
||||
*/
|
||||
export async function updateComposer(
|
||||
version: string,
|
||||
os_version: string
|
||||
): Promise<string> {
|
||||
switch (version) {
|
||||
case 'snapshot':
|
||||
case 'preview':
|
||||
case '1':
|
||||
case '2':
|
||||
return (
|
||||
'\ncomposer self-update --' +
|
||||
version +
|
||||
(await utils.suppressOutput(os_version))
|
||||
);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get Tools list after cleanup
|
||||
*
|
||||
@ -483,11 +513,10 @@ export async function addTools(
|
||||
script += await addArchive(tool, version, url, os_version);
|
||||
break;
|
||||
case 'composer':
|
||||
// If RC is released as latest release, switch to getcomposer.
|
||||
// Prefered source is GitHub as it is faster.
|
||||
// url = github + 'composer/composer/releases/latest/download/composer.phar';
|
||||
url = 'https://getcomposer.org/composer-stable.phar';
|
||||
script += await addArchive(tool, version, url, os_version);
|
||||
script +=
|
||||
(await addArchive('composer', version, url, os_version)) +
|
||||
(await updateComposer(version, os_version));
|
||||
break;
|
||||
case 'codeception':
|
||||
url =
|
||||
|
Loading…
Reference in New Issue
Block a user