2021-03-03 11:58:50 +07:00
|
|
|
import {exec} from '@actions/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';
|
2019-12-27 08:26:49 +07:00
|
|
|
import * as tools from './tools';
|
2019-10-27 07:12:49 +07:00
|
|
|
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
|
|
|
|
*/
|
2019-10-30 10:46:37 +07:00
|
|
|
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
|
2020-08-16 08:08:52 +07:00
|
|
|
const name = 'setup-php';
|
2020-10-05 14:29:36 +07:00
|
|
|
const url = 'https://setup-php.com/support';
|
2019-12-09 12:22:43 +07:00
|
|
|
const extension_csv: string =
|
|
|
|
(await utils.getInput('extensions', false)) ||
|
2020-01-26 19:35:27 +07:00
|
|
|
(await utils.getInput('extension', false)) ||
|
2019-12-09 12:22:43 +07:00
|
|
|
(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);
|
2021-02-22 12:13:59 +07:00
|
|
|
const tools_csv: string = await utils.getInput('tools', false);
|
2019-10-17 03:11:13 +07:00
|
|
|
|
2020-03-14 09:23:43 +07:00
|
|
|
let script: string = await utils.readScript(filename);
|
2020-01-07 09:36:14 +07:00
|
|
|
script += await tools.addTools(tools_csv, version, os_version);
|
2020-01-01 17:35:01 +07:00
|
|
|
|
2019-10-17 03:11:13 +07:00
|
|
|
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 09:15:11 +07:00
|
|
|
if (ini_values_csv) {
|
|
|
|
script += await config.addINIValues(ini_values_csv, os_version);
|
|
|
|
}
|
2019-10-27 07:12:49 +07:00
|
|
|
|
2020-08-16 08:08:52 +07:00
|
|
|
script += '\n' + (await utils.stepLog('Support this project', os_version));
|
|
|
|
script += '\n' + (await utils.addLog('$tick', name, url, 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 {
|
2020-10-19 16:12:37 +07:00
|
|
|
core.warning(
|
2021-05-04 23:41:06 +07:00
|
|
|
'setup-php v1 is deprecated.\nPlease upgrade to v2 - https://setup-php.com/w/Switch-to-v2'
|
2020-10-19 16:12:37 +07:00
|
|
|
);
|
2021-02-22 12:52:59 +07:00
|
|
|
const version: string = await utils.parseVersion(
|
|
|
|
await utils.getInput('php-version', true)
|
|
|
|
);
|
2020-10-19 16:12:37 +07:00
|
|
|
if (version == '8.1') {
|
|
|
|
core.setFailed(
|
2021-05-04 23:41:06 +07:00
|
|
|
'PHP 8.1 is not supported on setup-php v1.\nPlease upgrade to v2 - https://setup-php.com/w/Switch-to-v2'
|
2020-10-19 16:12:37 +07:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2021-02-22 12:52:59 +07:00
|
|
|
if (version) {
|
|
|
|
const os_version: string = process.platform;
|
|
|
|
// check the os version and run the respective script
|
|
|
|
let script_path = '';
|
|
|
|
switch (os_version) {
|
|
|
|
case 'darwin':
|
|
|
|
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);
|
|
|
|
await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
core.setFailed('Unable to get the PHP version');
|
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
|
2021-03-03 11:58:50 +07:00
|
|
|
(async () => {
|
|
|
|
await run();
|
|
|
|
})().catch(error => {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
});
|