Files
setup-php/src/install.ts

90 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-09-06 05:17:43 +05:30
import {exec} from '@actions/exec/lib/exec';
2019-09-20 08:11:20 +05:30
import * as core from '@actions/core';
2019-10-08 18:12:54 +05:30
import * as config from './config';
import * as coverage from './coverage';
2019-10-27 05:42:49 +05:30
import * as extensions from './extensions';
2019-12-27 06:56:49 +05:30
import * as tools from './tools';
2019-10-27 05:42:49 +05:30
import * as utils from './utils';
2019-12-19 02:38:12 +05:30
import * as matchers from './matchers';
2019-09-06 05:17:43 +05:30
2019-10-17 01:41:13 +05:30
/**
* Build the script
*
* @param filename
* @param version
* @param os_version
*/
export async function build(
2019-10-27 05:42:49 +05:30
filename: string,
version: string,
os_version: string
): Promise<string> {
2020-09-07 01:43:15 +05:30
const name = 'setup-php';
const url = 'setup-php.com/support';
2019-10-17 01:41:13 +05:30
// taking inputs
const extension_csv: string =
(await utils.getInput('extensions', false)) ||
2020-02-17 02:35:18 +05:30
(await utils.getInput('extension', false));
const ini_values_csv: string = await utils.getInput('ini-values', false);
2019-11-24 02:04:12 +05:30
const coverage_driver: string = await utils.getInput('coverage', false);
2019-12-27 06:56:49 +05:30
const pecl: string = await utils.getInput('pecl', false);
let tools_csv: string = await utils.getInput('tools', false);
if (
pecl == 'true' ||
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv) ||
/.*-(\d+\.\d+\.\d+).*/.test(extension_csv)
) {
2019-12-27 06:56:49 +05:30
tools_csv = 'pecl, ' + tools_csv;
}
2019-10-17 01:41:13 +05:30
2020-03-12 07:57:40 +05:30
let script: string = await utils.readScript(filename);
script += await tools.addTools(tools_csv, version, os_version);
2020-01-01 16:05:01 +05:30
2019-10-17 01:41:13 +05:30
if (extension_csv) {
script += await extensions.addExtension(extension_csv, version, os_version);
}
if (coverage_driver) {
script += await coverage.addCoverage(coverage_driver, version, os_version);
}
2020-07-08 07:45:11 +05:30
if (ini_values_csv) {
script += await config.addINIValues(ini_values_csv, os_version);
}
2019-10-27 05:42:49 +05:30
2020-09-07 01:43:15 +05:30
script += '\n' + (await utils.stepLog('Support this project', os_version));
script += '\n' + (await utils.addLog('$tick', name, url, os_version));
2019-10-27 05:42:49 +05:30
return await utils.writeScript(filename, script);
2019-10-17 01:41:13 +05:30
}
2019-09-20 08:11:20 +05:30
/**
* Run the script
*/
2019-11-24 02:04:12 +05:30
export async function run(): Promise<void> {
2019-09-06 05:17:43 +05:30
try {
2020-10-02 14:51:40 +05:30
const version: string = await utils.parseVersion(
await utils.getInput('php-version', true)
);
const os_version: string = process.platform;
2019-09-09 01:35:38 +05:30
// check the os version and run the respective script
2019-11-24 02:04:12 +05:30
let script_path = '';
switch (os_version) {
case 'darwin':
2019-12-27 06:56:49 +05:30
case 'linux':
script_path = await build(os_version + '.sh', version, os_version);
await exec('bash ' + script_path + ' ' + version + ' ' + __dirname);
break;
case 'win32':
script_path = await build('win32.ps1', version, os_version);
2019-12-26 18:31:18 +05:30
await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname);
break;
2019-09-06 05:17:43 +05:30
}
2019-12-19 02:38:12 +05:30
await matchers.addMatchers();
2019-10-17 01:41:13 +05:30
} catch (error) {
core.setFailed(error.message);
2019-09-06 05:17:43 +05:30
}
}
2019-09-07 18:01:50 +05:30
// call the run function
2019-10-11 04:41:25 +05:30
run();