mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Merge branch 'develop'
This commit is contained in:
commit
2484a27666
@ -24,6 +24,7 @@ const fs = __importStar(require("fs"));
|
|||||||
/*
|
/*
|
||||||
Read the scripts
|
Read the scripts
|
||||||
*/
|
*/
|
||||||
|
let os_version = process.platform;
|
||||||
let darwin = fs.readFileSync(path.join(__dirname, '../src/darwin.sh'), 'utf8');
|
let darwin = fs.readFileSync(path.join(__dirname, '../src/darwin.sh'), 'utf8');
|
||||||
let linux = fs.readFileSync(path.join(__dirname, '../src/linux.sh'), 'utf8');
|
let linux = fs.readFileSync(path.join(__dirname, '../src/linux.sh'), 'utf8');
|
||||||
let windows = fs.readFileSync(path.join(__dirname, '../src/windows.ps1'), 'utf8');
|
let windows = fs.readFileSync(path.join(__dirname, '../src/windows.ps1'), 'utf8');
|
||||||
@ -38,7 +39,7 @@ function asyncForEach(array, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Enable functions which are installed but not enabled
|
Enable extensions which are installed but not enabled
|
||||||
*/
|
*/
|
||||||
function enableExtension(extension) {
|
function enableExtension(extension) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -52,10 +53,11 @@ function enableExtension(extension) {
|
|||||||
} catch [Exception] {
|
} catch [Exception] {
|
||||||
echo $_
|
echo $_
|
||||||
}\n`;
|
}\n`;
|
||||||
let shell_code = `ext_dir=$(php -i | grep "extension_dir" | sed -e "s|.*=>\s*||")
|
let shell_code = `ext_dir=$(php-config --extension-dir)
|
||||||
enabled=$(php -r "if (in_array('${extension}', get_loaded_extensions())) {echo 'yes';} else {echo 'no';}")
|
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
|
if [ "$enabled" = "no" ] && [ -e "$ext_dir/${extension}.so" ]; then
|
||||||
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*:\s*||"'
|
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'
|
||||||
|
echo "${extension} enabled"
|
||||||
fi\n`;
|
fi\n`;
|
||||||
linux += shell_code;
|
linux += shell_code;
|
||||||
darwin += shell_code;
|
darwin += shell_code;
|
||||||
@ -79,38 +81,45 @@ function addExtension(extension_csv, version) {
|
|||||||
darwin += '\n';
|
darwin += '\n';
|
||||||
yield asyncForEach(extensions, function (extension) {
|
yield asyncForEach(extensions, function (extension) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// add script to enable extension is already installed along with php
|
||||||
enableExtension(extension);
|
enableExtension(extension);
|
||||||
linux +=
|
// else add script to attempt to install the extension
|
||||||
'sudo apt install -y php' +
|
if (os_version == 'linux') {
|
||||||
version +
|
linux +=
|
||||||
'-' +
|
'sudo apt install -y php' +
|
||||||
extension +
|
version +
|
||||||
' || 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 +
|
extension +
|
||||||
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
|
' || echo "Couldn\'t find extension php' +
|
||||||
extension +
|
version +
|
||||||
' }\n';
|
'-' +
|
||||||
darwin +=
|
|
||||||
'pecl install ' +
|
|
||||||
extension +
|
|
||||||
' || echo "Couldn\'t find extension: ' +
|
|
||||||
extension +
|
extension +
|
||||||
'"\n';
|
'"\n';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log('Cannot find pecl extension: ' + extension);
|
// check if pecl extension exists
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -146,6 +155,7 @@ Run the script
|
|||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
|
// taking inputs
|
||||||
let version = process.env['php-version'];
|
let version = process.env['php-version'];
|
||||||
if (!version) {
|
if (!version) {
|
||||||
version = core.getInput('php-version', { required: true });
|
version = core.getInput('php-version', { required: true });
|
||||||
@ -159,7 +169,7 @@ function run() {
|
|||||||
console.log('Input: ' + extension_csv);
|
console.log('Input: ' + extension_csv);
|
||||||
yield addExtension(extension_csv, version);
|
yield addExtension(extension_csv, version);
|
||||||
}
|
}
|
||||||
let os_version = process.platform;
|
// check the os version and run the respective script
|
||||||
if (os_version == 'darwin') {
|
if (os_version == 'darwin') {
|
||||||
yield createScript('darwin.sh', version);
|
yield createScript('darwin.sh', version);
|
||||||
yield exec_1.exec('sudo chmod a+x ' + version + 'darwin.sh');
|
yield exec_1.exec('sudo chmod a+x ' + version + 'darwin.sh');
|
||||||
|
@ -7,6 +7,7 @@ import * as fs from 'fs';
|
|||||||
/*
|
/*
|
||||||
Read the scripts
|
Read the scripts
|
||||||
*/
|
*/
|
||||||
|
let os_version = process.platform;
|
||||||
let darwin = fs.readFileSync(path.join(__dirname, '../src/darwin.sh'), 'utf8');
|
let darwin = fs.readFileSync(path.join(__dirname, '../src/darwin.sh'), 'utf8');
|
||||||
let linux = fs.readFileSync(path.join(__dirname, '../src/linux.sh'), 'utf8');
|
let linux = fs.readFileSync(path.join(__dirname, '../src/linux.sh'), 'utf8');
|
||||||
let windows = fs.readFileSync(
|
let windows = fs.readFileSync(
|
||||||
@ -24,7 +25,7 @@ async function asyncForEach(array: any, callback: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Enable functions which are installed but not enabled
|
Enable extensions which are installed but not enabled
|
||||||
*/
|
*/
|
||||||
async function enableExtension(extension: string) {
|
async function enableExtension(extension: string) {
|
||||||
windows += `try {
|
windows += `try {
|
||||||
@ -38,10 +39,11 @@ async function enableExtension(extension: string) {
|
|||||||
echo $_
|
echo $_
|
||||||
}\n`;
|
}\n`;
|
||||||
|
|
||||||
let shell_code = `ext_dir=$(php -i | grep "extension_dir" | sed -e "s|.*=>\s*||")
|
let shell_code = `ext_dir=$(php-config --extension-dir)
|
||||||
enabled=$(php -r "if (in_array('${extension}', get_loaded_extensions())) {echo 'yes';} else {echo 'no';}")
|
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
|
if [ "$enabled" = "no" ] && [ -e "$ext_dir/${extension}.so" ]; then
|
||||||
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*:\s*||"'
|
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'
|
||||||
|
echo "${extension} enabled"
|
||||||
fi\n`;
|
fi\n`;
|
||||||
linux += shell_code;
|
linux += shell_code;
|
||||||
darwin += shell_code;
|
darwin += shell_code;
|
||||||
@ -63,39 +65,46 @@ async function addExtension(extension_csv: string, version: string) {
|
|||||||
windows += '\n';
|
windows += '\n';
|
||||||
darwin += '\n';
|
darwin += '\n';
|
||||||
await asyncForEach(extensions, async function(extension: string) {
|
await asyncForEach(extensions, async function(extension: string) {
|
||||||
|
// add script to enable extension is already installed along with php
|
||||||
enableExtension(extension);
|
enableExtension(extension);
|
||||||
linux +=
|
|
||||||
'sudo apt install -y php' +
|
// else add script to attempt to install the extension
|
||||||
version +
|
if (os_version == 'linux') {
|
||||||
'-' +
|
linux +=
|
||||||
extension +
|
'sudo apt install -y php' +
|
||||||
' || echo "Couldn\'t find extension php' +
|
version +
|
||||||
version +
|
'-' +
|
||||||
'-' +
|
|
||||||
extension +
|
|
||||||
'"\n';
|
|
||||||
const http = new httpm.HttpClient('shivammathur/php-setup', [], {
|
|
||||||
allowRetries: true,
|
|
||||||
maxRetries: 2
|
|
||||||
});
|
|
||||||
const response: httpm.HttpClientResponse = await http.get(
|
|
||||||
'https://pecl.php.net/package/' + extension
|
|
||||||
);
|
|
||||||
if (response.message.statusCode == 200) {
|
|
||||||
windows +=
|
|
||||||
'try { Install-PhpExtension ' +
|
|
||||||
extension +
|
extension +
|
||||||
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
|
' || echo "Couldn\'t find extension php' +
|
||||||
extension +
|
version +
|
||||||
' }\n';
|
'-' +
|
||||||
darwin +=
|
|
||||||
'pecl install ' +
|
|
||||||
extension +
|
|
||||||
' || echo "Couldn\'t find extension: ' +
|
|
||||||
extension +
|
extension +
|
||||||
'"\n';
|
'"\n';
|
||||||
} else {
|
} else {
|
||||||
console.log('Cannot find pecl extension: ' + extension);
|
// check if pecl extension exists
|
||||||
|
const http = new httpm.HttpClient('shivammathur/php-setup', [], {
|
||||||
|
allowRetries: true,
|
||||||
|
maxRetries: 2
|
||||||
|
});
|
||||||
|
const response: httpm.HttpClientResponse = await 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';
|
linux += 'sudo apt autoremove -y';
|
||||||
@ -117,7 +126,6 @@ async function createScript(filename: string, version: string) {
|
|||||||
if (error) {
|
if (error) {
|
||||||
return console.log(error);
|
return console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('The file was saved!');
|
console.log('The file was saved!');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -127,6 +135,7 @@ Run the script
|
|||||||
*/
|
*/
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
|
// taking inputs
|
||||||
let version = process.env['php-version'];
|
let version = process.env['php-version'];
|
||||||
if (!version) {
|
if (!version) {
|
||||||
version = core.getInput('php-version', {required: true});
|
version = core.getInput('php-version', {required: true});
|
||||||
@ -142,7 +151,7 @@ async function run() {
|
|||||||
await addExtension(extension_csv, version);
|
await addExtension(extension_csv, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
let os_version = process.platform;
|
// check the os version and run the respective script
|
||||||
if (os_version == 'darwin') {
|
if (os_version == 'darwin') {
|
||||||
await createScript('darwin.sh', version);
|
await createScript('darwin.sh', version);
|
||||||
await exec('sudo chmod a+x ' + version + 'darwin.sh');
|
await exec('sudo chmod a+x ' + version + 'darwin.sh');
|
||||||
|
Loading…
Reference in New Issue
Block a user