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">
<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>
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
- 7.0
- 7.1
- 7.2
- 7.3
# Operating Systems Support
- Linux (ubuntu-latest)
- Windows (windows-latest)
- MacOS (macOS-latest)
## OS Support
# PHP Extension Support
- On linux extensions which have the package in apt are installed.
- On Windows and MacOS pecl extensions are installed.
|Virtual environment|matrix.operating-system|
|--- |--- |
|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 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
steps:
- name: Checkout
@ -46,7 +54,8 @@ steps:
run: php -m
```
Matrix Testing:
### Matrix Testing
```yaml
jobs:
run:
@ -68,16 +77,29 @@ jobs:
- name: Check PHP Version
run: php -v
- name: Check Composer Version
run: php -m
run: composer -V
- name: Check PHP Extensions
run: php -m
```
# 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
*/
let os_version = process.platform;
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');
@ -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) {
return __awaiter(this, void 0, void 0, function* () {
@ -52,10 +53,11 @@ function enableExtension(extension) {
} catch [Exception] {
echo $_
}\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';}")
if [ "$enabled" == 'no' ] && [ test -f "$ext_dir/${extension}.so" ]; then
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*:\s*||"'
if [ "$enabled" = "no" ] && [ -e "$ext_dir/${extension}.so" ]; then
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'
echo "${extension} enabled"
fi\n`;
linux += shell_code;
darwin += shell_code;
@ -79,38 +81,45 @@ function addExtension(extension_csv, version) {
darwin += '\n';
yield asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () {
// add script to enable extension is already installed along with php
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 ' +
// else add script to attempt to install the extension
if (os_version == 'linux') {
linux +=
'sudo apt install -y php' +
version +
'-' +
extension +
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
extension +
' }\n';
darwin +=
'pecl install ' +
extension +
' || echo "Couldn\'t find extension: ' +
' || echo "Couldn\'t find extension php' +
version +
'-' +
extension +
'"\n';
}
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() {
return __awaiter(this, void 0, void 0, function* () {
try {
// taking inputs
let version = process.env['php-version'];
if (!version) {
version = core.getInput('php-version', { required: true });
@ -159,7 +169,7 @@ function run() {
console.log('Input: ' + extension_csv);
yield addExtension(extension_csv, version);
}
let os_version = process.platform;
// check the os version and run the respective script
if (os_version == 'darwin') {
yield createScript('darwin.sh', version);
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",
"version": "1.0.0",
"version": "1.1.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

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

View File

@ -7,6 +7,7 @@ import * as fs from 'fs';
/*
Read the scripts
*/
let os_version = process.platform;
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(
@ -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) {
windows += `try {
@ -38,10 +39,11 @@ async function enableExtension(extension: string) {
echo $_
}\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';}")
if [ "$enabled" == 'no' ] && [ test -f "$ext_dir/${extension}.so" ]; then
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*:\s*||"'
if [ "$enabled" = "no" ] && [ -e "$ext_dir/${extension}.so" ]; then
echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'
echo "${extension} enabled"
fi\n`;
linux += shell_code;
darwin += shell_code;
@ -63,39 +65,46 @@ async function addExtension(extension_csv: string, version: string) {
windows += '\n';
darwin += '\n';
await asyncForEach(extensions, async function(extension: string) {
// add script to enable extension is already installed along with php
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: httpm.HttpClientResponse = await http.get(
'https://pecl.php.net/package/' + extension
);
if (response.message.statusCode == 200) {
windows +=
'try { Install-PhpExtension ' +
// else add script to attempt to install the extension
if (os_version == 'linux') {
linux +=
'sudo apt install -y php' +
version +
'-' +
extension +
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
extension +
' }\n';
darwin +=
'pecl install ' +
extension +
' || echo "Couldn\'t find extension: ' +
' || echo "Couldn\'t find extension php' +
version +
'-' +
extension +
'"\n';
} 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';
@ -117,7 +126,6 @@ async function createScript(filename: string, version: string) {
if (error) {
return console.log(error);
}
console.log('The file was saved!');
});
}
@ -127,6 +135,7 @@ Run the script
*/
async function run() {
try {
// taking inputs
let version = process.env['php-version'];
if (!version) {
version = core.getInput('php-version', {required: true});
@ -142,7 +151,7 @@ async function run() {
await addExtension(extension_csv, version);
}
let os_version = process.platform;
// check the os version and run the respective script
if (os_version == 'darwin') {
await createScript('darwin.sh', version);
await exec('sudo chmod a+x ' + version + 'darwin.sh');