mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-07-02 21:23:17 +07:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
db44db4b97 | |||
601f50f55e | |||
e71c06a64f | |||
c5825452ec | |||
339c69c9a5 | |||
e4a37d0f16 | |||
a398f54da4 | |||
69f9b777e1 | |||
02867faba4 | |||
35b0788556 | |||
2484a27666 | |||
42de8649eb | |||
f6674883c6 | |||
738fa3dfee | |||
9616296853 | |||
b45c80e26a |
17
.github/workflows/workflow.yml
vendored
17
.github/workflows/workflow.yml
vendored
@ -21,10 +21,21 @@ jobs:
|
||||
- name: Installing NPM
|
||||
run: npm install
|
||||
|
||||
- name: Installing PHP
|
||||
- name: Installing PHP with extensions and custom config
|
||||
run: node lib/install.js
|
||||
env:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
extension-csv: "mbstring, curl, mysqli, json, xml, xdebug, pcov, phpdbg"
|
||||
- name: Testing
|
||||
extension-csv: "mbstring, xdebug, pcov" #optional
|
||||
ini-values-csv: "post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata" #optional
|
||||
|
||||
- name: Testing PHP version
|
||||
run: php -v
|
||||
- name: Testing Composer version
|
||||
run: composer -V
|
||||
- name: Testing Extensions
|
||||
run: php -m
|
||||
- name: Testing ini values
|
||||
run: |
|
||||
php -r "echo \"post_max_size: \" . ini_get('post_max_size') . \"\n\";"
|
||||
php -r "echo \"short_open_tag: \" . ini_get('short_open_tag') . \"\n\";"
|
||||
php -r "echo \"date.timezone: \" . ini_get('date.timezone') . \"\n\";"
|
||||
|
74
README.md
74
README.md
@ -1,34 +1,51 @@
|
||||
# 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, php.ini configuration 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
|
||||
- 7.4 `7.4.0beta4` on `ubuntu`, and `7.4.0RC2` on `windows` and `macOS`
|
||||
|
||||
# Operating Systems Support
|
||||
- Linux (ubuntu-latest)
|
||||
- Windows (windows-latest)
|
||||
- MacOS (macOS-latest)
|
||||
**Note:** PHP 7.4 is currently in development, do not use in production.
|
||||
|
||||
# PHP Extension Support
|
||||
- On linux extensions which have the package in apt are installed.
|
||||
- On Windows and MacOS pecl extensions are installed.
|
||||
## OS Support
|
||||
|
||||
|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)
|
||||
Inputs supported by this GitHub Action.
|
||||
|
||||
- php-version
|
||||
- extension-csv (optional)
|
||||
- ini-values-csv (optional)
|
||||
|
||||
See [action.yml](action.yml) for more info
|
||||
|
||||
### Basic Usage
|
||||
|
||||
Basic:
|
||||
```yaml
|
||||
steps:
|
||||
- name: Checkout
|
||||
@ -37,7 +54,8 @@ steps:
|
||||
uses: shivammathur/setup-php@master
|
||||
with:
|
||||
php-version: 7.3
|
||||
extension-csv: mbstring, xdebug
|
||||
extension-csv: mbstring, xdebug #optional
|
||||
ini-values-csv: "post_max_size=256M, short_open_tag=On" #optional
|
||||
- name: Check PHP Version
|
||||
run: php -v
|
||||
- name: Check Composer Version
|
||||
@ -46,7 +64,8 @@ steps:
|
||||
run: php -m
|
||||
```
|
||||
|
||||
Matrix Testing:
|
||||
### Matrix Testing
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
run:
|
||||
@ -64,20 +83,35 @@ jobs:
|
||||
uses: shivammathur/setup-php@master
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
extension-csv: mbstring, xdebug
|
||||
extension-csv: mbstring, xdebug #optional
|
||||
ini-values-csv: "post_max_size=256M, short_open_tag=On" #optional
|
||||
- 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)
|
||||
- [phpbrew](https://github.com/phpbrew/phpbrew)
|
||||
|
||||
## 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)
|
||||
|
@ -11,6 +11,9 @@ inputs:
|
||||
extension-csv:
|
||||
description: '(Optional) Comma seperated list of PHP extensions to be installed.'
|
||||
required: false
|
||||
ini-values-csv:
|
||||
description: '(Optional) Custom values you want to set in php.ini'
|
||||
required: false
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/install.js'
|
||||
|
135
lib/install.js
135
lib/install.js
@ -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,28 +39,31 @@ 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* () {
|
||||
windows += `try {
|
||||
windows += `try {
|
||||
$${extension}_found = 0
|
||||
$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
|
||||
$${extension}_found = 1
|
||||
}
|
||||
} 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)
|
||||
${extension}_found=0
|
||||
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"
|
||||
${extension}_found=1
|
||||
fi\n`;
|
||||
linux += shell_code;
|
||||
darwin += shell_code;
|
||||
});
|
||||
linux += shell_code;
|
||||
darwin += shell_code;
|
||||
}
|
||||
/*
|
||||
Install and enable extensions
|
||||
@ -79,42 +83,83 @@ 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 +=
|
||||
'if [ $' +
|
||||
extension +
|
||||
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
|
||||
'_found -eq 0 ]; then sudo DEBIAN_FRONTEND=noninteractive apt install -y php' +
|
||||
version +
|
||||
'-' +
|
||||
extension +
|
||||
' }\n';
|
||||
darwin +=
|
||||
'pecl install ' +
|
||||
' || echo "Couldn\'t find extension php' +
|
||||
version +
|
||||
'-' +
|
||||
extension +
|
||||
' || echo "Couldn\'t find extension: ' +
|
||||
extension +
|
||||
'"\n';
|
||||
'"; fi\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) {
|
||||
let extension_version = 'stable';
|
||||
if (version == '7.4') {
|
||||
extension_version = 'alpha';
|
||||
}
|
||||
windows +=
|
||||
'if($' +
|
||||
extension +
|
||||
'_found -eq 0) { ' +
|
||||
'try { Install-PhpExtension ' +
|
||||
extension +
|
||||
' -MinimumStability ' +
|
||||
extension_version +
|
||||
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
|
||||
extension +
|
||||
' } }\n';
|
||||
darwin +=
|
||||
'if [ $' +
|
||||
extension +
|
||||
'_found -eq 0 ]; then sudo pecl install ' +
|
||||
extension +
|
||||
' || echo "Couldn\'t find extension: ' +
|
||||
extension +
|
||||
'"; fi\n';
|
||||
}
|
||||
else {
|
||||
console.log('Cannot find pecl extension: ' + extension);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
linux += 'sudo apt autoremove -y';
|
||||
linux += 'sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y';
|
||||
});
|
||||
}
|
||||
/*
|
||||
Add script to set custom ini values
|
||||
*/
|
||||
function addINIValues(ini_values_csv) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let ini_values = ini_values_csv
|
||||
.split(',')
|
||||
.map(function (ini_value) {
|
||||
return ini_value.trim();
|
||||
});
|
||||
yield asyncForEach(ini_values, function (ini_value) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// add script to set ini value
|
||||
linux += '\necho "' + ini_value + '" >> $ini_file';
|
||||
darwin += '\necho "' + ini_value + '" >> $ini_file';
|
||||
windows +=
|
||||
'\nAdd-Content C:\\tools\\php$version\\php.ini "' + ini_value + '"';
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
/*
|
||||
@ -146,20 +191,32 @@ 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 });
|
||||
}
|
||||
console.log('Input: ' + version);
|
||||
console.log('Version: ' + version);
|
||||
if (version == '7.4') {
|
||||
darwin = fs.readFileSync(path.join(__dirname, '../src/7.4.sh'), 'utf8');
|
||||
}
|
||||
let extension_csv = process.env['extension-csv'];
|
||||
if (!extension_csv) {
|
||||
extension_csv = core.getInput('extension-csv');
|
||||
}
|
||||
if (extension_csv) {
|
||||
console.log('Input: ' + extension_csv);
|
||||
console.log('Extensions: ' + extension_csv);
|
||||
yield addExtension(extension_csv, version);
|
||||
}
|
||||
let os_version = process.platform;
|
||||
let ini_values_csv = process.env['ini-values-csv'];
|
||||
if (!ini_values_csv) {
|
||||
ini_values_csv = core.getInput('ini-values-csv');
|
||||
}
|
||||
if (ini_values_csv) {
|
||||
console.log('INI Values: ' + ini_values_csv);
|
||||
yield addINIValues(ini_values_csv);
|
||||
}
|
||||
// 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
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-php",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-php",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.1",
|
||||
"private": false,
|
||||
"description": "Setup php action",
|
||||
"main": "lib/setup-php.js",
|
||||
|
50
src/7.4.sh
Normal file
50
src/7.4.sh
Normal file
@ -0,0 +1,50 @@
|
||||
brew fetch autoconf& brew fetch automake& brew fetch pcre& brew fetch libtool& brew fetch libpng& brew fetch webp& brew fetch jpeg& brew fetch freetype& brew fetch libxml2& brew fetch pkg-config& brew fetch krb5& brew fetch icu4c& brew fetch re2c& brew fetch bison& brew fetch libzip& brew fetch mcrypt& brew fetch zlib& brew fetch bzip2& brew fetch enchant
|
||||
brew install autoconf automake pcre libtool libpng webp jpeg freetype libxml2 pkg-config krb5 icu4c re2c bison libzip mcrypt zlib bzip2 enchant >> /dev/null
|
||||
brew link --force gettext
|
||||
brew link --force bison
|
||||
brew link --force openssl
|
||||
brew link --force libxml2
|
||||
brew link --force bzip2
|
||||
echo 'export PATH="/usr/local/opt/bzip2/bin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/krb5/bin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/krb5/sbin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/bzip2/bin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile
|
||||
echo 'export PATH="/Users/runner/.phpbrew/php/php-7.4.0RC1/bin:$PATH"' >> ~/.bash_profile
|
||||
source ~/.bash_profile >> /dev/null
|
||||
export LIBXML_LIBS="-L/usr/local/opt/libxml2/lib"
|
||||
export LIBXML_CFLAGS="-I/usr/local/opt/libxml2/include"
|
||||
export ENCHANT_LIBS="-L/usr/local/opt/enchant/lib"
|
||||
export ENCHANT_CFLAGS="-I/usr/local/opt/enchant/include"
|
||||
export FFI_LIBS="-L/usr/local/opt/libffi/lib"
|
||||
export FFI_CFLAGS="-I/usr/local/opt/libffi/include"
|
||||
export ICU_LIBS="-L/usr/local/opt/icu4c/lib"
|
||||
export ICU_CFLAGS="-I/usr/local/opt/icu4c/include"
|
||||
export KERBEROS_LIBS="-L/usr/local/opt/krb5/lib"
|
||||
export KERBEROS_CFLAGS="-I/usr/local/opt/krb5/include"
|
||||
export OPENSSL_LIBS="-L/usr/local/opt/openssl/lib"
|
||||
export OPENSSL_CFLAGS="-I/usr/local/opt/openssl/include"
|
||||
export READLINE_LIBS="-L/usr/local/opt/readline/lib"
|
||||
export READLINE_CFLAGS="-I/usr/local/opt/readline/include"
|
||||
export BZIP2_LIBS="-L/usr/local/opt/bzip2/lib"
|
||||
export BZIP2_CFLAGS="-I/usr/local/opt/bzip2/include"
|
||||
export PKG_CONFIG_PATH="/usr/local/opt/krb5/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/obzip2pt/libffi/lib/pkgconfig:/usr/local/opt/openssl@1.1/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig:/usr/local/opt/libxml2/lib/pkgconfig:/usr/local/opt/krb5/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig:/usr/local/opt/libxml2/lib/pkgconfig"
|
||||
cd ~
|
||||
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
|
||||
chmod +x ./phpbrew
|
||||
sudo mv phpbrew /usr/local/bin/phpbrew
|
||||
sudo mkdir -p /opt/phpbrew
|
||||
phpbrew init --root=/opt/phpbrew
|
||||
echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
phpbrew install -j 10 7.4.0RC2 +default +bz2="$(brew --prefix bzip2)" +zlib="$(brew --prefix zlib)" -openssl -- --with-libxml
|
||||
phpbrew switch php-7.4.0RC2 >> /dev/null
|
||||
sudo mkdir -p /usr/local/bin
|
||||
sudo ln -sf /Users/runner/.phpbrew/php/php-7.4.0RC2/bin/php /usr/local/bin/php
|
||||
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
sudo chmod 777 $ini_file
|
||||
brew install composer
|
@ -1,12 +1,18 @@
|
||||
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
|
||||
version=$(php-config --version | cut -c 1-3)
|
||||
if [ "$version" != "$1" ]; then
|
||||
brew tap exolnet/homebrew-deprecated;
|
||||
brew unlink php;
|
||||
brew install php@$1;
|
||||
brew link --force --overwrite php@$1;
|
||||
else
|
||||
sudo cp /etc/php.ini.default /etc/php.ini
|
||||
fi
|
||||
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
sudo chmod 777 $ini_file
|
||||
mkdir -p $(pecl config-get ext_dir)
|
||||
curl -sS https://getcomposer.org/installer | php
|
||||
chmod +x composer.phar
|
||||
mv composer.phar /usr/local/bin/composer
|
||||
composer global require hirak/prestissimo
|
||||
php -v
|
||||
composer -V
|
133
src/install.ts
133
src/install.ts
@ -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,24 +25,29 @@ 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) {
|
||||
function enableExtension(extension: string) {
|
||||
windows += `try {
|
||||
$${extension}_found = 0
|
||||
$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
|
||||
$${extension}_found = 1
|
||||
}
|
||||
} 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)
|
||||
${extension}_found=0
|
||||
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"
|
||||
${extension}_found=1
|
||||
fi\n`;
|
||||
linux += shell_code;
|
||||
darwin += shell_code;
|
||||
@ -63,42 +69,80 @@ 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 +=
|
||||
'if [ $' +
|
||||
extension +
|
||||
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
|
||||
'_found -eq 0 ]; then sudo DEBIAN_FRONTEND=noninteractive apt install -y php' +
|
||||
version +
|
||||
'-' +
|
||||
extension +
|
||||
' }\n';
|
||||
darwin +=
|
||||
'pecl install ' +
|
||||
' || echo "Couldn\'t find extension php' +
|
||||
version +
|
||||
'-' +
|
||||
extension +
|
||||
' || echo "Couldn\'t find extension: ' +
|
||||
extension +
|
||||
'"\n';
|
||||
'"; fi\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) {
|
||||
let extension_version = 'stable';
|
||||
if (version == '7.4') {
|
||||
extension_version = 'alpha';
|
||||
}
|
||||
windows +=
|
||||
'if($' +
|
||||
extension +
|
||||
'_found -eq 0) { ' +
|
||||
'try { Install-PhpExtension ' +
|
||||
extension +
|
||||
' -MinimumStability ' +
|
||||
extension_version +
|
||||
' } catch [Exception] { echo $_; echo "Could not install extension: "' +
|
||||
extension +
|
||||
' } }\n';
|
||||
darwin +=
|
||||
'if [ $' +
|
||||
extension +
|
||||
'_found -eq 0 ]; then sudo pecl install ' +
|
||||
extension +
|
||||
' || echo "Couldn\'t find extension: ' +
|
||||
extension +
|
||||
'"; fi\n';
|
||||
} else {
|
||||
console.log('Cannot find pecl extension: ' + extension);
|
||||
}
|
||||
}
|
||||
});
|
||||
linux += 'sudo apt autoremove -y';
|
||||
linux += 'sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y';
|
||||
}
|
||||
|
||||
/*
|
||||
Add script to set custom ini values
|
||||
*/
|
||||
async function addINIValues(ini_values_csv: string) {
|
||||
let ini_values: any = ini_values_csv
|
||||
.split(',')
|
||||
.map(function(ini_value: string) {
|
||||
return ini_value.trim();
|
||||
});
|
||||
await asyncForEach(ini_values, async function(ini_value: string) {
|
||||
// add script to set ini value
|
||||
linux += '\necho "' + ini_value + '" >> $ini_file';
|
||||
darwin += '\necho "' + ini_value + '" >> $ini_file';
|
||||
windows +=
|
||||
'\nAdd-Content C:\\tools\\php$version\\php.ini "' + ini_value + '"';
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
@ -117,7 +161,6 @@ async function createScript(filename: string, version: string) {
|
||||
if (error) {
|
||||
return console.log(error);
|
||||
}
|
||||
|
||||
console.log('The file was saved!');
|
||||
});
|
||||
}
|
||||
@ -127,22 +170,36 @@ Run the script
|
||||
*/
|
||||
async function run() {
|
||||
try {
|
||||
// taking inputs
|
||||
let version = process.env['php-version'];
|
||||
if (!version) {
|
||||
version = core.getInput('php-version', {required: true});
|
||||
}
|
||||
console.log('Input: ' + version);
|
||||
console.log('Version: ' + version);
|
||||
|
||||
if (version == '7.4') {
|
||||
darwin = fs.readFileSync(path.join(__dirname, '../src/7.4.sh'), 'utf8');
|
||||
}
|
||||
|
||||
let extension_csv = process.env['extension-csv'];
|
||||
if (!extension_csv) {
|
||||
extension_csv = core.getInput('extension-csv');
|
||||
}
|
||||
if (extension_csv) {
|
||||
console.log('Input: ' + extension_csv);
|
||||
console.log('Extensions: ' + extension_csv);
|
||||
await addExtension(extension_csv, version);
|
||||
}
|
||||
|
||||
let os_version = process.platform;
|
||||
let ini_values_csv = process.env['ini-values-csv'];
|
||||
if (!ini_values_csv) {
|
||||
ini_values_csv = core.getInput('ini-values-csv');
|
||||
}
|
||||
if (ini_values_csv) {
|
||||
console.log('INI Values: ' + ini_values_csv);
|
||||
await addINIValues(ini_values_csv);
|
||||
}
|
||||
|
||||
// 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');
|
||||
|
29
src/linux.sh
29
src/linux.sh
@ -1,10 +1,25 @@
|
||||
sudo add-apt-repository ppa:ondrej/php -y
|
||||
sudo apt update -y
|
||||
version=$(php-config --version | cut -c 1-3)
|
||||
if [ "$version" != "$1" ]; then
|
||||
if [ ! -e "/usr/bin/php$1" ]; then
|
||||
sudo DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt update -y
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt install -y php$1 curl;
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt autoremove -y;
|
||||
fi
|
||||
for tool in php phar phar.phar php-cgi php-config phpize; do
|
||||
if [ -e "/usr/bin/$tool$1" ]; then
|
||||
sudo update-alternatives --set $tool /usr/bin/$tool$1;
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ ! -e "/usr/bin/composer" ]; then
|
||||
sudo curl -s https://getcomposer.org/installer | php;
|
||||
sudo mv composer.phar /usr/local/bin/composer;
|
||||
fi
|
||||
composer global require hirak/prestissimo
|
||||
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
||||
sudo chmod 777 $ini_file
|
||||
sudo mkdir -p /run/php
|
||||
sudo apt install -y php$1 curl
|
||||
sudo apt autoremove -y
|
||||
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
|
@ -2,31 +2,45 @@ param (
|
||||
[Parameter(Mandatory=$true)][string]$version = "7.3"
|
||||
)
|
||||
|
||||
if($version -eq '7.4') {
|
||||
$version = '7.4RC'
|
||||
}
|
||||
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
|
||||
}
|
||||
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-production -Destination C:\tools\php$version\php.ini -Force
|
||||
Add-Content C:\tools\php$version\php.ini "date.timezone = 'UTC'"
|
||||
Set-PhpIniKey extension_dir C:\tools\php$version\ext
|
||||
Enable-PhpExtension openssl
|
||||
|
||||
$installed = php -v | grep ^PHP | cut -c 5-7
|
||||
echo $installed
|
||||
echo $version
|
||||
if($installed -ne $version) {
|
||||
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
|
||||
}
|
||||
|
||||
echo "Installing PHP"
|
||||
Uninstall-Php C:\tools\php
|
||||
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -Path C:\tools\php$version -TimeZone UTC -InitialPhpIni Production
|
||||
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"
|
||||
Add-Content C:\tools\php$version\php.ini "date.timezone = 'UTC'"
|
||||
Set-PhpIniKey extension_dir C:\tools\php$version\ext
|
||||
if($version -lt '7.4') {
|
||||
Enable-PhpExtension openssl
|
||||
} else {
|
||||
Add-Content C:\tools\php$version\php.ini "extension=php_openssl.dll"
|
||||
}
|
||||
}
|
||||
|
||||
echo "Installing Composer"
|
||||
Install-Composer -Scope System -Path C:\tools\php
|
||||
php -v
|
||||
|
Reference in New Issue
Block a user