Merge pull request #173 from shivammathur/develop

1.8.2
This commit is contained in:
Shivam Mathur 2020-02-03 04:26:49 +05:30 committed by GitHub
commit d9cf6f5ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1655 additions and 2539 deletions

View File

@ -74,7 +74,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
These tools can be setup globally using the `tools` input.
`codeception`, `composer`, `composer-prefetcher`, `deployer`, `pecl`, `phinx`, `phive`, `phpcbf`, `phpcpd`, `php-config`, `php-cs-fixer`, `phpcs`, `phpize`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `psalm`, `symfony`
`codeception`, `composer`, `composer-prefetcher`, `cs2pr`, `deployer`, `pecl`, `phinx`, `phive`, `phpcbf`, `phpcpd`, `php-config`, `php-cs-fixer`, `phpcs`, `phpize`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `psalm`, `symfony`
```yaml
uses: shivammathur/setup-php@v1
@ -115,7 +115,7 @@ with:
### PCOV
Specify `coverage: pcov` to use `PCOV`.
Specify `coverage: pcov` to use `PCOV` and disable `Xdebug`.
It is much faster than `Xdebug`.
`PCOV` needs `PHP >= 7.1`.
If your source code directory is other than `src`, `lib` or, `app`, specify `pcov.directory` using the `ini-values` input.
@ -281,6 +281,8 @@ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
### Problem Matchers
#### PHPUnit
You can setup problem matchers for your `PHPUnit` output by adding this step after the `setup-php` step. This will scan the logs for failing tests and surface that information prominently in the GitHub Actions UI by creating annotations and log file decorations.
```yaml
@ -288,6 +290,24 @@ You can setup problem matchers for your `PHPUnit` output by adding this step aft
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
```
#### Other tools
For tools that support `checkstyle` reporting like `phpstan`, `psalm`, `php-cs-fixer` and `phpcs` you can use `cs2pr` to annotate your code.
For examples refer to [cs2pr documentation](https://github.com/staabm/annotate-pull-request-from-checkstyle).
> Here is an example with `phpstan`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: '7.4'
tools: cs2pr, phpstan
- name: PHPStan
run: phpstan analyse src --error-format=checkstyle | cs2pr
```
### Examples
Examples for setting up this GitHub Action with different PHP Frameworks/Packages.

View File

@ -27,7 +27,7 @@ describe('Extension tests', () => {
it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension(
'xdebug, pcov, ast-beta',
'xdebug, pcov, ast-beta, xdebug-alpha',
'7.4',
'linux'
);
@ -35,7 +35,10 @@ describe('Extension tests', () => {
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov'
);
expect(linux).toContain('install_extension ast-beta');
expect(linux).toContain('add_unstable_extension ast beta extension');
expect(linux).toContain(
'add_unstable_extension xdebug alpha zend_extension'
);
linux = await extensions.addExtension('gearman', '7.0', 'linux');
expect(linux).toContain('gearman.sh 7.0');
@ -67,7 +70,7 @@ describe('Extension tests', () => {
);
expect(darwin).toContain('sudo pecl install -f xdebug');
expect(darwin).toContain('sudo pecl install -f pcov');
expect(darwin).toContain('install_extension ast-beta');
expect(darwin).toContain('add_unstable_extension ast beta extension');
darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin');
expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0');

View File

@ -96,13 +96,13 @@ describe('Tools tests', () => {
it('checking getUri', async () => {
expect(
await tools.getUri('tool', 'latest', 'releases', '', 'download')
await tools.getUri('tool', '.phar', 'latest', 'releases', '', 'download')
).toBe('releases/latest/download/tool.phar');
expect(
await tools.getUri('tool', '1.2.3', 'releases', '', 'download')
await tools.getUri('tool', '.phar', '1.2.3', 'releases', '', 'download')
).toBe('releases/download/1.2.3/tool.phar');
expect(
await tools.getUri('tool', '1.2.3', 'releases', 'v', 'download')
await tools.getUri('tool', '.phar', '1.2.3', 'releases', 'v', 'download')
).toBe('releases/download/v1.2.3/tool.phar');
});
@ -325,13 +325,16 @@ describe('Tools tests', () => {
it('checking addTools on linux', async () => {
const script: string = await tools.addTools(
'php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony',
'cs2pr, php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony',
'7.4',
'linux'
);
expect(script).toContain(
'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
);
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
);
expect(script).toContain(
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer'
);
@ -356,13 +359,16 @@ describe('Tools tests', () => {
});
it('checking addTools on darwin', async () => {
const script: string = await tools.addTools(
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3',
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3',
'7.4',
'darwin'
);
expect(script).toContain(
'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
);
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr'
);
expect(script).toContain(
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs'
);
@ -396,13 +402,16 @@ describe('Tools tests', () => {
});
it('checking addTools on windows', async () => {
const script: string = await tools.addTools(
'codeception, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exit',
'codeception, cs2pr, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exit',
'7.4',
'win32'
);
expect(script).toContain(
'Add-Tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
);
expect(script).toContain(
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
);
expect(script).toContain(
'Add-Tool https://deployer.org/deployer.phar deployer'
);

48
dist/index.js vendored
View File

@ -1684,13 +1684,15 @@ exports.parseTool = parseTool;
* @param version_prefix
* @param verb
*/
function getUri(tool, version, prefix, version_prefix, verb) {
function getUri(tool, extension, version, prefix, version_prefix, verb) {
return __awaiter(this, void 0, void 0, function* () {
switch (version) {
case 'latest':
return [prefix, version, verb, tool + '.phar'].filter(Boolean).join('/');
return [prefix, version, verb, tool + extension]
.filter(Boolean)
.join('/');
default:
return [prefix, verb, version_prefix + version, tool + '.phar']
return [prefix, verb, version_prefix + version, tool + extension]
.filter(Boolean)
.join('/');
}
@ -1940,12 +1942,17 @@ function addTools(tools_csv, php_version, os_version) {
const tool = tool_data.name;
const version = tool_data.version;
const github = 'https://github.com/';
let uri = yield getUri(tool, version, 'releases', '', 'download');
let uri = yield getUri(tool, '.phar', version, 'releases', '', 'download');
script += '\n';
let url = '';
switch (tool) {
case 'cs2pr':
uri = yield getUri(tool, '', version, 'releases', '', 'download');
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
script += yield addArchive(tool, version, url, os_version);
break;
case 'php-cs-fixer':
uri = yield getUri(tool, version, 'releases', 'v', 'download');
uri = yield getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += yield addArchive(tool, version, url, os_version);
break;
@ -2642,12 +2649,20 @@ function addExtensionDarwin(extension_csv, version, pipe) {
return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
const version_extension = version + extension;
const [extension_name, stability] = extension.split('-');
const prefix = yield utils.getExtensionPrefix(extension_name);
let install_command = '';
switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
prefix;
return;
case /5\.6xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe;
break;
@ -2748,12 +2763,20 @@ function addExtensionLinux(extension_csv, version, pipe) {
return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
const version_extension = version + extension;
const [extension_name, stability] = extension.split('-');
const prefix = yield utils.getExtensionPrefix(extension_name);
let install_command = '';
switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
prefix;
return;
// match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command =
@ -2791,12 +2814,7 @@ function addExtensionLinux(extension_csv, version, pipe) {
break;
}
script +=
'\nadd_extension ' +
extension +
' "' +
install_command +
'" ' +
(yield utils.getExtensionPrefix(extension));
'\nadd_extension ' + extension + ' "' + install_command + '" ' + prefix;
});
});
return script;

3717
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "setup-php",
"version": "1.8.1",
"version": "1.8.2",
"private": false,
"description": "Setup PHP for use with GitHub Actions",
"main": "dist/index.js",
@ -24,28 +24,28 @@
"author": "shivammathur",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/exec": "^1.0.2",
"@actions/io": "^1.0.1",
"@actions/core": "^1.2.2",
"@actions/exec": "^1.0.3",
"@actions/io": "^1.0.2",
"fs": "0.0.1-security"
},
"devDependencies": {
"@types/jest": "^24.0.21",
"@types/node": "^12.12.16",
"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"@types/jest": "^25.1.1",
"@types/node": "^13.7.0",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"@typescript-eslint/parser": "^2.18.0",
"@zeit/ncc": "^0.21.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^23.0.3",
"eslint-plugin-prettier": "^3.1.1",
"husky": "^3.0.9",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"prettier": "^1.17.1",
"ts-jest": "^24.1.0",
"typescript": "^3.7.3"
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-prettier": "^3.1.2",
"husky": "^4.2.1",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"prettier": "^1.19.1",
"ts-jest": "^25.1.0",
"typescript": "^3.7.5"
},
"husky": {
"skipCI": true,

View File

@ -18,12 +18,20 @@ export async function addExtensionDarwin(
await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase();
const version_extension: string = version + extension;
const [extension_name, stability]: string[] = extension.split('-');
const prefix = await utils.getExtensionPrefix(extension_name);
let install_command = '';
switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
prefix;
return;
case /5\.6xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe;
break;
@ -124,12 +132,20 @@ export async function addExtensionLinux(
await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase();
const version_extension: string = version + extension;
const [extension_name, stability]: string[] = extension.split('-');
const prefix = await utils.getExtensionPrefix(extension_name);
let install_command = '';
switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
prefix;
return;
// match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command =
@ -167,12 +183,7 @@ export async function addExtensionLinux(
break;
}
script +=
'\nadd_extension ' +
extension +
' "' +
install_command +
'" ' +
(await utils.getExtensionPrefix(extension));
'\nadd_extension ' + extension + ' "' + install_command + '" ' + prefix;
});
return script;
}

View File

@ -16,6 +16,13 @@ add_log() {
fi
}
# Function to remove extensions
remove_extension() {
extension=$1
sudo sed -i '' "/$extension/d" "$ini_file"
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
}
# Function to setup extensions
add_extension() {
extension=$1
@ -26,26 +33,49 @@ add_extension() {
elif php -m | grep -i -q -w "$extension"; then
add_log "$tick" "$extension" "Enabled"
elif ! php -m | grep -i -q -w "$extension"; then
(eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") ||
(eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
fi
}
# Function to force install extensions using PECL
install_extension() {
# Fuction to get the PECL version
get_pecl_version() {
extension=$1
extension_name="$(echo "$extension" | cut -d'-' -f 1)"
sudo sed -i "/$extension_name/d" "$ini_file"
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension_name"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension_name".so >/dev/null 2>&1
sudo pecl install -f "$extension" >/dev/null 2>&1
stability=$2
pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl -q -sSL "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eo "(\d*\.\d*\.\d*$stability\d*)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "(\d*\.\d*\.\d*)")
fi
echo "$pecl_version"
}
# Function to remove extensions
remove_extension() {
# Function to pre-release extensions using PECL
add_unstable_extension() {
extension=$1
sudo sed -i '' "/$1/d" "$ini_file"
sudo rm -rf "$ext_dir"/"$1".so >/dev/null 2>&1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then
extension_version=$(php -d="$prefix=$extension" -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
else
remove_extension "$extension"
add_extension "$extension" "sudo pecl install -f $extension-$pecl_version" "$prefix"
fi
elif php -m | grep -i -q -w "$extension"; then
extension_version=$(php -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
add_log "$tick" "$extension" "Enabled"
else
remove_extension "$extension"
add_extension "$extension" "sudo pecl install -f $extension-$pecl_version" "$prefix"
fi
else
add_extension "$extension" "sudo pecl install -f $extension-$pecl_version" "$prefix"
fi
}
# Function to setup a remote tool
@ -57,40 +87,52 @@ add_tool() {
composer -q global config process-timeout 0
add_log "$tick" "$tool" "Added"
else
if [ ! -e /usr/local/bin/"$tool" ]; then
rm -rf /usr/local/bin/"${tool:?}"
tool_path=/usr/local/bin/"$tool"
if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi
status_code=$(sudo curl -s -w "%{http_code}" -o /usr/local/bin/"$tool" -L "$url")
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then
sudo chmod a+x /usr/local/bin/"$tool"
sudo chmod a+x "$tool_path"
if [ "$tool" = "phive" ]; then
add_extension curl >/dev/null 2>&1
add_extension mbstring >/dev/null 2>&1
add_extension xml >/dev/null 2>&1
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path"
tr -d '\r' < "$tool_path" | sudo tee "$tool_path" >/dev/null 2>&1
fi
add_log "$tick" "$tool" "Added"
else
add_log "$cross" "$tool" "Could not setup $tool"
fi
fi
if [ "$tool" = "phive" ]; then
add_extension curl >/dev/null 2>&1
add_extension mbstring >/dev/null 2>&1
add_extension xml >/dev/null 2>&1
fi
}
# Function to add a tool using composer
add_composer_tool() {
tool=$1
release=$2
prefix=$3
(
composer global require "$prefix$release" >/dev/null 2>&1 && \
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \
composer global require "$prefix$release" >/dev/null 2>&1 &&
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" &&
add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool"
}
# Function to configure PECL
configure_pecl() {
for tool in pear pecl; do
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
done
}
# Function to log PECL, it is installed along with PHP
add_pecl() {
sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1
sudo pear config-set auto_discover 1 >/dev/null 2>&1
sudo pear channel-update pear.php.net >/dev/null 2>&1
sudo pecl channel-update pecl.php.net >/dev/null 2>&1
add_log "$tick" "PECL" "Added"
}
@ -117,3 +159,4 @@ sudo chmod 777 "$ini_file"
mkdir -p "$(pecl config-get ext_dir)"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
add_log "$tick" "PHP" "Installed PHP $semver"
configure_pecl

View File

@ -0,0 +1,15 @@
php_h="https://raw.githubusercontent.com/php/php-src/PHP-$2/main/php.h"
os=$(uname -s)
if [ "$os" = "Linux" ]; then
apiv=$(curl -sSL --retry 5 "$php_h" | grep "PHP_API_VERSION" | cut -d' ' -f 3)
dir="/usr/lib/php/$apiv"
sudo mkdir -p "$dir" && sudo chown -R "$USER":"$(id -g -n)" /usr/lib/php
elif [ "$os" = "Darwin" ]; then
apiv=$(curl -sSL --retry 5 "$php_h" | grep "PHP_API_VERSION" | cut -d' ' -f 3)
dir="/usr/local/lib/php/pecl/$apiv"
else
dir='C:\\tools\\php\\ext'
fi
hash=$(echo -n "$1" | openssl dgst -sha256 | cut -d ' ' -f 2)
echo "::set-output name=ext_dir::$dir"
echo "::set-output name=ext_hash::$hash"

View File

@ -22,7 +22,7 @@ Function Install-Phalcon() {
$zip_file = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1
New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll > $null 2>&1
Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll" -Destination "$ext_dir\php_phalcon.dll"
Enable-PhpExtension -Extension phalcon -Path $php_dir
}
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Installed and enabled"

View File

@ -27,14 +27,7 @@ install_phalcon() {
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
}
# Function to remove an extensions
remove_extension() {
extension=$1
sudo sed -i "/$extension/d" "$ini_file"
rm -rf "$ext_dir/$extension.so"
}
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ini_file="/etc/php/$2/cli/conf.d/50-phalcon.ini"
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
extension_major_version=$(echo "$1" | grep -i -Po '\d')
@ -44,18 +37,16 @@ cross="✗"
if [ "$extension_major_version" = "4" ]; then
if [ -e "$ext_dir/psr.so" ]; then
echo "extension=psr" >>"$ini_file"
echo "extension=psr.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
fi
if [ -e "$ext_dir/phalcon.so" ]; then
if php -m | grep -i -q -w psr; then
echo "extension=phalcon" >>"$ini_file"
phalcon_version=$(php -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
remove_extension "psr" >/dev/null 2>&1
remove_extension "phalcon" >/dev/null 2>&1
install_phalcon "$1" "$2"
else
echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_log "$tick" "$1" "Enabled"
fi
else
@ -68,12 +59,11 @@ fi
if [ "$extension_major_version" = "3" ]; then
if [ -e "$ext_dir/phalcon.so" ]; then
echo "extension=phalcon" >>"$ini_file"
phalcon_version=$(php -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
phalcon_version=$(php -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
remove_extension "phalcon" >/dev/null 2>&1
install_phalcon "$1" "$2"
else
echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_log "$tick" "$1" "Enabled"
fi
else

View File

@ -6,13 +6,8 @@ ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
if [ -e "$ext_dir/psr.so" ] && [ -e "$ext_dir/phalcon.so" ]; then
echo "extension=psr" >>"$ini_file"
echo "extension=phalcon" >>"$ini_file"
phalcon_semver=$(php -r "echo phpversion('phalcon');")
phalcon_version=$(echo "$phalcon_semver" | cut -d'.' -f 1)
phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major" ]; then
sudo sed -i '' "/psr/d" "$ini_file"
sudo sed -i '' "/phalcon/d" "$ini_file"
rm -rf "$ext_dir"/psr.so
rm -rf "$ext_dir"/phalcon.so
brew tap shivammathur/homebrew-phalcon
brew install phalcon@"$php_version"_"$extension_major"
fi

View File

@ -27,20 +27,35 @@ update_ppa() {
configure_pecl() {
if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then
for tool in pear pecl; do
sudo $tool config-set php_ini "$ini_file" >/dev/null 2>&1
sudo $tool config-set auto_discover 1 >/dev/null 2>&1
sudo $tool channel-update $tool.php.net >/dev/null 2>&1
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
done
pecl_config="true"
fi
}
# Fuction to get the PECL version
get_pecl_version() {
extension=$1
stability=$2
pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl -q -sSL "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Po "(\d*\.\d*\.\d*$stability\d*)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Po "(\d*\.\d*\.\d*)")
fi
echo "$pecl_version"
}
# Function to setup extensions
add_extension() {
extension=$1
install_command=$2
prefix=$3
if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then
# shellcheck disable=SC2046
$apt_install $(apt-cache depends php"$version"-"$extension" | awk '/Depends:/{print$2}') >/dev/null 2>&1
echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
elif php -m | grep -i -q -w "$extension"; then
add_log "$tick" "$extension" "Enabled"
@ -53,25 +68,57 @@ add_extension() {
sudo chmod 777 "$ini_file"
}
# Function to force install extensions using PECL
install_extension() {
# Function to delete extensions
delete_extension() {
extension=$1
extension_name="$(echo "$extension" | cut -d'-' -f 1)"
sudo sed -i "/$extension_name/d" "$ini_file"
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension_name"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension_name".so >/dev/null 2>&1
sudo pecl install -f "$extension" >/dev/null 2>&1
sudo sed -i "/$extension/d" "$ini_file"
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
}
# Function to remove extensions
# Function to disable and delete extensions
remove_extension() {
extension=$1
if [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then
sudo phpdismod -v "$version" "$extension"
fi
sudo sed -i "/$extension/d" "$ini_file"
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
delete_extension "$extension"
}
# Function to install a PECL version
add_pecl_extension() {
extension=$1
pecl_version=$2
(sudo pecl install -f "$extension-$pecl_version" >/dev/null 2>&1 &&
add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension-$pecl_version on PHP $semver"
}
# Function to pre-release extensions using PECL
add_unstable_extension() {
extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then
extension_version=$(php -d="$prefix=$extension" -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
else
delete_extension "$extension"
add_pecl_extension "$extension" "$pecl_version"
fi
elif php -m | grep -i -q -w "$extension"; then
extension_version=$(php -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
add_log "$tick" "$extension" "Enabled"
else
delete_extension "$extension"
add_pecl_extension "$extension" "$pecl_version"
fi
else
add_pecl_extension "$extension" "$pecl_version"
fi
}
# Function to update extension
@ -93,33 +140,36 @@ update_extension() {
add_tool() {
url=$1
tool=$2
if [ ! -e /usr/local/bin/"$tool" ]; then
rm -rf /usr/local/bin/"${tool:?}"
tool_path=/usr/local/bin/"$tool"
if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi
status_code=$(sudo curl -s -w "%{http_code}" -o /usr/local/bin/"$tool" -L "$url")
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then
sudo chmod a+x /usr/local/bin/"$tool"
add_log "$tick" "$tool" "Added"
else
add_log "$cross" "$tool" "Could not setup $tool"
fi
sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then
composer -q global config process-timeout 0
fi
if [ "$tool" = "phive" ]; then
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path"
elif [ "$tool" = "phive" ]; then
add_extension curl >/dev/null 2>&1
add_extension mbstring >/dev/null 2>&1
add_extension xml >/dev/null 2>&1
fi
add_log "$tick" "$tool" "Added"
else
add_log "$cross" "$tool" "Could not setup $tool"
fi
}
# Function to setup a tool using composer
add_composer_tool() {
tool=$1
release=$2
prefix=$3
(
composer global require "$prefix$release" >/dev/null 2>&1 && \
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \
composer global require "$prefix$release" >/dev/null 2>&1 &&
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" &&
add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool"
}
@ -150,7 +200,9 @@ setup_master() {
# Function to setup PECL
add_pecl() {
add_devtools
if [ ! -e /usr/bin/pecl ]; then
$apt_install php-pear >/dev/null 2>&1
fi
configure_pecl
add_log "$tick" "PECL" "Added"
}
@ -172,7 +224,6 @@ pecl_config="false"
version=$1
apt_install="sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y"
existing_version=$(php-config --version | cut -c 1-3)
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
# Setup PHP
step_log "Setup PHP"
@ -182,9 +233,7 @@ sudo mkdir -p /run/php
if [ "$existing_version" != "$version" ]; then
if [ ! -e "/usr/bin/php$version" ]; then
update_ppa
if [ "$version" = "7.4" ]; then
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml php"$version"-phpdbg >/dev/null 2>&1
elif [ "$version" = "8.0" ]; then
if [ "$version" = "8.0" ]; then
setup_master
else
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1
@ -196,9 +245,10 @@ if [ "$existing_version" != "$version" ]; then
switch_version
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
if [ "$version" = "8.0" ]; then
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
else
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
fi
if [ "$status" != "switched" ]; then
@ -207,6 +257,7 @@ if [ "$existing_version" != "$version" ]; then
status="Switched to PHP $semver"
fi
else
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
status="PHP $semver Found"
fi

View File

@ -35,7 +35,7 @@ Function Add-Extension {
)
try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
if ($null -ne $extension_info -and $mininum_stability -eq 'stable') {
if ($null -ne $extension_info) {
switch ($extension_info.State) {
'Builtin' {
Add-Log $tick $extension "Enabled"
@ -51,13 +51,9 @@ Function Add-Extension {
}
else {
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
if($mininum_stability -ne 'stable') {
Add-Log $tick "$extension-$mininum_stability" "Installed and enabled"
} else {
Add-Log $tick $extension "Installed and enabled"
}
}
}
catch {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
@ -118,6 +114,9 @@ Function Add-Tool() {
Add-Extension mbstring >$null 2>&1
Add-Extension xml >$null 2>&1
}
if($tool -eq "cs2pr") {
(Get-Content $php_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $php_dir/cs2pr
}
if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
Add-Log $tick $tool "Added"
} else {

View File

@ -116,6 +116,7 @@ export async function parseTool(
*/
export async function getUri(
tool: string,
extension: string,
version: string,
prefix: string,
version_prefix: string,
@ -123,9 +124,11 @@ export async function getUri(
): Promise<string> {
switch (version) {
case 'latest':
return [prefix, version, verb, tool + '.phar'].filter(Boolean).join('/');
return [prefix, version, verb, tool + extension]
.filter(Boolean)
.join('/');
default:
return [prefix, verb, version_prefix + version, tool + '.phar']
return [prefix, verb, version_prefix + version, tool + extension]
.filter(Boolean)
.join('/');
}
@ -404,12 +407,24 @@ export async function addTools(
const tool: string = tool_data.name;
const version: string = tool_data.version;
const github = 'https://github.com/';
let uri: string = await getUri(tool, version, 'releases', '', 'download');
let uri: string = await getUri(
tool,
'.phar',
version,
'releases',
'',
'download'
);
script += '\n';
let url = '';
switch (tool) {
case 'cs2pr':
uri = await getUri(tool, '', version, 'releases', '', 'download');
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
script += await addArchive(tool, version, url, os_version);
break;
case 'php-cs-fixer':
uri = await getUri(tool, version, 'releases', 'v', 'download');
uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += await addArchive(tool, version, url, os_version);
break;

BIN
update.zip Normal file

Binary file not shown.