setup-php/src/install.ts

76 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-09-06 06:47:43 +07:00
import {exec} from '@actions/exec/lib/exec';
2019-09-20 09:41:20 +07:00
import * as core from '@actions/core';
2019-10-08 19:42:54 +07:00
import * as config from './config';
import * as coverage from './coverage';
2019-10-27 07:12:49 +07:00
import * as extensions from './extensions';
import * as utils from './utils';
2019-09-06 06:47:43 +07:00
2019-10-17 03:11:13 +07:00
/**
* Build the script
*
* @param filename
* @param version
* @param os_version
*/
export async function build(
2019-10-27 07:12:49 +07:00
filename: string,
version: string,
os_version: string
): Promise<string> {
2019-10-17 03:11:13 +07:00
// taking inputs
const extension_csv: string =
(await utils.getInput('extensions', false)) ||
(await utils.getInput('extension-csv', false));
const ini_values_csv: string =
(await utils.getInput('ini-values', false)) ||
(await utils.getInput('ini-values-csv', false));
2019-11-24 03:34:12 +07:00
const coverage_driver: string = await utils.getInput('coverage', false);
2019-10-17 03:11:13 +07:00
let script: string = await utils.readScript(filename, version, os_version);
if (extension_csv) {
script += await extensions.addExtension(extension_csv, version, os_version);
}
if (ini_values_csv) {
script += await config.addINIValues(ini_values_csv, os_version);
}
if (coverage_driver) {
script += await coverage.addCoverage(coverage_driver, version, os_version);
}
2019-10-27 07:12:49 +07:00
return await utils.writeScript(filename, script);
2019-10-17 03:11:13 +07:00
}
2019-09-20 09:41:20 +07:00
/**
* Run the script
*/
2019-11-24 03:34:12 +07:00
export async function run(): Promise<void> {
2019-09-06 06:47:43 +07:00
try {
2019-11-24 03:34:12 +07:00
const os_version: string = process.platform;
2019-12-14 11:43:01 +07:00
let version: string = await utils.getInput('php-version', true);
version = version.length > 1 ? version : version + '.0';
2019-09-09 03:05:38 +07:00
// check the os version and run the respective script
2019-11-24 03:34:12 +07:00
let script_path = '';
switch (os_version) {
case 'darwin':
script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + __dirname);
break;
2019-11-24 03:34:12 +07:00
case 'linux': {
const pecl: string = await utils.getInput('pecl', false);
2019-11-07 12:41:35 +07:00
script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + pecl);
break;
2019-11-24 03:34:12 +07:00
}
case 'win32':
script_path = await build('win32.ps1', version, os_version);
2019-12-09 09:39:03 +07:00
await exec('pwsh ' + script_path + ' -version ' + version);
break;
2019-09-06 06:47:43 +07:00
}
2019-10-17 03:11:13 +07:00
} catch (error) {
core.setFailed(error.message);
2019-09-06 06:47:43 +07:00
}
}
2019-09-07 19:31:50 +07:00
// call the run function
2019-10-11 06:11:25 +07:00
run();