mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-09-01 02:14:16 +07:00
Refactor to dry unix scripts
This commit is contained in:
47
dist/index.js
vendored
47
dist/index.js
vendored
@ -2570,6 +2570,7 @@ async function getScript(filename, version, os_version) {
|
||||
const name = 'setup-php';
|
||||
const url = 'https://setup-php.com/support';
|
||||
// taking inputs
|
||||
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
||||
const extension_csv = await utils.getInput('extensions', false);
|
||||
const ini_values_csv = await utils.getInput('ini-values', false);
|
||||
const coverage_driver = await utils.getInput('coverage', false);
|
||||
@ -2603,8 +2604,7 @@ async function run() {
|
||||
const tool = await utils.scriptTool(os_version);
|
||||
const script = os_version + (await utils.scriptExtension(os_version));
|
||||
const location = await getScript(script, version, os_version);
|
||||
const fail_fast = await utils.readEnv('fail-fast');
|
||||
await exec_1.exec(await utils.joins(tool, location, version, __dirname, fail_fast));
|
||||
await exec_1.exec(await utils.joins(tool, location, version, __dirname));
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
@ -2865,9 +2865,8 @@ const utils = __importStar(__webpack_require__(163));
|
||||
*
|
||||
* @param extension_csv
|
||||
* @param version
|
||||
* @param pipe
|
||||
*/
|
||||
async function addExtensionDarwin(extension_csv, version, pipe) {
|
||||
async function addExtensionDarwin(extension_csv, version) {
|
||||
const extensions = await utils.extensionArray(extension_csv);
|
||||
let add_script = '\n';
|
||||
let remove_script = '';
|
||||
@ -2875,8 +2874,6 @@ async function addExtensionDarwin(extension_csv, version, pipe) {
|
||||
const version_extension = version + extension;
|
||||
const [ext_name, ext_version] = extension.split('-');
|
||||
const ext_prefix = await utils.getExtensionPrefix(ext_name);
|
||||
const command_prefix = 'pecl_install ';
|
||||
let command = '';
|
||||
switch (true) {
|
||||
// match :extension
|
||||
case /^:/.test(ext_name):
|
||||
@ -2911,26 +2908,20 @@ async function addExtensionDarwin(extension_csv, version, pipe) {
|
||||
case /(5\.6|7\.[0-4]|8\.[0-9])(xdebug|igbinary)/.test(version_extension):
|
||||
case /(5\.6|7\.[0-4])(grpc|imagick|protobuf|swoole)/.test(version_extension):
|
||||
case /(7\.[1-4]|8\.[0-9])pcov/.test(version_extension):
|
||||
command = 'add_brew_extension ' + ext_name;
|
||||
break;
|
||||
add_script += await utils.joins('\nadd_brew_extension', ext_name, ext_prefix);
|
||||
return;
|
||||
// match 5.6redis
|
||||
case /5\.6redis/.test(version_extension):
|
||||
command = command_prefix + 'redis-2.2.8';
|
||||
break;
|
||||
// match 5.4imagick and 5.5imagick
|
||||
case /^5\.[4-5]imagick$/.test(version_extension):
|
||||
command = await utils.joins('brew install pkg-config imagemagick' + pipe, '&& ' + command_prefix + 'imagick' + pipe);
|
||||
extension = 'redis-2.2.8';
|
||||
break;
|
||||
// match sqlite
|
||||
case /^sqlite$/.test(extension):
|
||||
extension = 'sqlite3';
|
||||
command = command_prefix + extension;
|
||||
break;
|
||||
default:
|
||||
command = command_prefix + extension;
|
||||
break;
|
||||
}
|
||||
add_script += await utils.joins('\nadd_extension', extension, '"' + command + '"', ext_prefix);
|
||||
add_script += await utils.joins('\nadd_extension', extension, ext_prefix);
|
||||
});
|
||||
return add_script + remove_script;
|
||||
}
|
||||
@ -3013,9 +3004,8 @@ exports.addExtensionWindows = addExtensionWindows;
|
||||
*
|
||||
* @param extension_csv
|
||||
* @param version
|
||||
* @param pipe
|
||||
*/
|
||||
async function addExtensionLinux(extension_csv, version, pipe) {
|
||||
async function addExtensionLinux(extension_csv, version) {
|
||||
const extensions = await utils.extensionArray(extension_csv);
|
||||
let add_script = '\n';
|
||||
let remove_script = '';
|
||||
@ -3023,8 +3013,6 @@ async function addExtensionLinux(extension_csv, version, pipe) {
|
||||
const version_extension = version + extension;
|
||||
const [ext_name, ext_version] = extension.split('-');
|
||||
const ext_prefix = await utils.getExtensionPrefix(ext_name);
|
||||
const command_prefix = 'sudo $debconf_fix apt-get install -y php';
|
||||
let command = '';
|
||||
switch (true) {
|
||||
// Match :extension
|
||||
case /^:/.test(ext_name):
|
||||
@ -3066,27 +3054,20 @@ async function addExtensionLinux(extension_csv, version, pipe) {
|
||||
// match 8.0xdebug3...8.9xdebug3
|
||||
case /^8\.[0-9]xdebug3$/.test(version_extension):
|
||||
extension = 'xdebug';
|
||||
command = command_prefix + version + '-' + extension + pipe;
|
||||
break;
|
||||
// match pdo extensions
|
||||
case /.*pdo[_-].*/.test(version_extension):
|
||||
extension = extension.replace(/pdo[_-]|3/, '');
|
||||
add_script += '\nadd_pdo_extension ' + extension;
|
||||
return;
|
||||
// match uopz
|
||||
case /^(uopz)$/.test(extension):
|
||||
command = command_prefix + '-' + extension + pipe;
|
||||
break;
|
||||
// match sqlite
|
||||
case /^sqlite$/.test(extension):
|
||||
extension = 'sqlite3';
|
||||
command = command_prefix + version + '-' + extension + pipe;
|
||||
break;
|
||||
default:
|
||||
command = command_prefix + version + '-' + extension + pipe;
|
||||
break;
|
||||
}
|
||||
add_script += await utils.joins('\nadd_extension', extension, '"' + command + '"', ext_prefix);
|
||||
add_script += await utils.joins('\nadd_extension', extension, ext_prefix);
|
||||
});
|
||||
return add_script + remove_script;
|
||||
}
|
||||
@ -3100,24 +3081,24 @@ exports.addExtensionLinux = addExtensionLinux;
|
||||
* @param no_step
|
||||
*/
|
||||
async function addExtension(extension_csv, version, os_version, no_step = false) {
|
||||
const pipe = await utils.suppressOutput(os_version);
|
||||
const log = await utils.stepLog('Setup Extensions', os_version);
|
||||
let script = '\n';
|
||||
switch (no_step) {
|
||||
case true:
|
||||
script += (await utils.stepLog('Setup Extensions', os_version)) + pipe;
|
||||
script += log + (await utils.suppressOutput(os_version));
|
||||
break;
|
||||
case false:
|
||||
default:
|
||||
script += await utils.stepLog('Setup Extensions', os_version);
|
||||
script += log;
|
||||
break;
|
||||
}
|
||||
switch (os_version) {
|
||||
case 'win32':
|
||||
return script + (await addExtensionWindows(extension_csv, version));
|
||||
case 'darwin':
|
||||
return script + (await addExtensionDarwin(extension_csv, version, pipe));
|
||||
return script + (await addExtensionDarwin(extension_csv, version));
|
||||
case 'linux':
|
||||
return script + (await addExtensionLinux(extension_csv, version, pipe));
|
||||
return script + (await addExtensionLinux(extension_csv, version));
|
||||
default:
|
||||
return await utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
}
|
||||
|
Reference in New Issue
Block a user