Compare commits

..

7 Commits
1.1.0 ... 1.1.2

Author SHA1 Message Date
35b0788556 Bump version to 1.1.2 2019-09-09 04:55:53 +05:30
2484a27666 Merge branch 'develop' 2019-09-09 04:30:21 +05:30
42de8649eb Fix script to enable extensions 2019-09-09 04:09:41 +05:30
f6674883c6 Update README to add more info about OS support 2019-09-09 01:13:47 +05:30
738fa3dfee Update README to add more info about OS support 2019-09-09 00:58:00 +05:30
9616296853 Improve README.md (#6)
* Improve README.md
2019-09-08 12:53:33 +05:30
b45c80e26a Fix command in matrix testing snippet 2019-09-08 09:49:23 +05:30
5 changed files with 126 additions and 85 deletions

View File

@ -1,34 +1,42 @@
# setup-php # Setup PHP in GitHub Actions
<p align="left"> <p align="left">
<a href="https://github.com/shivammathur/setup-php"><img alt="GitHub Actions status" src="https://github.com/shivammathur/setup-php/workflows/Main%20workflow/badge.svg"></a> <a href="https://github.com/shivammathur/setup-php"><img alt="GitHub Actions status" src="https://github.com/shivammathur/setup-php/workflows/Main%20workflow/badge.svg"></a>
<a href="https://github.com/shivammathur/setup-php/blob/master/LICENSE"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg"></a>
</p> </p>
This action sets up a php environment along with composer and required PHP extensions on multiple platforms for use in github actions. [GitHub Action](https://github.com/features/actions) to install PHP with required extensions and composer. This action can be added as a step in your action workflow and it will setup the PHP environment you need to test your application. Refer to [Usage](#usage) section to see how to use this.
# PHP Version Support ## PHP Versions Support
- 5.6 - 5.6
- 7.0 - 7.0
- 7.1 - 7.1
- 7.2 - 7.2
- 7.3 - 7.3
# Operating Systems Support ## OS Support
- Linux (ubuntu-latest)
- Windows (windows-latest)
- MacOS (macOS-latest)
# PHP Extension Support |Virtual environment|matrix.operating-system|
- On linux extensions which have the package in apt are installed. |--- |--- |
- On Windows and MacOS pecl extensions are installed. |Windows Server 2019|`windows-latest` or `windows-2019`|
|Windows Server 2016 R2|`windows-2016`|
|Ubuntu 18.04|`ubuntu-latest` or `ubuntu-18.04`|
|Ubuntu 16.04|`ubuntu-16.04`|
|macOS X Mojave 10.14|`macOS-latest` or `macOS-10.14`|
## PHP Extension Support
- On `ubuntu` extensions which have the package in apt are installed.
- On `windows` and `macOS` PECL extensions are installed.
- Extensions which are installed along with PHP if specified are enabled. - Extensions which are installed along with PHP if specified are enabled.
- Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interruped. - Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interruped.
# Usage ## Usage
See [action.yml](action.yml) See [action.yml](action.yml) for inputs this action supports.
### Basic
Basic:
```yaml ```yaml
steps: steps:
- name: Checkout - name: Checkout
@ -46,7 +54,8 @@ steps:
run: php -m run: php -m
``` ```
Matrix Testing: ### Matrix Testing
```yaml ```yaml
jobs: jobs:
run: run:
@ -68,16 +77,29 @@ jobs:
- name: Check PHP Version - name: Check PHP Version
run: php -v run: php -v
- name: Check Composer Version - name: Check Composer Version
run: php -m run: composer -V
- name: Check PHP Extensions - name: Check PHP Extensions
run: php -m run: php -m
``` ```
# License ## License
The scripts and documentation in this project are released under the [MIT License](LICENSE) The scripts and documentation in this project are released under the [MIT License](LICENSE)
# Contributions ## Contributions
Contributions are welcome! See [Contributor's Guide](docs/contributors.md) Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
## This action uses the following works
- [powershell-phpmanager](https://github.com/mlocati/powershell-phpmanager)
- [Homebrew](https://brew.sh/)
- [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php)
- [exolnet/homebrew-deprecated](https://github.com/eXolnet/homebrew-deprecated)
## Further Reading
- [About GitHub Actions](https://github.com/features/actions)
- [GitHub Actions Syntax](https://help.github.com/en/articles/workflow-syntax-for-github-actions)
- [Other Awesome Actions](https://github.com/sdras/awesome-actions)

View File

@ -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');

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "setup-php", "name": "setup-php",
"version": "1.0.0", "version": "1.1.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "setup-php", "name": "setup-php",
"version": "1.0.0", "version": "1.1.2",
"private": false, "private": false,
"description": "Setup php action", "description": "Setup php action",
"main": "lib/setup-php.js", "main": "lib/setup-php.js",

View File

@ -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');