Improve workflow and lint the code

This commit is contained in:
Shivam Mathur 2019-11-24 02:04:12 +05:30
parent 2b938d931a
commit 3f6c88dec7
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
18 changed files with 1531 additions and 474 deletions

22
.eslintrc.json Normal file
View File

@ -0,0 +1,22 @@
{
"env": { "node": true, "jest": true },
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 2020, "sourceType": "module" },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint", "jest"],
"rules": {
"camelcase": "off",
"require-atomic-updates": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/camelcase": "off"
}
}

View File

@ -1,5 +1,19 @@
name: Main workflow name: Main workflow
on: [push, pull_request] on:
pull_request:
branches:
- master
- develop
- verbose
paths-ignore:
- '**.md'
push:
branches:
- master
- develop
- verbose
paths-ignore:
- '**.md'
jobs: jobs:
run: run:
name: Run name: Run
@ -20,11 +34,14 @@ jobs:
with: with:
node-version: 12.x node-version: 12.x
- name: Cache node modules - name: Get npm cache directory
uses: actions/cache@preview id: npm-cache
id: cache run: echo "::set-output name=dir::$(npm config get cache)"
- name: Install dependencies
uses: actions/cache@v1
with: with:
path: node_modules path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-node- ${{ runner.os }}-node-
@ -33,12 +50,18 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
run: npm install run: npm install
- name: Prettier Format Check
run: npm run format-check
- name: ESLint Check
run: npm run lint
- name: Run tests - name: Run tests
run: npm test run: npm test
- name: Send Coverage - name: Send Coverage
continue-on-error: true continue-on-error: true
timeout-minutes: 2 timeout-minutes: 1
run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }} run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }}
- name: Setup PHP with extensions and custom config - name: Setup PHP with extensions and custom config

View File

@ -1,6 +1,4 @@
import * as config from '../src/config';
import * as coverage from '../src/coverage'; import * as coverage from '../src/coverage';
import * as extensions from '../src/coverage';
jest.mock('../src/extensions', () => ({ jest.mock('../src/extensions', () => ({
addExtension: jest.fn().mockImplementation(extension => { addExtension: jest.fn().mockImplementation(extension => {
@ -24,40 +22,44 @@ describe('Config tests', () => {
}); });
it('checking addCoverage with PCOV on linux', async () => { it('checking addCoverage with PCOV on linux', async () => {
let linux: string = await coverage.addCoverage('pcov', '7.4', 'linux'); const linux: string = await coverage.addCoverage('pcov', '7.4', 'linux');
expect(linux).toContain('addExtension pcov'); expect(linux).toContain('addExtension pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file'); expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
expect(linux).toContain('sudo phpdismod -v 7.4 xdebug'); expect(linux).toContain('sudo phpdismod -v 7.4 xdebug');
}); });
it('checking addCoverage with PCOV on darwin', async () => { it('checking addCoverage with PCOV on darwin', async () => {
let darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin'); const darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin');
expect(darwin).toContain('addExtension pcov'); expect(darwin).toContain('addExtension pcov');
}); });
it('checking addCoverage with Xdebug on windows', async () => { it('checking addCoverage with Xdebug on windows', async () => {
let win32: string = await coverage.addCoverage('xdebug', '7.3', 'win32'); const win32: string = await coverage.addCoverage('xdebug', '7.3', 'win32');
expect(win32).toContain('addExtension xdebug'); expect(win32).toContain('addExtension xdebug');
}); });
it('checking addCoverage with Xdebug on linux', async () => { it('checking addCoverage with Xdebug on linux', async () => {
let linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux'); const linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux');
expect(linux).toContain('addExtension xdebug'); expect(linux).toContain('addExtension xdebug');
}); });
it('checking addCoverage with Xdebug on darwin', async () => { it('checking addCoverage with Xdebug on darwin', async () => {
let darwin: string = await coverage.addCoverage('xdebug', '7.4', 'darwin'); const darwin: string = await coverage.addCoverage(
'xdebug',
'7.4',
'darwin'
);
expect(darwin).toContain('addExtension xdebug'); expect(darwin).toContain('addExtension xdebug');
}); });
it('checking disableCoverage windows', async () => { it('checking disableCoverage windows', async () => {
let win32 = await coverage.addCoverage('none', '7.4', 'win32'); const win32 = await coverage.addCoverage('none', '7.4', 'win32');
expect(win32).toContain('Disable-PhpExtension xdebug'); expect(win32).toContain('Disable-PhpExtension xdebug');
expect(win32).toContain('Disable-PhpExtension pcov'); expect(win32).toContain('Disable-PhpExtension pcov');
}); });
it('checking disableCoverage on linux', async () => { it('checking disableCoverage on linux', async () => {
let linux: string = await coverage.addCoverage('none', '7.4', 'linux'); const linux: string = await coverage.addCoverage('none', '7.4', 'linux');
expect(linux).toContain('sudo phpdismod -v 7.4 xdebug'); expect(linux).toContain('sudo phpdismod -v 7.4 xdebug');
expect(linux).toContain('sudo phpdismod -v 7.4 pcov'); expect(linux).toContain('sudo phpdismod -v 7.4 pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file'); expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
@ -65,7 +67,7 @@ describe('Config tests', () => {
}); });
it('checking disableCoverage on darwin', async () => { it('checking disableCoverage on darwin', async () => {
let darwin: string = await coverage.addCoverage('none', '7.4', 'darwin'); const darwin: string = await coverage.addCoverage('none', '7.4', 'darwin');
expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" $ini_file'); expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" $ini_file');
expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" $ini_file'); expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" $ini_file');
}); });

View File

@ -10,7 +10,7 @@ describe('Extension tests', () => {
expect(win32).toContain('Install-PhpExtension xdebug'); expect(win32).toContain('Install-PhpExtension xdebug');
expect(win32).toContain('Install-PhpExtension pcov'); expect(win32).toContain('Install-PhpExtension pcov');
win32 = await extensions.addExtension('xdebug, pcov', '7.4', 'win32'); win32 = await extensions.addExtension('xdebug, pcov', '7.4', 'win32');
const extension_url: string = const extension_url =
'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll'; 'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
expect(win32).toContain( expect(win32).toContain(
'Invoke-WebRequest -Uri ' + 'Invoke-WebRequest -Uri ' +

View File

@ -10,11 +10,11 @@ jest.mock('../src/install', () => ({
version: string, version: string,
os_version: string os_version: string
): Promise<string> => { ): Promise<string> => {
let extension_csv: string = process.env['extension-csv'] || ''; const extension_csv: string = process.env['extension-csv'] || '';
let ini_values_csv: string = process.env['ini-values-csv'] || ''; const ini_values_csv: string = process.env['ini-values-csv'] || '';
let coverage_driver: string = process.env['coverage'] || ''; const coverage_driver: string = process.env['coverage'] || '';
let script: string = 'initial script'; let script = 'initial script ' + filename + version + os_version;
if (extension_csv) { if (extension_csv) {
script += 'install extensions'; script += 'install extensions';
} }
@ -30,19 +30,20 @@ jest.mock('../src/install', () => ({
), ),
run: jest.fn().mockImplementation( run: jest.fn().mockImplementation(
async (): Promise<string> => { async (): Promise<string> => {
let os_version: string = process.env['RUNNER_OS'] || ''; const os_version: string = process.env['RUNNER_OS'] || '';
let version: string = process.env['php-version'] || ''; const version: string = process.env['php-version'] || '';
let script: string = ''; let script = '';
switch (os_version) { switch (os_version) {
case 'darwin': case 'darwin':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
script += 'sh script.sh ' + version + ' ' + __dirname; script += 'sh script.sh ' + version + ' ' + __dirname;
break; break;
case 'linux': case 'linux': {
let pecl: string = process.env['pecl'] || ''; const pecl: string = process.env['pecl'] || '';
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
script += 'sh script.sh ' + version + ' ' + pecl + ' ' + __dirname; script += 'sh script.sh ' + version + ' ' + pecl + ' ' + __dirname;
break; break;
}
case 'win32': case 'win32':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
script += script +=
@ -72,7 +73,7 @@ function setEnv(
extension_csv: string, extension_csv: string,
ini_values_csv: string, ini_values_csv: string,
coverage_driver: string, coverage_driver: string,
pecl: any pecl: string
): void { ): void {
process.env['php-version'] = version; process.env['php-version'] = version;
process.env['RUNNER_OS'] = os; process.env['RUNNER_OS'] = os;
@ -116,7 +117,7 @@ describe('Install', () => {
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3 true'); expect(script).toContain('sh script.sh 7.3 true');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', true); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true');
// @ts-ignore // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');

View File

@ -27,28 +27,35 @@ describe('Utils tests', () => {
}); });
it('checking asyncForEach', async () => { it('checking asyncForEach', async () => {
let array: Array<number> = [1, 2, 3, 4]; const array: Array<string> = ['a', 'b', 'c'];
let sum: number = 0; let concat = '';
await utils.asyncForEach(array, function(num: number): void { await utils.asyncForEach(array, async function(str: string): Promise<void> {
sum += num; concat += str;
}); });
expect(sum).toBe(10); expect(concat).toBe('abc');
});
it('checking asyncForEach', async () => {
expect(await utils.color('error')).toBe('31');
expect(await utils.color('success')).toBe('32');
expect(await utils.color('any')).toBe('32');
expect(await utils.color('warning')).toBe('33');
}); });
it('checking readScripts', async () => { it('checking readScripts', async () => {
let rc: string = fs.readFileSync( const rc: string = fs.readFileSync(
path.join(__dirname, '../src/scripts/7.4.sh'), path.join(__dirname, '../src/scripts/7.4.sh'),
'utf8' 'utf8'
); );
let darwin: string = fs.readFileSync( const darwin: string = fs.readFileSync(
path.join(__dirname, '../src/scripts/darwin.sh'), path.join(__dirname, '../src/scripts/darwin.sh'),
'utf8' 'utf8'
); );
let linux: string = fs.readFileSync( const linux: string = fs.readFileSync(
path.join(__dirname, '../src/scripts/linux.sh'), path.join(__dirname, '../src/scripts/linux.sh'),
'utf8' 'utf8'
); );
let win32: string = fs.readFileSync( const win32: string = fs.readFileSync(
path.join(__dirname, '../src/scripts/win32.ps1'), path.join(__dirname, '../src/scripts/win32.ps1'),
'utf8' 'utf8'
); );
@ -64,11 +71,11 @@ describe('Utils tests', () => {
}); });
it('checking writeScripts', async () => { it('checking writeScripts', async () => {
let testString: string = 'sudo apt-get install php'; const testString = 'sudo apt-get install php';
let runner_dir: string = process.env['RUNNER_TOOL_CACHE'] || ''; const runner_dir: string = process.env['RUNNER_TOOL_CACHE'] || '';
let script_path: string = path.join(runner_dir, 'test.sh'); const script_path: string = path.join(runner_dir, 'test.sh');
await utils.writeScript('test.sh', testString); await utils.writeScript('test.sh', testString);
await fs.readFile(script_path, function(error: any, data: Buffer) { await fs.readFile(script_path, function(error: Error | null, data: Buffer) {
expect(testString).toBe(data.toString()); expect(testString).toBe(data.toString());
}); });
await cleanup(script_path); await cleanup(script_path);
@ -97,7 +104,7 @@ describe('Utils tests', () => {
}); });
it('checking log', async () => { it('checking log', async () => {
let message: string = 'Test message'; const message = 'Test message';
let warning_log: string = await utils.log(message, 'win32', 'warning'); let warning_log: string = await utils.log(message, 'win32', 'warning');
expect(warning_log).toEqual('printf "\\033[33;1m' + message + ' \\033[0m"'); expect(warning_log).toEqual('printf "\\033[33;1m' + message + ' \\033[0m"');

View File

@ -17,6 +17,47 @@ var __importStar = (this && this.__importStar) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const utils = __importStar(require("./utils")); const utils = __importStar(require("./utils"));
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
function addINIValuesUnix(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
const ini_values = yield utils.INIArray(ini_values_csv);
let script = '\n';
yield utils.asyncForEach(ini_values, function (line) {
return __awaiter(this, void 0, void 0, function* () {
script +=
(yield utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n';
});
});
return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script;
});
}
exports.addINIValuesUnix = addINIValuesUnix;
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
function addINIValuesWindows(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
const ini_values = yield utils.INIArray(ini_values_csv);
let script = '\n';
yield utils.asyncForEach(ini_values, function (line) {
return __awaiter(this, void 0, void 0, function* () {
script +=
(yield utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
});
});
return ('Add-Content C:\\tools\\php\\php.ini "' +
ini_values.join('\n') +
'"' +
script);
});
}
exports.addINIValuesWindows = addINIValuesWindows;
/** /**
* Function to add custom ini values * Function to add custom ini values
* *
@ -50,44 +91,3 @@ function addINIValues(ini_values_csv, os_version, no_step = false) {
}); });
} }
exports.addINIValues = addINIValues; exports.addINIValues = addINIValues;
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
function addINIValuesUnix(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let ini_values = yield utils.INIArray(ini_values_csv);
let script = '\n';
yield utils.asyncForEach(ini_values, function (line) {
return __awaiter(this, void 0, void 0, function* () {
script +=
(yield utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n';
});
});
return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script;
});
}
exports.addINIValuesUnix = addINIValuesUnix;
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
function addINIValuesWindows(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let ini_values = yield utils.INIArray(ini_values_csv);
let script = '\n';
yield utils.asyncForEach(ini_values, function (line) {
return __awaiter(this, void 0, void 0, function* () {
script +=
(yield utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
});
});
return ('Add-Content C:\\tools\\php\\php.ini "' +
ini_values.join('\n') +
'"' +
script);
});
}
exports.addINIValuesWindows = addINIValuesWindows;

View File

@ -19,30 +19,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
const utils = __importStar(require("./utils")); const utils = __importStar(require("./utils"));
const extensions = __importStar(require("./extensions")); const extensions = __importStar(require("./extensions"));
const config = __importStar(require("./config")); const config = __importStar(require("./config"));
/**
* Function to set coverage driver
*
* @param coverage_driver
* @param version
* @param os_version
*/
function addCoverage(coverage_driver, version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
coverage_driver.toLowerCase();
let script = '\n' + (yield utils.stepLog('Setup Coverage', os_version));
switch (coverage_driver) {
case 'pcov':
return script + (yield addCoveragePCOV(version, os_version));
case 'xdebug':
return script + (yield addCoverageXdebug(version, os_version));
case 'none':
return script + (yield disableCoverage(version, os_version));
default:
return '';
}
});
}
exports.addCoverage = addCoverage;
/** /**
* Function to setup Xdebug * Function to setup Xdebug
* *
@ -149,3 +125,27 @@ function disableCoverage(version, os_version) {
}); });
} }
exports.disableCoverage = disableCoverage; exports.disableCoverage = disableCoverage;
/**
* Function to set coverage driver
*
* @param coverage_driver
* @param version
* @param os_version
*/
function addCoverage(coverage_driver, version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
coverage_driver.toLowerCase();
const script = '\n' + (yield utils.stepLog('Setup Coverage', os_version));
switch (coverage_driver) {
case 'pcov':
return script + (yield addCoveragePCOV(version, os_version));
case 'xdebug':
return script + (yield addCoverageXdebug(version, os_version));
case 'none':
return script + (yield disableCoverage(version, os_version));
default:
return '';
}
});
}
exports.addCoverage = addCoverage;

View File

@ -18,41 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path")); const path = __importStar(require("path"));
const utils = __importStar(require("./utils")); const utils = __importStar(require("./utils"));
/**
* Install and enable extensions
*
* @param extension_csv
* @param version
* @param os_version
* @param log_prefix
*/
function addExtension(extension_csv, version, os_version, no_step = false) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
switch (no_step) {
case true:
script +=
(yield utils.stepLog('Setup Extensions', os_version)) +
(yield utils.suppressOutput(os_version));
break;
case false:
default:
script += yield utils.stepLog('Setup Extensions', os_version);
break;
}
switch (os_version) {
case 'win32':
return script + (yield addExtensionWindows(extension_csv, version));
case 'darwin':
return script + (yield addExtensionDarwin(extension_csv, version));
case 'linux':
return script + (yield addExtensionLinux(extension_csv, version));
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
exports.addExtension = addExtension;
/** /**
* Install and enable extensions for darwin * Install and enable extensions for darwin
* *
@ -61,7 +26,7 @@ exports.addExtension = addExtension;
*/ */
function addExtensionDarwin(extension_csv, version) { function addExtensionDarwin(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let extensions = yield utils.extensionArray(extension_csv); const extensions = yield utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -97,7 +62,7 @@ exports.addExtensionDarwin = addExtensionDarwin;
*/ */
function addExtensionWindows(extension_csv, version) { function addExtensionWindows(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let extensions = yield utils.extensionArray(extension_csv); const extensions = yield utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -105,7 +70,7 @@ function addExtensionWindows(extension_csv, version) {
// add script to enable extension is already installed along with php // add script to enable extension is already installed along with php
let install_command = ''; let install_command = '';
switch (version + extension) { switch (version + extension) {
case '7.4xdebug': case '7.4xdebug': {
const extension_url = 'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll'; const extension_url = 'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
install_command = install_command =
'Invoke-WebRequest -Uri ' + 'Invoke-WebRequest -Uri ' +
@ -113,6 +78,7 @@ function addExtensionWindows(extension_csv, version) {
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n'; ' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
install_command += 'Enable-PhpExtension xdebug'; install_command += 'Enable-PhpExtension xdebug';
break; break;
}
case '7.2xdebug': case '7.2xdebug':
default: default:
install_command = 'Install-PhpExtension ' + extension; install_command = 'Install-PhpExtension ' + extension;
@ -139,7 +105,7 @@ exports.addExtensionWindows = addExtensionWindows;
*/ */
function addExtensionLinux(extension_csv, version) { function addExtensionLinux(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let extensions = yield utils.extensionArray(extension_csv); const extensions = yield utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -190,3 +156,38 @@ function addExtensionLinux(extension_csv, version) {
}); });
} }
exports.addExtensionLinux = addExtensionLinux; exports.addExtensionLinux = addExtensionLinux;
/**
* Install and enable extensions
*
* @param extension_csv
* @param version
* @param os_version
* @param log_prefix
*/
function addExtension(extension_csv, version, os_version, no_step = false) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
switch (no_step) {
case true:
script +=
(yield utils.stepLog('Setup Extensions', os_version)) +
(yield utils.suppressOutput(os_version));
break;
case false:
default:
script += yield utils.stepLog('Setup Extensions', os_version);
break;
}
switch (os_version) {
case 'win32':
return script + (yield addExtensionWindows(extension_csv, version));
case 'darwin':
return script + (yield addExtensionDarwin(extension_csv, version));
case 'linux':
return script + (yield addExtensionLinux(extension_csv, version));
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
exports.addExtension = addExtension;

View File

@ -32,9 +32,9 @@ const utils = __importStar(require("./utils"));
function build(filename, version, os_version) { function build(filename, version, os_version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// taking inputs // taking inputs
let extension_csv = yield utils.getInput('extension-csv', false); const extension_csv = yield utils.getInput('extension-csv', false);
let ini_values_csv = yield utils.getInput('ini-values-csv', false); const ini_values_csv = yield utils.getInput('ini-values-csv', false);
let coverage_driver = yield utils.getInput('coverage', false); const coverage_driver = yield utils.getInput('coverage', false);
let script = yield utils.readScript(filename, version, os_version); let script = yield utils.readScript(filename, version, os_version);
if (extension_csv) { if (extension_csv) {
script += yield extensions.addExtension(extension_csv, version, os_version); script += yield extensions.addExtension(extension_csv, version, os_version);
@ -55,8 +55,8 @@ exports.build = build;
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
let os_version = process.platform; const os_version = process.platform;
let version = yield utils.getInput('php-version', true); const version = yield utils.getInput('php-version', true);
// check the os version and run the respective script // check the os version and run the respective script
let script_path = ''; let script_path = '';
switch (os_version) { switch (os_version) {
@ -64,11 +64,12 @@ function run() {
script_path = yield build(os_version + '.sh', version, os_version); script_path = yield build(os_version + '.sh', version, os_version);
yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname); yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'linux': case 'linux': {
let pecl = yield utils.getInput('pecl', false); const pecl = yield utils.getInput('pecl', false);
script_path = yield build(os_version + '.sh', version, os_version); script_path = yield build(os_version + '.sh', version, os_version);
yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + pecl); yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + pecl);
break; break;
}
case 'win32': case 'win32':
script_path = yield build('win32.ps1', version, os_version); script_path = yield build('win32.ps1', version, os_version);
yield exec_1.exec('pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname); yield exec_1.exec('pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname);

View File

@ -27,7 +27,7 @@ const core = __importStar(require("@actions/core"));
*/ */
function getInput(name, mandatory) { function getInput(name, mandatory) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let input = process.env[name]; const input = process.env[name];
switch (input) { switch (input) {
case '': case '':
case undefined: case undefined:
@ -53,6 +53,90 @@ function asyncForEach(array, callback) {
}); });
} }
exports.asyncForEach = asyncForEach; exports.asyncForEach = asyncForEach;
/**
* Get color index
*
* @param type
*/
function color(type) {
return __awaiter(this, void 0, void 0, function* () {
switch (type) {
case 'error':
return '31';
default:
case 'success':
return '32';
case 'warning':
return '33';
}
});
}
exports.color = color;
/**
* Log to console
*
* @param message
* @param os_version
* @param log_type
* @param prefix
*/
function log(message, os_version, log_type) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return ('printf "\\033[' +
(yield color(log_type)) +
';1m' +
message +
' \\033[0m"');
case 'linux':
case 'darwin':
default:
return ('echo "\\033[' + (yield color(log_type)) + ';1m' + message + '\\033[0m"');
}
});
}
exports.log = log;
/**
* Function to log a step
*
* @param message
* @param os_version
*/
function stepLog(message, os_version) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return 'Step-Log "' + message + '"';
case 'linux':
case 'darwin':
return 'step_log "' + message + '"';
default:
return yield log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
exports.stepLog = stepLog;
/**
* Function to log a result
* @param mark
* @param subject
* @param message
*/
function addLog(mark, subject, message, os_version) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
case 'linux':
case 'darwin':
return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
default:
return yield log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
exports.addLog = addLog;
/** /**
* Read the scripts * Read the scripts
* *
@ -87,8 +171,8 @@ exports.readScript = readScript;
*/ */
function writeScript(filename, script) { function writeScript(filename, script) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let runner_dir = yield getInput('RUNNER_TOOL_CACHE', false); const runner_dir = yield getInput('RUNNER_TOOL_CACHE', false);
let script_path = path.join(runner_dir, filename); const script_path = path.join(runner_dir, filename);
fs.writeFileSync(script_path, script, { mode: 0o755 }); fs.writeFileSync(script_path, script, { mode: 0o755 });
return script_path; return script_path;
}); });
@ -136,72 +220,6 @@ function INIArray(ini_values_csv) {
}); });
} }
exports.INIArray = INIArray; exports.INIArray = INIArray;
/**
* Function to log a step
*
* @param message
* @param os_version
*/
function stepLog(message, os_version) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return 'Step-Log "' + message + '"';
case 'linux':
case 'darwin':
return 'step_log "' + message + '"';
default:
return yield log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
exports.stepLog = stepLog;
/**
* Function to log a result
* @param mark
* @param subject
* @param message
*/
function addLog(mark, subject, message, os_version) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return 'Add-Log "' + mark + '" "' + subject + '" "' + message + '"';
case 'linux':
case 'darwin':
return 'add_log "' + mark + '" "' + subject + '" "' + message + '"';
default:
return yield log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
});
}
exports.addLog = addLog;
/**
* Log to console
*
* @param message
* @param os_version
* @param log_type
* @param prefix
*/
function log(message, os_version, log_type) {
return __awaiter(this, void 0, void 0, function* () {
const color = {
error: '31',
success: '32',
warning: '33'
};
switch (os_version) {
case 'win32':
return ('printf "\\033[' + color[log_type] + ';1m' + message + ' \\033[0m"');
case 'linux':
case 'darwin':
default:
return 'echo "\\033[' + color[log_type] + ';1m' + message + '\\033[0m"';
}
});
}
exports.log = log;
/** /**
* Function to get prefix required to load an extension. * Function to get prefix required to load an extension.
* *
@ -209,7 +227,7 @@ exports.log = log;
*/ */
function getExtensionPrefix(extension) { function getExtensionPrefix(extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let zend = ['xdebug', 'opcache', 'ioncube', 'eaccelerator']; const zend = ['xdebug', 'opcache', 'ioncube', 'eaccelerator'];
switch (zend.indexOf(extension)) { switch (zend.indexOf(extension)) {
case 0: case 0:
case 1: case 1:

950
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@
"main": "lib/setup-php.js", "main": "lib/setup-php.js",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"lint": "eslint **/*.ts --cache",
"format": "prettier --write **/*.ts", "format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts", "format-check": "prettier --check **/*.ts",
"test": "jest" "test": "jest"
@ -29,6 +30,13 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^24.0.21", "@types/jest": "^24.0.21",
"@types/node": "^12.12.0", "@types/node": "^12.12.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.0.3",
"eslint-plugin-prettier": "^3.1.1",
"husky": "^3.0.9", "husky": "^3.0.9",
"jest": "^24.9.0", "jest": "^24.9.0",
"jest-circus": "^24.9.0", "jest-circus": "^24.9.0",

View File

@ -1,5 +1,44 @@
import * as utils from './utils'; import * as utils from './utils';
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
export async function addINIValuesUnix(
ini_values_csv: string
): Promise<string> {
const ini_values: Array<string> = await utils.INIArray(ini_values_csv);
let script = '\n';
await utils.asyncForEach(ini_values, async function(line: string) {
script +=
(await utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n';
});
return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script;
}
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
export async function addINIValuesWindows(
ini_values_csv: string
): Promise<string> {
const ini_values: Array<string> = await utils.INIArray(ini_values_csv);
let script = '\n';
await utils.asyncForEach(ini_values, async function(line: string) {
script +=
(await utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
});
return (
'Add-Content C:\\tools\\php\\php.ini "' +
ini_values.join('\n') +
'"' +
script
);
}
/** /**
* Function to add custom ini values * Function to add custom ini values
* *
@ -11,7 +50,7 @@ export async function addINIValues(
os_version: string, os_version: string,
no_step = false no_step = false
): Promise<string> { ): Promise<string> {
let script: string = '\n'; let script = '\n';
switch (no_step) { switch (no_step) {
case true: case true:
script += script +=
@ -38,42 +77,3 @@ export async function addINIValues(
); );
} }
} }
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
export async function addINIValuesUnix(
ini_values_csv: string
): Promise<string> {
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
let script: string = '\n';
await utils.asyncForEach(ini_values, async function(line: string) {
script +=
(await utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n';
});
return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script;
}
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
export async function addINIValuesWindows(
ini_values_csv: string
): Promise<string> {
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
let script: string = '\n';
await utils.asyncForEach(ini_values, async function(line: string) {
script +=
(await utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
});
return (
'Add-Content C:\\tools\\php\\php.ini "' +
ini_values.join('\n') +
'"' +
script
);
}

View File

@ -2,40 +2,16 @@ import * as utils from './utils';
import * as extensions from './extensions'; import * as extensions from './extensions';
import * as config from './config'; import * as config from './config';
/**
* Function to set coverage driver
*
* @param coverage_driver
* @param version
* @param os_version
*/
export async function addCoverage(
coverage_driver: string,
version: string,
os_version: string
): Promise<string> {
coverage_driver.toLowerCase();
let script: string =
'\n' + (await utils.stepLog('Setup Coverage', os_version));
switch (coverage_driver) {
case 'pcov':
return script + (await addCoveragePCOV(version, os_version));
case 'xdebug':
return script + (await addCoverageXdebug(version, os_version));
case 'none':
return script + (await disableCoverage(version, os_version));
default:
return '';
}
}
/** /**
* Function to setup Xdebug * Function to setup Xdebug
* *
* @param version * @param version
* @param os_version * @param os_version
*/ */
export async function addCoverageXdebug(version: string, os_version: string) { export async function addCoverageXdebug(
version: string,
os_version: string
): Promise<string> {
return ( return (
(await extensions.addExtension('xdebug', version, os_version, true)) + (await extensions.addExtension('xdebug', version, os_version, true)) +
(await utils.suppressOutput(os_version)) + (await utils.suppressOutput(os_version)) +
@ -55,8 +31,11 @@ export async function addCoverageXdebug(version: string, os_version: string) {
* @param version * @param version
* @param os_version * @param os_version
*/ */
export async function addCoveragePCOV(version: string, os_version: string) { export async function addCoveragePCOV(
let script: string = '\n'; version: string,
os_version: string
): Promise<string> {
let script = '\n';
switch (version) { switch (version) {
default: default:
script += script +=
@ -115,8 +94,11 @@ export async function addCoveragePCOV(version: string, os_version: string) {
* @param version * @param version
* @param os_version * @param os_version
*/ */
export async function disableCoverage(version: string, os_version: string) { export async function disableCoverage(
let script: string = '\n'; version: string,
os_version: string
): Promise<string> {
let script = '\n';
switch (os_version) { switch (os_version) {
case 'linux': case 'linux':
script += script +=
@ -154,3 +136,30 @@ export async function disableCoverage(version: string, os_version: string) {
return script; return script;
} }
/**
* Function to set coverage driver
*
* @param coverage_driver
* @param version
* @param os_version
*/
export async function addCoverage(
coverage_driver: string,
version: string,
os_version: string
): Promise<string> {
coverage_driver.toLowerCase();
const script: string =
'\n' + (await utils.stepLog('Setup Coverage', os_version));
switch (coverage_driver) {
case 'pcov':
return script + (await addCoveragePCOV(version, os_version));
case 'xdebug':
return script + (await addCoverageXdebug(version, os_version));
case 'none':
return script + (await disableCoverage(version, os_version));
default:
return '';
}
}

View File

@ -1,49 +1,6 @@
import * as path from 'path'; import * as path from 'path';
import * as utils from './utils'; import * as utils from './utils';
/**
* Install and enable extensions
*
* @param extension_csv
* @param version
* @param os_version
* @param log_prefix
*/
export async function addExtension(
extension_csv: string,
version: string,
os_version: string,
no_step = false
): Promise<string> {
let script: string = '\n';
switch (no_step) {
case true:
script +=
(await utils.stepLog('Setup Extensions', os_version)) +
(await utils.suppressOutput(os_version));
break;
case false:
default:
script += await utils.stepLog('Setup Extensions', os_version);
break;
}
switch (os_version) {
case 'win32':
return script + (await addExtensionWindows(extension_csv, version));
case 'darwin':
return script + (await addExtensionDarwin(extension_csv, version));
case 'linux':
return script + (await addExtensionLinux(extension_csv, version));
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}
/** /**
* Install and enable extensions for darwin * Install and enable extensions for darwin
* *
@ -54,12 +11,12 @@ export async function addExtensionDarwin(
extension_csv: string, extension_csv: string,
version: string version: string
): Promise<string> { ): Promise<string> {
let extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script: string = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
// add script to enable extension is already installed along with php // add script to enable extension is already installed along with php
let install_command: string = ''; let install_command = '';
switch (version + extension) { switch (version + extension) {
case '5.6xdebug': case '5.6xdebug':
install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1';
@ -89,16 +46,16 @@ export async function addExtensionWindows(
extension_csv: string, extension_csv: string,
version: string version: string
): Promise<string> { ): Promise<string> {
let extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script: string = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
// add script to enable extension is already installed along with php // add script to enable extension is already installed along with php
let install_command: string = ''; let install_command = '';
switch (version + extension) { switch (version + extension) {
case '7.4xdebug': case '7.4xdebug': {
const extension_url: string = const extension_url =
'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll'; 'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
install_command = install_command =
'Invoke-WebRequest -Uri ' + 'Invoke-WebRequest -Uri ' +
@ -106,6 +63,7 @@ export async function addExtensionWindows(
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n'; ' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
install_command += 'Enable-PhpExtension xdebug'; install_command += 'Enable-PhpExtension xdebug';
break; break;
}
case '7.2xdebug': case '7.2xdebug':
default: default:
install_command = 'Install-PhpExtension ' + extension; install_command = 'Install-PhpExtension ' + extension;
@ -132,13 +90,13 @@ export async function addExtensionLinux(
extension_csv: string, extension_csv: string,
version: string version: string
): Promise<string> { ): Promise<string> {
let extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script: string = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
// add script to enable extension is already installed along with php // add script to enable extension is already installed along with php
let install_command: string = ''; let install_command = '';
switch (version + extension) { switch (version + extension) {
case '7.2phalcon3': case '7.2phalcon3':
case '7.3phalcon3': case '7.3phalcon3':
@ -180,3 +138,46 @@ export async function addExtensionLinux(
}); });
return script; return script;
} }
/**
* Install and enable extensions
*
* @param extension_csv
* @param version
* @param os_version
* @param log_prefix
*/
export async function addExtension(
extension_csv: string,
version: string,
os_version: string,
no_step = false
): Promise<string> {
let script = '\n';
switch (no_step) {
case true:
script +=
(await utils.stepLog('Setup Extensions', os_version)) +
(await utils.suppressOutput(os_version));
break;
case false:
default:
script += await utils.stepLog('Setup Extensions', os_version);
break;
}
switch (os_version) {
case 'win32':
return script + (await addExtensionWindows(extension_csv, version));
case 'darwin':
return script + (await addExtensionDarwin(extension_csv, version));
case 'linux':
return script + (await addExtensionLinux(extension_csv, version));
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}

View File

@ -18,9 +18,9 @@ export async function build(
os_version: string os_version: string
): Promise<string> { ): Promise<string> {
// taking inputs // taking inputs
let extension_csv: string = await utils.getInput('extension-csv', false); const extension_csv: string = await utils.getInput('extension-csv', false);
let ini_values_csv: string = await utils.getInput('ini-values-csv', false); const ini_values_csv: string = await utils.getInput('ini-values-csv', false);
let coverage_driver: string = await utils.getInput('coverage', false); const coverage_driver: string = await utils.getInput('coverage', false);
let script: string = await utils.readScript(filename, version, os_version); let script: string = await utils.readScript(filename, version, os_version);
if (extension_csv) { if (extension_csv) {
@ -39,22 +39,23 @@ export async function build(
/** /**
* Run the script * Run the script
*/ */
export async function run() { export async function run(): Promise<void> {
try { try {
let os_version: string = process.platform; const os_version: string = process.platform;
let version: string = await utils.getInput('php-version', true); const version: string = await utils.getInput('php-version', true);
// check the os version and run the respective script // check the os version and run the respective script
let script_path: string = ''; let script_path = '';
switch (os_version) { switch (os_version) {
case 'darwin': case 'darwin':
script_path = await build(os_version + '.sh', version, os_version); script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + __dirname); await exec('sh ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'linux': case 'linux': {
let pecl: string = await utils.getInput('pecl', false); const pecl: string = await utils.getInput('pecl', false);
script_path = await build(os_version + '.sh', version, os_version); script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + pecl); await exec('sh ' + script_path + ' ' + version + ' ' + pecl);
break; break;
}
case 'win32': case 'win32':
script_path = await build('win32.ps1', version, os_version); script_path = await build('win32.ps1', version, os_version);
await exec( await exec(

View File

@ -12,7 +12,7 @@ export async function getInput(
name: string, name: string,
mandatory: boolean mandatory: boolean
): Promise<string> { ): Promise<string> {
let input = process.env[name]; const input = process.env[name];
switch (input) { switch (input) {
case '': case '':
case undefined: case undefined:
@ -30,111 +30,67 @@ export async function getInput(
* @param callback * @param callback
*/ */
export async function asyncForEach( export async function asyncForEach(
array: Array<any>, array: Array<string>,
callback: any callback: (
): Promise<any> { element: string,
for (let index: number = 0; index < array.length; index++) { index: number,
array: Array<string>
) => Promise<void>
): Promise<void> {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array); await callback(array[index], index, array);
} }
} }
/** /**
* Read the scripts * Get color index
* *
* @param filename * @param type
* @param version
* @param os_version
*/ */
export async function readScript( export async function color(type: string): Promise<string> {
filename: string, switch (type) {
version: string, case 'error':
os_version: string return '31';
default:
case 'success':
return '32';
case 'warning':
return '33';
}
}
/**
* Log to console
*
* @param message
* @param os_version
* @param log_type
* @param prefix
*/
export async function log(
message: string,
os_version: string,
log_type: string
): Promise<string> { ): Promise<string> {
switch (os_version) { switch (os_version) {
case 'darwin':
switch (version) {
case '7.4':
return fs.readFileSync(
path.join(__dirname, '../src/scripts/7.4.sh'),
'utf8'
);
}
return fs.readFileSync(
path.join(__dirname, '../src/scripts/' + filename),
'utf8'
);
case 'linux':
case 'win32': case 'win32':
return fs.readFileSync( return (
path.join(__dirname, '../src/scripts/' + filename), 'printf "\\033[' +
'utf8' (await color(log_type)) +
';1m' +
message +
' \\033[0m"'
); );
case 'linux':
case 'darwin':
default: default:
return await log( return (
'Platform ' + os_version + ' is not supported', 'echo "\\033[' + (await color(log_type)) + ';1m' + message + '\\033[0m"'
os_version,
'error'
); );
} }
} }
/**
* Write final script which runs
*
* @param filename
* @param version
* @param script
*/
export async function writeScript(
filename: string,
script: string
): Promise<string> {
let runner_dir: string = await getInput('RUNNER_TOOL_CACHE', false);
let script_path: string = path.join(runner_dir, filename);
fs.writeFileSync(script_path, script, {mode: 0o755});
return script_path;
}
/**
* Function to break extension csv into an array
*
* @param extension_csv
*/
export async function extensionArray(
extension_csv: string
): Promise<Array<string>> {
switch (extension_csv) {
case '':
case ' ':
return [];
default:
return extension_csv.split(',').map(function(extension: string) {
return extension
.trim()
.replace('php-', '')
.replace('php_', '');
});
}
}
/**
* Function to break ini values csv into an array
*
* @param ini_values_csv
* @constructor
*/
export async function INIArray(ini_values_csv: string): Promise<Array<string>> {
switch (ini_values_csv) {
case '':
case ' ':
return [];
default:
return ini_values_csv.split(',').map(function(ini_value: string) {
return ini_value.trim();
});
}
}
/** /**
* Function to log a step * Function to log a step
* *
@ -188,34 +144,99 @@ export async function addLog(
} }
/** /**
* Log to console * Read the scripts
* *
* @param message * @param filename
* @param version
* @param os_version * @param os_version
* @param log_type
* @param prefix
*/ */
export async function log( export async function readScript(
message: string, filename: string,
os_version: string, version: string,
log_type: string os_version: string
): Promise<string> { ): Promise<string> {
const color: any = {
error: '31',
success: '32',
warning: '33'
};
switch (os_version) { switch (os_version) {
case 'win32':
return (
'printf "\\033[' + color[log_type] + ';1m' + message + ' \\033[0m"'
);
case 'linux':
case 'darwin': case 'darwin':
switch (version) {
case '7.4':
return fs.readFileSync(
path.join(__dirname, '../src/scripts/7.4.sh'),
'utf8'
);
}
return fs.readFileSync(
path.join(__dirname, '../src/scripts/' + filename),
'utf8'
);
case 'linux':
case 'win32':
return fs.readFileSync(
path.join(__dirname, '../src/scripts/' + filename),
'utf8'
);
default: default:
return 'echo "\\033[' + color[log_type] + ';1m' + message + '\\033[0m"'; return await log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}
/**
* Write final script which runs
*
* @param filename
* @param version
* @param script
*/
export async function writeScript(
filename: string,
script: string
): Promise<string> {
const runner_dir: string = await getInput('RUNNER_TOOL_CACHE', false);
const script_path: string = path.join(runner_dir, filename);
fs.writeFileSync(script_path, script, {mode: 0o755});
return script_path;
}
/**
* Function to break extension csv into an array
*
* @param extension_csv
*/
export async function extensionArray(
extension_csv: string
): Promise<Array<string>> {
switch (extension_csv) {
case '':
case ' ':
return [];
default:
return extension_csv.split(',').map(function(extension: string) {
return extension
.trim()
.replace('php-', '')
.replace('php_', '');
});
}
}
/**
* Function to break ini values csv into an array
*
* @param ini_values_csv
* @constructor
*/
export async function INIArray(ini_values_csv: string): Promise<Array<string>> {
switch (ini_values_csv) {
case '':
case ' ':
return [];
default:
return ini_values_csv.split(',').map(function(ini_value: string) {
return ini_value.trim();
});
} }
} }
@ -225,7 +246,7 @@ export async function log(
* @param extension * @param extension
*/ */
export async function getExtensionPrefix(extension: string): Promise<string> { export async function getExtensionPrefix(extension: string): Promise<string> {
let zend: Array<string> = ['xdebug', 'opcache', 'ioncube', 'eaccelerator']; const zend: Array<string> = ['xdebug', 'opcache', 'ioncube', 'eaccelerator'];
switch (zend.indexOf(extension)) { switch (zend.indexOf(extension)) {
case 0: case 0:
case 1: case 1: