setup-php/src/install.ts

67 lines
2.1 KiB
TypeScript
Raw Normal View History

import path from 'path';
import fs from 'fs';
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
*
2022-01-29 06:59:58 +07:00
* @param os
2019-10-17 03:11:13 +07:00
*/
export async function getScript(os: string): Promise<string> {
const url = 'https://setup-php.com/sponsor';
const filename = os + (await utils.scriptExtension(os));
const script_path = path.join(__dirname, '../src/scripts', filename);
const run_path = script_path.replace(os, 'run');
2020-11-08 14:36:21 +07:00
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
2020-10-04 18:33:02 +07:00
const extension_csv: string = await utils.getInput('extensions', false);
2020-02-17 04:05:18 +07:00
const ini_values_csv: string = await utils.getInput('ini-values', false);
2019-11-24 03:34:12 +07:00
const coverage_driver: string = await utils.getInput('coverage', false);
2020-12-17 13:43:39 +07:00
const tools_csv: string = await utils.getInput('tools', false);
const version: string = await utils.parseVersion(
await utils.getInput('php-version', true)
);
const ini_file: string = await utils.parseIniFile(
await utils.getInput('ini-file', false)
);
let script = await utils.joins('.', script_path, version, ini_file);
2019-10-17 03:11:13 +07:00
if (extension_csv) {
2022-01-29 06:59:58 +07:00
script += await extensions.addExtension(extension_csv, version, os);
2019-10-17 03:11:13 +07:00
}
2022-01-29 06:59:58 +07:00
script += await tools.addTools(tools_csv, version, os);
2019-10-17 03:11:13 +07:00
if (coverage_driver) {
2022-01-29 06:59:58 +07:00
script += await coverage.addCoverage(coverage_driver, version, os);
2019-10-17 03:11:13 +07:00
}
2020-07-08 09:15:11 +07:00
if (ini_values_csv) {
2022-01-29 06:59:58 +07:00
script += await config.addINIValues(ini_values_csv, os);
2020-07-08 09:15:11 +07:00
}
2022-01-29 06:59:58 +07:00
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os));
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os));
2020-09-07 03:13:15 +07:00
fs.writeFileSync(run_path, script, {mode: 0o755});
return run_path;
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> {
const os: string = process.platform;
const tool = await utils.scriptTool(os);
const run_path = await getScript(os);
await exec(tool + run_path);
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);
});