mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-07-23 23:29:07 +07:00
Add coverage support, improve logs and fix bugs
This commit is contained in:
186
lib/features.js
186
lib/features.js
@ -18,24 +18,32 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils = __importStar(require("./utils"));
|
||||
const pecl = __importStar(require("./pecl"));
|
||||
function addExtension(extensions, version, os_version) {
|
||||
function addExtension(extension_csv, version, os_version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (os_version === 'win32') {
|
||||
return yield addExtensionWindows(extensions, version);
|
||||
switch (os_version) {
|
||||
case 'win32':
|
||||
return yield addExtensionWindows(extension_csv, version);
|
||||
case 'darwin':
|
||||
return yield addExtensionDarwin(extension_csv, version);
|
||||
case 'linux':
|
||||
return yield addExtensionLinux(extension_csv, version);
|
||||
default:
|
||||
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
}
|
||||
else if (os_version === 'linux') {
|
||||
return yield addExtensionLinux(extensions, version);
|
||||
}
|
||||
return yield addExtensionDarwin(extensions);
|
||||
});
|
||||
}
|
||||
exports.addExtension = addExtension;
|
||||
function addINIValues(ini_values_csv, os_version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (os_version === 'win32') {
|
||||
return yield addINIValuesWindows(ini_values_csv);
|
||||
switch (os_version) {
|
||||
case 'win32':
|
||||
return yield addINIValuesWindows(ini_values_csv);
|
||||
case 'darwin':
|
||||
case 'linux':
|
||||
return yield addINIValuesUnix(ini_values_csv);
|
||||
default:
|
||||
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
}
|
||||
return yield addINIValuesUnix(ini_values_csv);
|
||||
});
|
||||
}
|
||||
exports.addINIValues = addINIValues;
|
||||
@ -46,14 +54,15 @@ exports.addINIValues = addINIValues;
|
||||
*/
|
||||
function enableExtensionWindows(extension) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return `try {
|
||||
return (`try {
|
||||
$exist = Test-Path -Path $ext_dir\\php_${extension}.dll
|
||||
if(!(php -m | findstr -i ${extension}) -and $exist) {
|
||||
Enable-PhpExtension ${extension} C:\\tools\\php
|
||||
}
|
||||
} catch [Exception] {
|
||||
echo $_
|
||||
}\n`;
|
||||
Enable-PhpExtension ${extension} C:\\tools\\php\n` +
|
||||
(yield utils.log(extension + ' enabled', 'win32', 'success')) +
|
||||
`}
|
||||
} catch [Exception] {\n` +
|
||||
(yield utils.log(extension + ' could not be installed', 'win32', 'error')) +
|
||||
` }\n`);
|
||||
});
|
||||
}
|
||||
exports.enableExtensionWindows = enableExtensionWindows;
|
||||
@ -64,10 +73,10 @@ exports.enableExtensionWindows = enableExtensionWindows;
|
||||
*/
|
||||
function enableExtensionUnix(extension) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return `if [ ! "$(php -m | grep ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then
|
||||
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'
|
||||
echo "${extension} enabled"
|
||||
fi\n`;
|
||||
return (`if [ ! "$(php -m | grep ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then
|
||||
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'\n` +
|
||||
(yield utils.log(extension + ' enabled', 'unix', 'success')) +
|
||||
`; fi\n`);
|
||||
});
|
||||
}
|
||||
exports.enableExtensionUnix = enableExtensionUnix;
|
||||
@ -75,24 +84,37 @@ exports.enableExtensionUnix = enableExtensionUnix;
|
||||
* Install and enable extensions for darwin
|
||||
*
|
||||
* @param extension_csv
|
||||
* @param version
|
||||
*/
|
||||
function addExtensionDarwin(extension_csv) {
|
||||
function addExtensionDarwin(extension_csv, version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let extensions = yield utils.extensionArray(extension_csv);
|
||||
let script = '\n';
|
||||
yield utils.asyncForEach(extensions, function (extension) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
extension = extension.toLowerCase();
|
||||
// add script to enable extension is already installed along with php
|
||||
script += yield enableExtensionUnix(extension);
|
||||
if (yield pecl.checkPECLExtension(extension)) {
|
||||
script +=
|
||||
'if [ ! "$(php -m | grep ' +
|
||||
extension +
|
||||
')" ]; then sudo pecl install ' +
|
||||
extension +
|
||||
' || echo "Couldn\'t find extension: ' +
|
||||
extension +
|
||||
'"; fi\n';
|
||||
switch (yield pecl.checkPECLExtension(extension)) {
|
||||
case true:
|
||||
extension =
|
||||
version === '5.6' && extension === 'xdebug'
|
||||
? 'xdebug-2.5.5'
|
||||
: extension;
|
||||
script +=
|
||||
'if [ ! "$(php -m | grep ' +
|
||||
extension +
|
||||
')" ]; then sudo pecl install ' +
|
||||
extension +
|
||||
' || ' +
|
||||
(yield utils.log("Couldn't install extension: " + extension, 'darwin', 'error')) +
|
||||
'; fi\n';
|
||||
break;
|
||||
case false:
|
||||
default:
|
||||
script +=
|
||||
(yield utils.log('Could not find extension: ' + extension, 'darwin', 'error')) + '\n';
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -112,24 +134,38 @@ function addExtensionWindows(extension_csv, version) {
|
||||
let script = '\n';
|
||||
yield utils.asyncForEach(extensions, function (extension) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
extension = extension.toLowerCase();
|
||||
// add script to enable extension is already installed along with php
|
||||
script += yield enableExtensionWindows(extension);
|
||||
let extension_version = 'stable';
|
||||
if (version == '7.4') {
|
||||
extension_version = 'alpha';
|
||||
let extension_version = '';
|
||||
switch (version) {
|
||||
case '7.4':
|
||||
extension_version = 'alpha';
|
||||
break;
|
||||
case '7.2':
|
||||
default:
|
||||
extension_version = 'stable';
|
||||
break;
|
||||
}
|
||||
if (yield pecl.checkPECLExtension(extension)) {
|
||||
script +=
|
||||
'if(!(php -m | findstr -i ' +
|
||||
extension +
|
||||
')) { ' +
|
||||
'try { Install-PhpExtension ' +
|
||||
extension +
|
||||
' -MinimumStability ' +
|
||||
extension_version +
|
||||
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
|
||||
extension +
|
||||
' } }\n';
|
||||
switch (yield pecl.checkPECLExtension(extension)) {
|
||||
case true:
|
||||
script +=
|
||||
'if(!(php -m | findstr -i ' +
|
||||
extension +
|
||||
')) { ' +
|
||||
'try { Install-PhpExtension ' +
|
||||
extension +
|
||||
' -MinimumStability ' +
|
||||
extension_version +
|
||||
' } catch [Exception] { ' +
|
||||
(yield utils.log('Could not install extension: ' + extension, 'win32', 'error')) +
|
||||
' } }\n';
|
||||
break;
|
||||
case false:
|
||||
default:
|
||||
script +=
|
||||
(yield utils.log('Could not find extension: ' + extension, 'win32', 'error')) + '\n';
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -149,6 +185,7 @@ function addExtensionLinux(extension_csv, version) {
|
||||
let script = '\n';
|
||||
yield utils.asyncForEach(extensions, function (extension) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
extension = extension.toLowerCase();
|
||||
// add script to enable extension is already installed along with php
|
||||
script += yield enableExtensionUnix(extension);
|
||||
script +=
|
||||
@ -158,11 +195,9 @@ function addExtensionLinux(extension_csv, version) {
|
||||
version +
|
||||
'-' +
|
||||
extension +
|
||||
' || echo "Couldn\'t find extension php' +
|
||||
version +
|
||||
'-' +
|
||||
extension +
|
||||
'"; fi\n';
|
||||
' || ' +
|
||||
(yield utils.log("Couldn't find extension php" + version + '-' + extension, 'linux', 'error')) +
|
||||
'; fi\n';
|
||||
});
|
||||
});
|
||||
return script;
|
||||
@ -207,3 +242,54 @@ function addINIValuesWindows(ini_values_csv) {
|
||||
});
|
||||
}
|
||||
exports.addINIValuesWindows = addINIValuesWindows;
|
||||
function addCoverage(coverage, version, os_version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let script = '';
|
||||
script += '\n';
|
||||
coverage = coverage.toLowerCase();
|
||||
// pcov
|
||||
switch (coverage) {
|
||||
case 'pcov':
|
||||
// if version is 7.1 or newer
|
||||
switch (version) {
|
||||
default:
|
||||
script += yield addExtension(coverage, version, os_version);
|
||||
script += yield addINIValues('pcov.enabled=1', os_version);
|
||||
// add command to disable xdebug and enable pcov
|
||||
switch (os_version) {
|
||||
case 'linux':
|
||||
script +=
|
||||
"sudo phpdismod xdebug || echo 'xdebug not installed'\n";
|
||||
script += "sudo phpenmod pcov || echo 'pcov not installed'\n";
|
||||
break;
|
||||
case 'darwin':
|
||||
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
|
||||
break;
|
||||
case 'win32':
|
||||
script +=
|
||||
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
|
||||
break;
|
||||
}
|
||||
// success
|
||||
script += yield utils.log('pcov enabled as coverage driver', os_version, 'success');
|
||||
// version is not supported
|
||||
break;
|
||||
case '5.6':
|
||||
case '7.0':
|
||||
script += yield utils.log('pcov requires php 7.1 or newer', os_version, 'warning');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
//xdebug
|
||||
case 'xdebug':
|
||||
script += yield addExtension(coverage, version, os_version);
|
||||
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success');
|
||||
break;
|
||||
// unknown coverage driver
|
||||
default:
|
||||
script = '';
|
||||
}
|
||||
return script;
|
||||
});
|
||||
}
|
||||
exports.addCoverage = addCoverage;
|
||||
|
@ -30,12 +30,14 @@ function run() {
|
||||
let version = yield utils.getInput('php-version', true);
|
||||
let extension_csv = yield utils.getInput('extension-csv', false);
|
||||
let ini_values_csv = yield utils.getInput('ini-values-csv', false);
|
||||
let coverage = yield utils.getInput('coverage', false);
|
||||
let os_version = process.platform;
|
||||
// check the os version and run the respective script
|
||||
if (os_version == 'darwin') {
|
||||
let darwin = yield utils.readScript('darwin.sh', version, os_version);
|
||||
darwin += yield features.addExtension(extension_csv, version, os_version);
|
||||
darwin += yield features.addINIValues(ini_values_csv, os_version);
|
||||
darwin += yield features.addCoverage(coverage, version, os_version);
|
||||
yield utils.writeScript('darwin.sh', version, darwin);
|
||||
yield exec_1.exec('sh -x ./' + version + 'darwin.sh ' + version);
|
||||
}
|
||||
@ -43,6 +45,7 @@ function run() {
|
||||
let windows = yield utils.readScript('win32.ps1', version, os_version);
|
||||
windows += yield features.addExtension(extension_csv, version, os_version);
|
||||
windows += yield features.addINIValues(ini_values_csv, os_version);
|
||||
windows += yield features.addCoverage(coverage, version, os_version);
|
||||
yield utils.writeScript('win32.ps1', version, windows);
|
||||
yield exec_1.exec('powershell .\\' + version + 'win32.ps1 -version ' + version);
|
||||
}
|
||||
@ -50,6 +53,7 @@ function run() {
|
||||
let linux = yield utils.readScript('linux.sh', version, os_version);
|
||||
linux += yield features.addExtension(extension_csv, version, os_version);
|
||||
linux += yield features.addINIValues(ini_values_csv, os_version);
|
||||
linux += yield features.addCoverage(coverage, version, os_version);
|
||||
yield utils.writeScript('linux.sh', version, linux);
|
||||
yield exec_1.exec('./' + version + 'linux.sh ' + version);
|
||||
}
|
||||
|
49
lib/utils.js
49
lib/utils.js
@ -22,10 +22,13 @@ const core = __importStar(require("@actions/core"));
|
||||
function getInput(name, mandatory) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let input = process.env[name];
|
||||
if (!input) {
|
||||
input = core.getInput(name, { required: mandatory });
|
||||
switch (input) {
|
||||
case '':
|
||||
case undefined:
|
||||
return core.getInput(name, { required: mandatory });
|
||||
default:
|
||||
return input;
|
||||
}
|
||||
return input;
|
||||
});
|
||||
}
|
||||
exports.getInput = getInput;
|
||||
@ -53,10 +56,21 @@ exports.asyncForEach = asyncForEach;
|
||||
*/
|
||||
function readScript(filename, version, os_version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (version === '7.4' && os_version === 'darwin') {
|
||||
return fs.readFileSync(path.join(__dirname, '../src/7.4.sh'), 'utf8');
|
||||
switch (os_version) {
|
||||
case 'darwin':
|
||||
switch (version) {
|
||||
case '7.4':
|
||||
return fs.readFileSync(path.join(__dirname, '../src/7.4.sh'), 'utf8');
|
||||
case '7.3':
|
||||
default:
|
||||
return fs.readFileSync(path.join(__dirname, '../src/' + filename), 'utf8');
|
||||
}
|
||||
case 'win32':
|
||||
case 'linux':
|
||||
return fs.readFileSync(path.join(__dirname, '../src/' + filename), 'utf8');
|
||||
default:
|
||||
return yield log('Platform ' + os_version + ' is not supported', os_version, 'error');
|
||||
}
|
||||
return fs.readFileSync(path.join(__dirname, '../src/' + filename), 'utf8');
|
||||
});
|
||||
}
|
||||
exports.readScript = readScript;
|
||||
@ -102,3 +116,26 @@ function INIArray(ini_values_csv) {
|
||||
});
|
||||
}
|
||||
exports.INIArray = INIArray;
|
||||
function log(message, os_version, log_type) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
switch (os_version) {
|
||||
case 'win32':
|
||||
const color = {
|
||||
error: 'red',
|
||||
success: 'green',
|
||||
warning: 'yellow'
|
||||
};
|
||||
return "Write-Host '" + message + "' -ForegroundColor " + color[log_type];
|
||||
case 'linux':
|
||||
case 'darwin':
|
||||
default:
|
||||
const unix_color = {
|
||||
error: '31',
|
||||
success: '32',
|
||||
warning: '33'
|
||||
};
|
||||
return ('echo -e "\\033[' + unix_color[log_type] + ';1m' + message + '\\033[0m"');
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.log = log;
|
||||
|
Reference in New Issue
Block a user