Add support for adding PHP extensions

This commit is contained in:
Shivam Mathur
2019-09-07 18:01:50 +05:30
parent 1c6748567c
commit c5513d9a78
6842 changed files with 266 additions and 1017047 deletions

View File

@ -18,59 +18,108 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec/lib/exec");
const fs = require('fs');
let darwin = `echo $1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew unlink php
brew tap exolnet/homebrew-deprecated
brew tap homebrew/homebrew-php
brew install php@$1
brew link --force --overwrite php@$1
curl -sS https://getcomposer.org/installer | php
chmod +x composer.phar
mv composer.phar /usr/local/bin/composer
php -v
composer -V`;
let linux = `sudo add-apt-repository ppa:ondrej/php -y
sudo apt update -y
sudo apt install -y php$1 curl
sudo update-alternatives --set php /usr/bin/php$1
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
php -v
composer -V`;
let windows = `param (
[Parameter(Mandatory=$true)][string]$version = "7.3"
)
echo "Installing NuGet"
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
if($version -lt '7.0') {
echo "Installing Visual C++"
Install-Module -Name VcRedist -Force
New-Item -Path C:\\Temp\\VcRedist -ItemType Directory
Get-VcList | Save-VcRedist -Path C:\\Temp\\VcRedist
$VcList = Get-VcList
Install-VcRedist -Path C:\\Temp\\VcRedist -VcList $VcList -Silent
const path = __importStar(require("path"));
const httpm = __importStar(require("typed-rest-client/HttpClient"));
const fs = __importStar(require("fs"));
/*
Read the scripts
*/
let darwin = fs.readFileSync(path.join(__dirname, '../src/darwin.sh'), 'utf8');
let linux = fs.readFileSync(path.join(__dirname, '../src/linux.sh'), 'utf8');
let windows = fs.readFileSync(path.join(__dirname, '../src/windows.ps1'), 'utf8');
/*
Credit: https://github.com/Atinux
*/
function asyncForEach(array, callback) {
return __awaiter(this, void 0, void 0, function* () {
for (let index = 0; index < array.length; index++) {
yield callback(array[index], index, array);
}
});
}
echo "Installing PhpManager"
Install-Module -Name PhpManager -Force -Scope CurrentUser
echo "Installing PHP"
Uninstall-Php C:\\tools\\php
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -Path C:\\tools\\php$version -TimeZone UTC
echo "Switch PHP"
(Get-PhpSwitcher).targets
Initialize-PhpSwitcher -Alias C:\\tools\\php -Scope CurrentUser -Force
Add-PhpToSwitcher -Name $version -Path C:\\tools\\php$version -Force
Switch-Php $version -Force
echo "Housekeeping in PHP.ini, enabling openssl"
Move-item -Path C:\\tools\\php$version\\php.ini-development -Destination C:\\tools\\php$version\\php.ini -Force
Add-Content C:\\tools\\php$version\\php.ini "extension=C:\\tools\\php$version\\ext\\php_openssl.dll"
Add-Content C:\\tools\\php$version\\php.ini "date.timezone = 'UTC'"
echo "Installing Composer"
Install-Composer -Scope System -Path C:\\tools\\php
php -v
composer -V`;
/*
Enable functions which are installed but not enabled
*/
function enableExtension(extension) {
return __awaiter(this, void 0, void 0, function* () {
windows += `try {
$ext_dir = Get-PhpIniKey extension_dir
$exist = Test-Path -Path $ext_dir\\php_${extension}.dll
$enabled = php -r "if (in_array('${extension}', get_loaded_extensions())) {echo 'yes';} else {echo 'no';}"
if($enabled -eq 'no' -and $exist) {
Enable-PhpExtension ${extension} C:\\tools\\php$version
}
} catch [Exception] {
echo $_
}\n`;
let shell_code = `ext_dir=$(php -i | grep "extension_dir" | sed -e "s|.*=>\s*||")
enabled=$(php -r "if (in_array('${extension}', get_loaded_extensions())) {echo 'yes';} else {echo 'no';}")
if [ "$enabled" == 'no' ] && [ test -f "$ext_dir/${extension}.so" ]; then
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*:\s*||"'
fi\n`;
linux += shell_code;
darwin += shell_code;
});
}
/*
Install and enable extensions
*/
function addExtension(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () {
let extensions = extension_csv
.split(',')
.map(function (extension) {
return extension
.trim()
.replace('php-', '')
.replace('php_', '');
});
linux += '\n';
windows += '\n';
darwin += '\n';
yield asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () {
enableExtension(extension);
linux +=
'sudo apt install -y php' +
version +
'-' +
extension +
' || echo "Couldn\'t find extension php' +
version +
'-' +
extension +
'"\n';
const http = new httpm.HttpClient('shivammathur/php-setup', [], {
allowRetries: true,
maxRetries: 2
});
const response = yield http.get('https://pecl.php.net/package/' + extension);
if (response.message.statusCode == 200) {
windows +=
'try { Install-PhpExtension ' +
extension +
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
extension +
' }\n';
darwin +=
'pecl install ' +
extension +
' || echo "Couldn\'t find extension: ' +
extension +
'"\n';
}
else {
console.log('Cannot find pecl extension: ' + extension);
}
});
});
linux += 'sudo apt autoremove -y';
});
}
/*
Write final script which runs
*/
function createScript(filename, version) {
return __awaiter(this, void 0, void 0, function* () {
let script = '';
@ -91,6 +140,9 @@ function createScript(filename, version) {
});
});
}
/*
Run the script
*/
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
@ -99,6 +151,14 @@ function run() {
version = core.getInput('php-version', { required: true });
}
console.log('Input: ' + version);
let extension_csv = process.env['extension-csv'];
if (!extension_csv) {
extension_csv = core.getInput('extension-csv');
}
if (extension_csv) {
console.log('Input: ' + extension_csv);
yield addExtension(extension_csv, version);
}
let os_version = process.platform;
if (os_version == 'darwin') {
yield createScript('darwin.sh', version);
@ -120,6 +180,7 @@ function run() {
}
});
}
run().then(() => {
// call the run function
run().then(function () {
console.log('done');
});