From 935e74fb40d61c80e726192a38e7f30aa75939f9 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 20 Dec 2019 18:29:05 +0530 Subject: [PATCH 01/11] Refactor scripts and fix reading php-version --- __tests__/install.test.ts | 26 ++++- dist/index.js | 2 +- src/install.ts | 2 +- src/scripts/darwin.sh | 72 ++++++-------- src/scripts/linux.sh | 204 +++++++++++++++++++++----------------- 5 files changed, 173 insertions(+), 133 deletions(-) diff --git a/__tests__/install.test.ts b/__tests__/install.test.ts index 9842a38e..b5daa8ae 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -32,7 +32,7 @@ jest.mock('../src/install', () => ({ async (): Promise => { const os_version: string = process.env['RUNNER_OS'] || ''; let version: string = process.env['php-version'] || ''; - version = version.length > 1 ? version : version + '.0'; + version = version.length > 1 ? version.slice(0, 3) : version + '.0'; let script = ''; switch (os_version) { case 'darwin': @@ -69,14 +69,14 @@ jest.mock('../src/install', () => ({ * @param coverage_driver */ function setEnv( - version: string, + version: string | number, os: string, extension_csv: string, ini_values_csv: string, coverage_driver: string, pecl: string ): void { - process.env['php-version'] = version; + process.env['php-version'] = version.toString(); process.env['RUNNER_OS'] = os; process.env['extensions'] = extension_csv; process.env['ini-values'] = ini_values_csv; @@ -150,4 +150,24 @@ describe('Install', () => { expect(script).toContain('set coverage driver'); expect(script).toContain('sh script.sh 7.3 ' + __dirname); }); + + it('Test malformed version inputs', async () => { + setEnv('7.4.1', 'darwin', '', '', '', ''); + // @ts-ignore + let script: string = await install.run(); + expect(script).toContain('initial script'); + expect(script).toContain('sh script.sh 7.4 ' + __dirname); + + setEnv(8.0, 'darwin', '', '', '', ''); + // @ts-ignore + script = await install.run(); + expect(script).toContain('initial script'); + expect(script).toContain('sh script.sh 8.0 ' + __dirname); + + setEnv(8, 'darwin', '', '', '', ''); + // @ts-ignore + script = await install.run(); + expect(script).toContain('initial script'); + expect(script).toContain('sh script.sh 8.0 ' + __dirname); + }); }); diff --git a/dist/index.js b/dist/index.js index eb724e3a..accea60c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1906,7 +1906,7 @@ function run() { try { const os_version = process.platform; let version = yield utils.getInput('php-version', true); - version = version.length > 1 ? version : version + '.0'; + version = version.length > 1 ? version.slice(0, 3) : version + '.0'; // check the os version and run the respective script let script_path = ''; switch (os_version) { diff --git a/src/install.ts b/src/install.ts index b36434d8..1d7fd741 100644 --- a/src/install.ts +++ b/src/install.ts @@ -49,7 +49,7 @@ export async function run(): Promise { try { const os_version: string = process.platform; let version: string = await utils.getInput('php-version', true); - version = version.length > 1 ? version : version + '.0'; + version = version.length > 1 ? version.slice(0, 3) : version + '.0'; // check the os version and run the respective script let script_path = ''; switch (os_version) { diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index f5f6934f..068e2141 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -1,11 +1,10 @@ -tick="✓" -cross="✗" - +# Function to log start of a operation step_log() { message=$1 printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message" } +# Function to log result of a operation add_log() { mark=$1 subject=$2 @@ -17,46 +16,16 @@ add_log() { fi } -get_extension_regex() { - extension=$1 - case $extension in - "opcache") - echo "^Zend\sOPcache$" - ;; - "xdebug") - echo "^Xdebug$" - ;; - *) - echo ^"$extension"$ - ;; - esac -} - -step_log "Setup PHP and Composer" -export HOMEBREW_NO_INSTALL_CLEANUP=TRUE -brew tap shivammathur/homebrew-php >/dev/null 2>&1 -brew install shivammathur/php/php@"$1" composer >/dev/null 2>&1 -brew link --force --overwrite php@"$1" >/dev/null 2>&1 -ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") -echo "date.timezone=UTC" >> "$ini_file" -ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") -sudo chmod 777 "$ini_file" -mkdir -p "$(pecl config-get ext_dir)" -composer global require hirak/prestissimo >/dev/null 2>&1 -semver=$(php -v | head -n 1 | cut -f 2 -d ' ') -add_log "$tick" "PHP" "Installed PHP $semver" -add_log "$tick" "Composer" "Installed" - +# Function to setup extensions add_extension() { extension=$1 install_command=$2 prefix=$3 - extension_regex="$(get_extension_regex "$extension")" - if ! php -m | grep -i -q "$extension_regex" && [ -e "$ext_dir/$extension.so" ]; then + if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" - elif php -m | grep -i -q "$extension_regex"; then + elif php -m | grep -i -q -w "$extension"; then add_log "$tick" "$extension" "Enabled" - elif ! php -m | grep -i -q "$extension_regex"; then + elif ! php -m | grep -i -q -w "$extension"; then exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null) if [ "$exists" = "200" ]; then ( @@ -64,9 +33,34 @@ add_extension() { add_log "$tick" "$extension" "Installed and enabled" ) || add_log "$cross" "$extension" "Could not install $extension on PHP $semver" else - if ! php -m | grep -i -q "$extension_regex"; then + if ! php -m | grep -i -q -w "$extension"; then add_log "$cross" "$extension" "Could not find $extension for PHP $semver on PECL" fi fi fi -} \ No newline at end of file +} + +# Function to setup PHP and composer +setup_php_and_composer() { + export HOMEBREW_NO_INSTALL_CLEANUP=TRUE + brew tap shivammathur/homebrew-php >/dev/null 2>&1 + brew install shivammathur/php/php@"$version" composer >/dev/null 2>&1 + brew link --force --overwrite php@"$version" >/dev/null 2>&1 +} + +# Variables +tick="✓" +cross="✗" +version=$1 + +# Setup PHP and composer +step_log "Setup PHP and Composer" +setup_php_and_composer +ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") +echo "date.timezone=UTC" >> "$ini_file" +ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") +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" +add_log "$tick" "Composer" "Installed" diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index 0e89a247..b18346c8 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -1,11 +1,10 @@ -tick="✓" -cross="✗" - +# Function to log start of a operation step_log() { message=$1 printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message" } +# Function to log result of a operation add_log() { mark=$1 subject=$2 @@ -17,63 +16,122 @@ add_log() { fi } -get_extension_regex() { - extension=$1 - case $extension in - "opcache") - echo "^Zend\sOPcache$" - ;; - "xdebug") - echo "^Xdebug$" - ;; - *) - echo ^"$extension"$ - ;; - esac +# Function to update php ppa +update_ppa() { + if [ "$ppa_updated" = "false" ]; then + find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 + ppa_updated="true" + fi } +# Function to setup extension +add_extension() { + extension=$1 + install_command=$2 + prefix=$3 + if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then + echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" + 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") || + (update_ppa && eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") || + add_log "$cross" "$extension" "Could not install $extension on PHP $semver" + fi +} + +# Function to setup the nightly build from master branch +setup_master() { + tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz + install_dir=~/php/"$version" + sudo mkdir -m 777 -p ~/php + $apt_install libicu-dev >/dev/null 2>&1 + curl -o "$tar_file" -L https://bintray.com/shivammathur/php/download_file?file_path="$tar_file" >/dev/null 2>&1 + sudo tar xf "$tar_file" -C ~/php >/dev/null 2>&1 + rm -rf "$tar_file" + sudo ln -sf -S "$version" "$install_dir"/bin/* /usr/bin/ + sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini +} + +# Function to setup PECL +setup_pecl() { + $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1 + sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1 + sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1 + wget https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar >/dev/null 2>&1 + sudo php install-pear-nozlib.phar >/dev/null 2>&1 + 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 +} + +# Function to setup composer +setup_composer() { + if [ ! -e "/usr/bin/composer" ]; then + curl -s -L https://getcomposer.org/installer >composer-setup.php + if [ "$(curl -s https://composer.github.io/installer.sig)" != "$(php -r "echo hash_file('sha384', 'composer-setup.php');")" ]; then + echo >&2 'ERROR: Invalid installer signature' + else + export COMPOSER_ALLOW_SUPERUSER=1 + sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer + fi + rm composer-setup.php + fi + add_log "$tick" "Composer" "Installed" +} + +# Function to switch versions of PHP binaries +switch_version() { + for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do + if [ -e "/usr/bin/$tool$version" ]; then + sudo update-alternatives --set $tool /usr/bin/"$tool$version" >/dev/null 2>&1 + fi + done +} + +# Variables +tick="✓" +cross="✗" +ppa_updated="false" +version=$1 +pecl=$2 +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 and Composer" sudo mkdir -p /var/run sudo mkdir -p /run/php -find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 -if [ "$existing_version" != "$1" ]; then - if [ ! -e "/usr/bin/php$1" ]; then - if [ "$1" = "7.4" ]; then - sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1" php"$1"-phpdbg php"$1"-xml curl php"$1"-curl >/dev/null 2>&1 - elif [ "$1" = "8.0" ]; then - tar_file=php_"$1"%2Bubuntu"$(lsb_release -r -s)".tar.xz - install_dir=~/php/"$1" - sudo DEBIAN_FRONTEND=noninteractive apt-get -y install libicu-dev >/dev/null 2>&1 - curl -o "$tar_file" -L https://bintray.com/shivammathur/php/download_file?file_path="$tar_file" >/dev/null 2>&1 - sudo mkdir -m 777 -p ~/php - sudo tar xf "$tar_file" -C ~/php >/dev/null 2>&1 && rm -rf "$tar_file" - sudo ln -sf -S "$1" "$install_dir"/bin/* /usr/bin/ && sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini - else - sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1" curl php"$1"-curl >/dev/null 2>&1 - fi - status="installed" - else - status="switched" - fi - for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do - if [ -e "/usr/bin/$tool$1" ]; then - sudo update-alternatives --set $tool /usr/bin/"$tool$1" >/dev/null 2>&1 - fi - done +if [ "$existing_version" != "$version" ]; then + if [ ! -e "/usr/bin/php$version" ]; then + update_ppa + ppa_updated=1 + if [ "$version" = "7.4" ]; then + $apt_install php"$version" php"$version"-phpdbg php"$version"-xml curl php"$version"-curl >/dev/null 2>&1 + elif [ "$version" = "8.0" ]; then + setup_master + else + $apt_install php"$version" curl php"$version"-curl >/dev/null 2>&1 + fi + status="installed" + else + status="switched" + fi - semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-') - if [ "$1" = "8.0" ]; then - semver=$(php -v | head -n 1 | cut -f 2 -d ' ') - fi + switch_version - if [ "$status" != "switched" ]; then - status="Installed PHP $semver" - else - status="Switched to PHP $semver" - fi + 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 ' ') + fi + + if [ "$status" != "switched" ]; then + status="Installed PHP $semver" + else + status="Switched to PHP $semver" + fi else status="PHP $semver Found" fi @@ -82,45 +140,13 @@ ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") sudo chmod 777 "$ini_file" add_log "$tick" "PHP" "$status" -if [ "$2" = "true" ]; then - sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1"-dev php"$1"-xml >/dev/null 2>&1 - sudo update-alternatives --set php-config /usr/bin/php-config"$1" >/dev/null 2>&1 - sudo update-alternatives --set phpize /usr/bin/phpize"$1" >/dev/null 2>&1 - wget https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar >/dev/null 2>&1 - sudo php install-pear-nozlib.phar >/dev/null 2>&1 - sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1 - sudo pear config-set auto_discover 1 - sudo pear channel-update pear.php.net + +# Setup PECL +if [ "$pecl" = "true" ]; then + update_ppa + setup_pecl add_log "$tick" "PECL" "Installed" fi -if [ ! -e "/usr/bin/composer" ]; then - curl -s -L https://getcomposer.org/installer > composer-setup.php - if [ "$(curl -s https://composer.github.io/installer.sig)" != "$(php -r "echo hash_file('sha384', 'composer-setup.php');")" ]; then - >&2 echo 'ERROR: Invalid installer signature' - else - export COMPOSER_ALLOW_SUPERUSER=1 - sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer - fi - rm composer-setup.php -fi -composer global require hirak/prestissimo >/dev/null 2>&1 -add_log "$tick" "Composer" "Installed" - -add_extension() -{ - extension=$1 - install_command=$2 - prefix=$3 - extension_regex="$(get_extension_regex "$extension")" - if ! php -m | grep -i -q "$extension_regex" && [ -e "$ext_dir/$extension.so" ]; then - echo "$prefix=$extension" >> "$ini_file" && add_log "$tick" "$extension" "Enabled" - elif php -m | grep -i -q "$extension_regex"; then - add_log "$tick" "$extension" "Enabled" - elif ! php -m | grep -i -q "$extension_regex"; then - ( - eval "$install_command" && \ - add_log "$tick" "$extension" "Installed and enabled" - ) || add_log "$cross" "$extension" "Could not install $extension on PHP $semver" - fi -} \ No newline at end of file +# Setup composer +setup_composer From 4c045616f458dcd672298c0b9bc526cca7dfb8ff Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 23 Dec 2019 23:19:38 +0530 Subject: [PATCH 02/11] Improve support for ext-phalcon and refactor extensions.ts --- __tests__/extensions.test.ts | 28 +++++++++-------- dist/index.js | 59 +++++++++++++++--------------------- src/extensions.ts | 59 +++++++++++++++--------------------- src/scripts/darwin.sh | 16 ++++++++++ src/scripts/phalcon.sh | 12 +++----- src/scripts/win32.ps1 | 28 ++++++++++++++++- 6 files changed, 112 insertions(+), 90 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 5aa82106..02ae61c0 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -3,20 +3,21 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( - 'xdebug, pcov, redis', + 'xdebug, pcov, phalcon4', '7.4', 'win32' ); expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension pcov'); - expect(win32).toContain('Add-Extension redis beta'); + expect(win32).toContain('Add-Phalcon phalcon4'); win32 = await extensions.addExtension( - 'does_not_exist', + 'phalcon3, does_not_exist', '7.2', 'win32', true ); + expect(win32).toContain('Add-Phalcon phalcon3'); expect(win32).toContain('Add-Extension does_not_exist'); win32 = await extensions.addExtension('xdebug', '7.2', 'fedora'); @@ -25,7 +26,7 @@ describe('Extension tests', () => { it('checking addExtensionOnLinux', async () => { let linux: string = await extensions.addExtension( - 'xdebug, pcov, redis', + 'xdebug, pcov', '7.4', 'linux' ); @@ -37,9 +38,6 @@ describe('Extension tests', () => { 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov' ); expect(linux).toContain('pecl install pcov'); - expect(linux).toContain( - 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-igbinary php7.4-redis' - ); linux = await extensions.addExtension('gearman', '7.0', 'linux'); expect(linux).toContain('gearman.sh 7.0'); @@ -51,8 +49,8 @@ describe('Extension tests', () => { '7.2', 'linux' ); - expect(linux).toContain('phalcon.sh 3.4.x 7.2'); - expect(linux).toContain('phalcon.sh master 7.2'); + expect(linux).toContain('phalcon.sh phalcon3 7.2'); + expect(linux).toContain('phalcon.sh phalcon4 7.2'); expect(linux).toContain('gearman.sh 7.2'); linux = await extensions.addExtension( @@ -60,12 +58,12 @@ describe('Extension tests', () => { '7.3', 'linux' ); - expect(linux).toContain('phalcon.sh 3.4.x 7.3'); - expect(linux).toContain('phalcon.sh master 7.3'); + expect(linux).toContain('phalcon.sh phalcon3 7.3'); + expect(linux).toContain('phalcon.sh phalcon4 7.3'); expect(linux).toContain('gearman.sh 7.3'); linux = await extensions.addExtension('phalcon4, gearman', '7.4', 'linux'); - expect(linux).toContain('phalcon.sh master 7.4'); + expect(linux).toContain('phalcon.sh phalcon4 7.4'); expect(linux).toContain('gearman.sh 7.4'); linux = await extensions.addExtension('xdebug', '7.2', 'fedora'); @@ -81,6 +79,12 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install xdebug'); expect(darwin).toContain('sudo pecl install pcov'); + darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); + expect(darwin).toContain('add_phalcon phalcon3'); + + darwin = await extensions.addExtension('phalcon4', '7.3', 'darwin'); + expect(darwin).toContain('add_phalcon phalcon4'); + darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); expect(darwin).toContain('sudo pecl install pcov'); diff --git a/dist/index.js b/dist/index.js index accea60c..1e140d0a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2194,13 +2194,16 @@ function addExtensionDarwin(extension_csv, version) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '5.6xdebug': + switch (true) { + case /5\.6xdebug/.test(version + extension): install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; break; - case '5.6redis': + case /5\.6redis/.test(version + extension): install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nadd_phalcon ' + extension; + return; default: install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; break; @@ -2231,9 +2234,10 @@ function addExtensionWindows(extension_csv, version) { yield utils.asyncForEach(extensions, function (extension) { return __awaiter(this, void 0, void 0, function* () { // add script to enable extension is already installed along with php - switch (version + extension) { - case '7.4redis': - script += '\nAdd-Extension ' + extension + ' beta'; + switch (true) { + // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nAdd-Phalcon ' + extension; break; default: script += '\nAdd-Extension ' + extension; @@ -2260,35 +2264,9 @@ function addExtensionLinux(extension_csv, version) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '7.4redis': - install_command = - 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-igbinary php7.4-redis >/dev/null 2>&1'; - break; - case '7.2phalcon3': - case '7.3phalcon3': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' 3.4.x ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.2phalcon4': - case '7.3phalcon4': - case '7.4phalcon4': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' master ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.0gearman': - case '7.1gearman': - case '7.2gearman': - case '7.3gearman': - case '7.4gearman': + switch (true) { + // match 5.6gearman..7.4gearman + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): install_command = 'sh ' + path.join(__dirname, '../src/scripts/gearman.sh') + @@ -2296,6 +2274,17 @@ function addExtensionLinux(extension_csv, version) { version + ' >/dev/null 2>&1'; break; + // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/phalcon.sh') + + ' ' + + extension + + ' ' + + version + + ' >/dev/null 2>&1'; + break; default: install_command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + diff --git a/src/extensions.ts b/src/extensions.ts index b10fd33e..3f76d86a 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -17,13 +17,16 @@ export async function addExtensionDarwin( extension = extension.toLowerCase(); // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '5.6xdebug': + switch (true) { + case /5\.6xdebug/.test(version + extension): install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; break; - case '5.6redis': + case /5\.6redis/.test(version + extension): install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nadd_phalcon ' + extension; + return; default: install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; break; @@ -53,9 +56,10 @@ export async function addExtensionWindows( let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { // add script to enable extension is already installed along with php - switch (version + extension) { - case '7.4redis': - script += '\nAdd-Extension ' + extension + ' beta'; + switch (true) { + // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nAdd-Phalcon ' + extension; break; default: script += '\nAdd-Extension ' + extension; @@ -82,35 +86,9 @@ export async function addExtensionLinux( // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '7.4redis': - install_command = - 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-igbinary php7.4-redis >/dev/null 2>&1'; - break; - case '7.2phalcon3': - case '7.3phalcon3': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' 3.4.x ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.2phalcon4': - case '7.3phalcon4': - case '7.4phalcon4': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' master ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.0gearman': - case '7.1gearman': - case '7.2gearman': - case '7.3gearman': - case '7.4gearman': + switch (true) { + // match 5.6gearman..7.4gearman + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): install_command = 'sh ' + path.join(__dirname, '../src/scripts/gearman.sh') + @@ -118,6 +96,17 @@ export async function addExtensionLinux( version + ' >/dev/null 2>&1'; break; + // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/phalcon.sh') + + ' ' + + extension + + ' ' + + version + + ' >/dev/null 2>&1'; + break; default: install_command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 068e2141..e4d68bba 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -40,6 +40,22 @@ add_extension() { fi } +add_phalcon() { + extension=$1 + sudo pecl install psr >/dev/null 2>&1 + brew install autoconf automake libtool >/dev/null 2>&1 + git clone https://github.com/phalcon/cphalcon.git >/dev/null 2>&1 + cd cphalcon || echo "could not cd" + git checkout "$(git branch -r | grep -E "origin/${extension: -1}\.\d\.x" | sort -r | head -n 1 | sed "s/ //g")" >/dev/null 2>&1 + sed -i '' 's/zend_ulong/ulong/' build/php7/64bits/phalcon.zep.c + sed -i '' 's/ulong/zend_ulong/' build/php7/64bits/phalcon.zep.c + cd build/php7/64bits && sudo phpize >/dev/null 2>&1 + sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-phalcon >/dev/null 2>&1 + sudo glibtoolize --force >/dev/null 2>&1 && sudo autoreconf >/dev/null 2>&1 + sudo make -i -j2 >/dev/null 2>&1 && sudo make install >/dev/null 2>&1 + echo "extension=phalcon.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled" +} + # Function to setup PHP and composer setup_php_and_composer() { export HOMEBREW_NO_INSTALL_CLEANUP=TRUE diff --git a/src/scripts/phalcon.sh b/src/scripts/phalcon.sh index 382f7314..516f3c03 100644 --- a/src/scripts/phalcon.sh +++ b/src/scripts/phalcon.sh @@ -1,8 +1,6 @@ ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") -ini_dir=$(php --ini | grep in: | sed -e "s|.*:s*||" | sed "s/ //g") -if [ ! "$(apt-cache search php"$2"-psr)" ]; then - sudo DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y >/dev/null 2>&1 -fi +find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 +curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$2"-dev sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$2"-psr for tool in php-config phpize; do @@ -19,6 +17,6 @@ if [ ! "$(apt-cache search php"$2"-psr)" ]; then echo "extension=psr.so" >> "$ini_file" fi -cd ~ && git clone --depth=1 -v https://github.com/phalcon/cphalcon.git -b "$1" -cd cphalcon/build && sudo ./install --phpize /usr/bin/phpize"$2" --php-config /usr/bin/php-config"$2" -echo "extension=phalcon.so" | sudo tee "$ini_dir/50-phalcon.ini" \ No newline at end of file +extension_major_version=$(echo "$1" | grep -i -Po '\d') +extension_version=$(apt-cache policy -- *phalcon | grep -i -Po "$extension_major_version\.\d\.\d.*php$2" | head -n 1) +sudo DEBIAN_FRONTEND=noninteractive apt-fast -o Dpkg::Options::="--force-overwrite" install -y php"$2"-phalcon="$extension_version" \ No newline at end of file diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 7193d900..5d67c86d 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -9,6 +9,7 @@ $php_dir = 'C:\tools\php' $ext_dir = $php_dir + '\ext' $ProgressPreference = 'SilentlyContinue' $master_version = '8.0' +$arch='x64' Function Step-Log($message) { printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message @@ -33,7 +34,6 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) { } Step-Log "Setup PHP and Composer" if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) { - $arch='x64' if ($version -lt '7.0') { Install-Module -Name VcRedist -Force $arch='x86' @@ -101,3 +101,29 @@ Function Add-Extension { Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)" } } + +Function Add-Phalcon { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateSet('phalcon3', 'phalcon4')] + [string] + $extension + ) + $extension_version = $extension.substring($extension.Length - 1) + $nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" } + $domain = "https://github.com" + Install-Phpextension psr + try + { + $match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" + $zip_file = $match.Matches[0].Groups[1].Value + Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $PSScriptRoot\phalcon.zip + Expand-Archive -Path $PSScriptRoot\phalcon.zip -DestinationPath $PSScriptRoot\phalcon -Force > $null 2>&1 + New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $PSScriptRoot\phalcon\php_phalcon.dll > $null 2>&1 + Enable-PhpExtension -Extension phalcon -Path $php_dir + Add-Log $tick $extension "Installed and enabled" + } catch { + Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)" + } +} From 273096b82f3d5d06d18203d9ebdccc8f456f0ce6 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 26 Dec 2019 18:31:18 +0530 Subject: [PATCH 03/11] Refactor coverage and extension code --- __tests__/coverage.test.ts | 55 +++------ __tests__/extensions.test.ts | 8 +- __tests__/install.test.ts | 9 +- dist/index.js | 164 ++++++++++--------------- src/{ext => bin}/php_pcov.dll | Bin src/coverage.ts | 93 ++++---------- src/extensions.ts | 76 +++++++----- src/install.ts | 4 +- src/scripts/7.4.sh | 116 ----------------- src/scripts/darwin.sh | 19 +-- src/scripts/{ => ext}/gearman.sh | 0 src/scripts/{ => ext}/pcov.sh | 0 src/scripts/ext/phalcon.ps1 | 27 ++++ src/scripts/{ => ext}/phalcon.sh | 0 src/scripts/ext/phalcon_darwin.sh | 16 +++ src/scripts/{ => ext}/xdebug.sh | 0 src/scripts/{ => ext}/xdebug_darwin.sh | 0 src/scripts/linux.sh | 12 +- src/scripts/win32.ps1 | 139 +++++++++++---------- 19 files changed, 286 insertions(+), 452 deletions(-) rename src/{ext => bin}/php_pcov.dll (100%) delete mode 100644 src/scripts/7.4.sh rename src/scripts/{ => ext}/gearman.sh (100%) rename src/scripts/{ => ext}/pcov.sh (100%) create mode 100644 src/scripts/ext/phalcon.ps1 rename src/scripts/{ => ext}/phalcon.sh (100%) create mode 100644 src/scripts/ext/phalcon_darwin.sh rename src/scripts/{ => ext}/xdebug.sh (100%) rename src/scripts/{ => ext}/xdebug_darwin.sh (100%) diff --git a/__tests__/coverage.test.ts b/__tests__/coverage.test.ts index 121d04c2..b8eaf597 100644 --- a/__tests__/coverage.test.ts +++ b/__tests__/coverage.test.ts @@ -2,20 +2,15 @@ import * as coverage from '../src/coverage'; jest.mock('../src/extensions', () => ({ addExtension: jest.fn().mockImplementation(extension => { - return 'addExtension ' + extension + '\n'; + return 'add_extension ' + extension + '\n'; }) })); describe('Config tests', () => { it('checking addCoverage with PCOV on windows', async () => { let win32: string = await coverage.addCoverage('pcov', '7.4', 'win32'); - expect(win32).toContain('addExtension pcov'); - expect(win32).toContain( - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir' - ); - expect(win32).toContain( - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' - ); + expect(win32).toContain('add_extension pcov'); + expect(win32).toContain('Remove-Extension xdebug'); win32 = await coverage.addCoverage('pcov', '7.0', 'win32'); expect(win32).toContain('PHP 7.1 or newer is required'); @@ -26,24 +21,19 @@ describe('Config tests', () => { it('checking addCoverage with PCOV on linux', async () => { const linux: string = await coverage.addCoverage('pcov', '7.4', 'linux'); - expect(linux).toContain('addExtension pcov'); - expect(linux).toContain('sudo sed -i "/xdebug/d" "$ini_file"'); - expect(linux).toContain('sudo phpdismod -v 7.4 xdebug'); - expect(linux).toContain( - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug' - ); + expect(linux).toContain('add_extension pcov'); + expect(linux).toContain('remove_extension xdebug'); }); it('checking addCoverage with PCOV on darwin', async () => { const darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin'); - expect(darwin).toContain('addExtension pcov'); - expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" "$ini_file"'); - expect(darwin).toContain('sudo rm -rf "$ext_dir"/xdebug.so'); + expect(darwin).toContain('add_extension pcov'); + expect(darwin).toContain('remove_extension xdebug'); }); it('checking addCoverage with Xdebug on windows', async () => { const win32: string = await coverage.addCoverage('xdebug', '7.4', 'win32'); - expect(win32).toContain('addExtension xdebug'); + expect(win32).toContain('add_extension xdebug'); }); it('checking addCoverage with Xdebug on windows', async () => { @@ -53,7 +43,7 @@ describe('Config tests', () => { it('checking addCoverage with Xdebug on linux', async () => { const linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux'); - expect(linux).toContain('addExtension xdebug'); + expect(linux).toContain('add_extension xdebug'); }); it('checking addCoverage with Xdebug on linux', async () => { @@ -67,7 +57,7 @@ describe('Config tests', () => { '7.4', 'darwin' ); - expect(darwin).toContain('addExtension xdebug'); + expect(darwin).toContain('add_extension xdebug'); }); it('checking addCoverage with Xdebug on darwin', async () => { @@ -81,33 +71,20 @@ describe('Config tests', () => { it('checking disableCoverage windows', async () => { const win32 = await coverage.addCoverage('none', '7.4', 'win32'); - expect(win32).toContain('Disable-PhpExtension xdebug'); - expect(win32).toContain('Disable-PhpExtension pcov'); - expect(win32).toContain( - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' - ); - expect(win32).toContain( - 'if (Test-Path $ext_dir\\php_pcov.dll) { Remove-Item $ext_dir\\php_pcov.dll }' - ); + expect(win32).toContain('Remove-Extension xdebug'); + expect(win32).toContain('Remove-Extension pcov'); }); it('checking disableCoverage on linux', async () => { const linux: string = await coverage.addCoverage('none', '7.4', 'linux'); - expect(linux).toContain('sudo phpdismod -v 7.4 xdebug'); - expect(linux).toContain('sudo phpdismod -v 7.4 pcov'); - expect(linux).toContain('sudo sed -i "/xdebug/d" "$ini_file"'); - expect(linux).toContain('sudo sed -i "/pcov/d" "$ini_file"'); - expect(linux).toContain( - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug php-pcov' - ); + expect(linux).toContain('remove_extension xdebug'); + expect(linux).toContain('remove_extension pcov'); }); it('checking disableCoverage on darwin', async () => { const darwin: string = await coverage.addCoverage('none', '7.4', 'darwin'); - expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" "$ini_file"'); - expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" "$ini_file"'); - expect(darwin).toContain('sudo rm -rf "$ext_dir"/xdebug.so'); - expect(darwin).toContain('sudo rm -rf "$ext_dir"/pcov.so'); + expect(darwin).toContain('remove_extension xdebug'); + expect(darwin).toContain('remove_extension pcov'); }); it('checking no or invalid coverage driver', async () => { diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 02ae61c0..61c41e2d 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -9,7 +9,7 @@ describe('Extension tests', () => { ); expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension pcov'); - expect(win32).toContain('Add-Phalcon phalcon4'); + expect(win32).toContain('phalcon.ps1 phalcon4'); win32 = await extensions.addExtension( 'phalcon3, does_not_exist', @@ -17,7 +17,7 @@ describe('Extension tests', () => { 'win32', true ); - expect(win32).toContain('Add-Phalcon phalcon3'); + expect(win32).toContain('phalcon.ps1 phalcon3'); expect(win32).toContain('Add-Extension does_not_exist'); win32 = await extensions.addExtension('xdebug', '7.2', 'fedora'); @@ -80,10 +80,10 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install pcov'); darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); - expect(darwin).toContain('add_phalcon phalcon3'); + expect(darwin).toContain('phalcon_darwin.sh phalcon3'); darwin = await extensions.addExtension('phalcon4', '7.3', 'darwin'); - expect(darwin).toContain('add_phalcon phalcon4'); + expect(darwin).toContain('phalcon_darwin.sh phalcon4'); darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); expect(darwin).toContain('sudo pecl install pcov'); diff --git a/__tests__/install.test.ts b/__tests__/install.test.ts index b5daa8ae..76616051 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -47,8 +47,7 @@ jest.mock('../src/install', () => ({ } case 'win32': script = await install.build(os_version + '.sh', version, os_version); - script += - 'pwsh script.ps1 -version ' + version + ' -dir ' + __dirname; + script += 'pwsh script.ps1 ' + version + ' ' + __dirname; break; default: script += os_version + ' is not supported'; @@ -90,13 +89,13 @@ describe('Install', () => { // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('pwsh script.ps1 -version 7.0 -dir ' + __dirname); + expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname); setEnv('7.3', 'win32', '', '', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname); + expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname); setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', ''); // @ts-ignore @@ -105,7 +104,7 @@ describe('Install', () => { expect(script).toContain('install extensions'); expect(script).toContain('edit php.ini'); expect(script).toContain('set coverage driver'); - expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname); + expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname); }); it('Test install on linux', async () => { diff --git a/dist/index.js b/dist/index.js index 1e140d0a..fdcdabc9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1570,8 +1570,9 @@ const config = __importStar(__webpack_require__(641)); * * @param version * @param os_version + * @param pipe */ -function addCoverageXdebug(version, os_version) { +function addCoverageXdebug(version, os_version, pipe) { return __awaiter(this, void 0, void 0, function* () { switch (version) { case '8.0': @@ -1580,7 +1581,7 @@ function addCoverageXdebug(version, os_version) { case '7.4': default: return ((yield extensions.addExtension('xdebug', version, os_version, true)) + - (yield utils.suppressOutput(os_version)) + + pipe + '\n' + (yield utils.addLog('$tick', 'xdebug', 'Xdebug enabled as coverage driver', os_version))); } @@ -1592,47 +1593,27 @@ exports.addCoverageXdebug = addCoverageXdebug; * * @param version * @param os_version + * @param pipe */ -function addCoveragePCOV(version, os_version) { +function addCoveragePCOV(version, os_version, pipe) { return __awaiter(this, void 0, void 0, function* () { let script = '\n'; switch (version) { default: script += (yield extensions.addExtension('pcov', version, os_version, true)) + - (yield utils.suppressOutput(os_version)) + + pipe + '\n'; script += (yield config.addINIValues('pcov.enabled=1', os_version, true)) + '\n'; // add command to disable xdebug and enable pcov switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug -y ' + - (yield utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (yield utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (yield utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; break; } // success @@ -1653,56 +1634,20 @@ exports.addCoveragePCOV = addCoveragePCOV; * * @param version * @param os_version + * @param pipe */ -function disableCoverage(version, os_version) { +function disableCoverage(version, os_version, pipe) { return __awaiter(this, void 0, void 0, function* () { let script = '\n'; switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/pcov.ini ]; then sudo phpdismod -v ' + - version + - ' pcov; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i "/pcov/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug php-pcov -y ' + - (yield utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i \'\' "/pcov/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (yield utils.suppressOutput('darwin')) + - '\n'; - script += - 'sudo rm -rf "$ext_dir"/pcov.so ' + - (yield utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; + script += 'remove_extension pcov' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (yield utils.suppressOutput('win32')) + - '\n'; - script += - 'if (Test-Path $ext_dir\\php_pcov.dll) { Remove-Item $ext_dir\\php_pcov.dll }' + - (yield utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; + script += 'Remove-Extension pcov' + pipe + '\n'; break; } script += yield utils.addLog('$tick', 'none', 'Disabled Xdebug and PCOV', os_version); @@ -1721,13 +1666,14 @@ function addCoverage(coverage_driver, version, os_version) { return __awaiter(this, void 0, void 0, function* () { coverage_driver.toLowerCase(); const script = '\n' + (yield utils.stepLog('Setup Coverage', os_version)); + const pipe = yield utils.suppressOutput(os_version); switch (coverage_driver) { case 'pcov': - return script + (yield addCoveragePCOV(version, os_version)); + return script + (yield addCoveragePCOV(version, os_version, pipe)); case 'xdebug': - return script + (yield addCoverageXdebug(version, os_version)); + return script + (yield addCoverageXdebug(version, os_version, pipe)); case 'none': - return script + (yield disableCoverage(version, os_version)); + return script + (yield disableCoverage(version, os_version, pipe)); default: return ''; } @@ -1922,7 +1868,7 @@ function run() { } case 'win32': script_path = yield build('win32.ps1', version, os_version); - yield exec_1.exec('pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname); + yield exec_1.exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); break; } yield matchers.addMatchers(); @@ -2184,28 +2130,35 @@ const utils = __importStar(__webpack_require__(163)); * * @param extension_csv * @param version + * @param pipe */ -function addExtensionDarwin(extension_csv, version) { +function addExtensionDarwin(extension_csv, version, pipe) { return __awaiter(this, void 0, void 0, function* () { const extensions = yield utils.extensionArray(extension_csv); let script = '\n'; yield utils.asyncForEach(extensions, function (extension) { return __awaiter(this, void 0, void 0, function* () { extension = extension.toLowerCase(); + const version_extension = version + extension; // add script to enable extension is already installed along with php let install_command = ''; switch (true) { - case /5\.6xdebug/.test(version + extension): - install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; + case /5\.6xdebug/.test(version_extension): + install_command = 'sudo pecl install xdebug-2.5.5' + pipe; break; - case /5\.6redis/.test(version + extension): - install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; + case /5\.6redis/.test(version_extension): + install_command = 'sudo pecl install redis-2.2.8' + pipe; + break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + + ' ' + + extension + + pipe; break; - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nadd_phalcon ' + extension; - return; default: - install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; + install_command = 'sudo pecl install ' + extension + pipe; break; } script += @@ -2226,18 +2179,27 @@ exports.addExtensionDarwin = addExtensionDarwin; * * @param extension_csv * @param version + * @param pipe */ -function addExtensionWindows(extension_csv, version) { +function addExtensionWindows(extension_csv, version, pipe) { return __awaiter(this, void 0, void 0, function* () { const extensions = yield utils.extensionArray(extension_csv); let script = '\n'; yield utils.asyncForEach(extensions, function (extension) { return __awaiter(this, void 0, void 0, function* () { // add script to enable extension is already installed along with php + const version_extension = version + extension; switch (true) { // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nAdd-Phalcon ' + extension; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + script += + '\n& ' + + path.join(__dirname, '../src/scripts/ext/phalcon.ps1') + + ' ' + + extension + + ' ' + + version + + '\n'; break; default: script += '\nAdd-Extension ' + extension; @@ -2254,8 +2216,9 @@ exports.addExtensionWindows = addExtensionWindows; * * @param extension_csv * @param version + * @param pipe */ -function addExtensionLinux(extension_csv, version) { +function addExtensionLinux(extension_csv, version, pipe) { return __awaiter(this, void 0, void 0, function* () { const extensions = yield utils.extensionArray(extension_csv); let script = '\n'; @@ -2263,27 +2226,28 @@ function addExtensionLinux(extension_csv, version) { return __awaiter(this, void 0, void 0, function* () { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php + const version_extension = version + extension; let install_command = ''; switch (true) { // match 5.6gearman..7.4gearman - case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/gearman.sh') + + path.join(__dirname, '../src/scripts/ext/gearman.sh') + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + + path.join(__dirname, '../src/scripts/ext/phalcon.sh') + ' ' + extension + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; default: install_command = @@ -2291,9 +2255,10 @@ function addExtensionLinux(extension_csv, version) { version + '-' + extension.replace('pdo_', '').replace('pdo-', '') + - ' >/dev/null 2>&1 || sudo pecl install ' + + pipe + + ' || sudo pecl install ' + extension + - ' >/dev/null 2>&1'; + pipe; break; } script += @@ -2319,12 +2284,11 @@ exports.addExtensionLinux = addExtensionLinux; */ function addExtension(extension_csv, version, os_version, no_step = false) { return __awaiter(this, void 0, void 0, function* () { + const pipe = yield utils.suppressOutput(os_version); let script = '\n'; switch (no_step) { case true: - script += - (yield utils.stepLog('Setup Extensions', os_version)) + - (yield utils.suppressOutput(os_version)); + script += (yield utils.stepLog('Setup Extensions', os_version)) + pipe; break; case false: default: @@ -2333,11 +2297,11 @@ function addExtension(extension_csv, version, os_version, no_step = false) { } switch (os_version) { case 'win32': - return script + (yield addExtensionWindows(extension_csv, version)); + return script + (yield addExtensionWindows(extension_csv, version, pipe)); case 'darwin': - return script + (yield addExtensionDarwin(extension_csv, version)); + return script + (yield addExtensionDarwin(extension_csv, version, pipe)); case 'linux': - return script + (yield addExtensionLinux(extension_csv, version)); + return script + (yield addExtensionLinux(extension_csv, version, pipe)); default: return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); } diff --git a/src/ext/php_pcov.dll b/src/bin/php_pcov.dll similarity index 100% rename from src/ext/php_pcov.dll rename to src/bin/php_pcov.dll diff --git a/src/coverage.ts b/src/coverage.ts index 4b6e0275..7b2996a3 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -7,10 +7,12 @@ import * as config from './config'; * * @param version * @param os_version + * @param pipe */ export async function addCoverageXdebug( version: string, - os_version: string + os_version: string, + pipe: string ): Promise { switch (version) { case '8.0': @@ -27,7 +29,7 @@ export async function addCoverageXdebug( default: return ( (await extensions.addExtension('xdebug', version, os_version, true)) + - (await utils.suppressOutput(os_version)) + + pipe + '\n' + (await utils.addLog( '$tick', @@ -44,17 +46,19 @@ export async function addCoverageXdebug( * * @param version * @param os_version + * @param pipe */ export async function addCoveragePCOV( version: string, - os_version: string + os_version: string, + pipe: string ): Promise { let script = '\n'; switch (version) { default: script += (await extensions.addExtension('pcov', version, os_version, true)) + - (await utils.suppressOutput(os_version)) + + pipe + '\n'; script += (await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n'; @@ -62,32 +66,11 @@ export async function addCoveragePCOV( // add command to disable xdebug and enable pcov switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug -y ' + - (await utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (await utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (await utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; break; } @@ -119,58 +102,23 @@ export async function addCoveragePCOV( * * @param version * @param os_version + * @param pipe */ export async function disableCoverage( version: string, - os_version: string + os_version: string, + pipe: string ): Promise { let script = '\n'; switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/pcov.ini ]; then sudo phpdismod -v ' + - version + - ' pcov; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i "/pcov/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug php-pcov -y ' + - (await utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i \'\' "/pcov/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (await utils.suppressOutput('darwin')) + - '\n'; - script += - 'sudo rm -rf "$ext_dir"/pcov.so ' + - (await utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; + script += 'remove_extension pcov' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (await utils.suppressOutput('win32')) + - '\n'; - script += - 'if (Test-Path $ext_dir\\php_pcov.dll) { Remove-Item $ext_dir\\php_pcov.dll }' + - (await utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; + script += 'Remove-Extension pcov' + pipe + '\n'; break; } script += await utils.addLog( @@ -198,13 +146,14 @@ export async function addCoverage( coverage_driver.toLowerCase(); const script: string = '\n' + (await utils.stepLog('Setup Coverage', os_version)); + const pipe: string = await utils.suppressOutput(os_version); switch (coverage_driver) { case 'pcov': - return script + (await addCoveragePCOV(version, os_version)); + return script + (await addCoveragePCOV(version, os_version, pipe)); case 'xdebug': - return script + (await addCoverageXdebug(version, os_version)); + return script + (await addCoverageXdebug(version, os_version, pipe)); case 'none': - return script + (await disableCoverage(version, os_version)); + return script + (await disableCoverage(version, os_version, pipe)); default: return ''; } diff --git a/src/extensions.ts b/src/extensions.ts index 3f76d86a..36583669 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -6,29 +6,37 @@ import * as utils from './utils'; * * @param extension_csv * @param version + * @param pipe */ export async function addExtensionDarwin( extension_csv: string, - version: string + version: string, + pipe: string ): Promise { const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); + const version_extension: string = version + extension; // add script to enable extension is already installed along with php let install_command = ''; switch (true) { - case /5\.6xdebug/.test(version + extension): - install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; + case /5\.6xdebug/.test(version_extension): + install_command = 'sudo pecl install xdebug-2.5.5' + pipe; break; - case /5\.6redis/.test(version + extension): - install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; + case /5\.6redis/.test(version_extension): + install_command = 'sudo pecl install redis-2.2.8' + pipe; + break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + + ' ' + + extension + + pipe; break; - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nadd_phalcon ' + extension; - return; default: - install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; + install_command = 'sudo pecl install ' + extension + pipe; break; } script += @@ -47,19 +55,29 @@ export async function addExtensionDarwin( * * @param extension_csv * @param version + * @param pipe */ export async function addExtensionWindows( extension_csv: string, - version: string + version: string, + pipe: string ): Promise { const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { // add script to enable extension is already installed along with php + const version_extension: string = version + extension; switch (true) { // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nAdd-Phalcon ' + extension; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + script += + '\n& ' + + path.join(__dirname, '../src/scripts/ext/phalcon.ps1') + + ' ' + + extension + + ' ' + + version + + '\n'; break; default: script += '\nAdd-Extension ' + extension; @@ -74,38 +92,40 @@ export async function addExtensionWindows( * * @param extension_csv * @param version + * @param pipe */ export async function addExtensionLinux( extension_csv: string, - version: string + version: string, + pipe: string ): Promise { const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php - + const version_extension: string = version + extension; let install_command = ''; switch (true) { // match 5.6gearman..7.4gearman - case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/gearman.sh') + + path.join(__dirname, '../src/scripts/ext/gearman.sh') + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + + path.join(__dirname, '../src/scripts/ext/phalcon.sh') + ' ' + extension + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; default: install_command = @@ -113,9 +133,10 @@ export async function addExtensionLinux( version + '-' + extension.replace('pdo_', '').replace('pdo-', '') + - ' >/dev/null 2>&1 || sudo pecl install ' + + pipe + + ' || sudo pecl install ' + extension + - ' >/dev/null 2>&1'; + pipe; break; } script += @@ -143,12 +164,11 @@ export async function addExtension( os_version: string, no_step = false ): Promise { + const pipe: string = await utils.suppressOutput(os_version); let script = '\n'; switch (no_step) { case true: - script += - (await utils.stepLog('Setup Extensions', os_version)) + - (await utils.suppressOutput(os_version)); + script += (await utils.stepLog('Setup Extensions', os_version)) + pipe; break; case false: default: @@ -158,11 +178,11 @@ export async function addExtension( switch (os_version) { case 'win32': - return script + (await addExtensionWindows(extension_csv, version)); + return script + (await addExtensionWindows(extension_csv, version, pipe)); case 'darwin': - return script + (await addExtensionDarwin(extension_csv, version)); + return script + (await addExtensionDarwin(extension_csv, version, pipe)); case 'linux': - return script + (await addExtensionLinux(extension_csv, version)); + return script + (await addExtensionLinux(extension_csv, version, pipe)); default: return await utils.log( 'Platform ' + os_version + ' is not supported', diff --git a/src/install.ts b/src/install.ts index 1d7fd741..c0b8f97f 100644 --- a/src/install.ts +++ b/src/install.ts @@ -65,9 +65,7 @@ export async function run(): Promise { } case 'win32': script_path = await build('win32.ps1', version, os_version); - await exec( - 'pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname - ); + await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); break; } await matchers.addMatchers(); diff --git a/src/scripts/7.4.sh b/src/scripts/7.4.sh deleted file mode 100644 index 723dcaac..00000000 --- a/src/scripts/7.4.sh +++ /dev/null @@ -1,116 +0,0 @@ -tick="✓" -cross="✗" - -step_log() { - message=$1 - printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message" -} - -add_log() { - mark=$1 - subject=$2 - message=$3 - if [ "$mark" = "$tick" ]; then - printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" - else - printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" - fi -} -version='7.4.0' -step_log "Setup dependencies" -for package in pkg-config autoconf bison re2c openssl@1.1 krb5 enchant libffi freetype intltool icu4c libiconv t1lib gd libzip gmp tidyp libxml2 libxslt postgresql curl; -do - brew install "$package" >/dev/null 2>&1 - add_log "$tick" "$package" "Installed" -done -brew link icu4c gettext --force >/dev/null 2>&1 - -for package in gettext gmp krb5 icu4c bison openssl@1.1 libxml2 libffi libxslt libiconv pkgconfig enchant krb5 readline libedit freetype; -do - caps_package=$(echo "$package" | tr '[:lower:]' '[:upper:]') - { - echo 'export PATH="/usr/local/opt/'"$package"'/bin:$PATH"' - echo 'export PKG_CONFIG_PATH="/usr/local/opt/'$package'/lib/pkgconfig:$PKG_CONFIG_PATH"' - echo 'export '"$caps_package"'_LIBS="-L/usr/local/opt/'$package'/lib"' - echo 'export '"$caps_package"'_CFLAGS="-I/usr/local/opt/'$package'/include"' - } >> ~/.bash_profile; -done -{ -echo 'export ICONV_LIBS="-L/usr/local/opt/libiconv/lib"' -echo 'export ICONV_CFLAGS="-I/usr/local/opt/libiconv/include"' -echo 'export LIBXML_LIBS="-L/usr/local/opt/libxml2/lib"' -echo 'export LIBXML_CFLAGS="-I/usr/local/opt/libxml2/include"' -echo 'export ICU_LIBS="-L/usr/local/opt/icu4c/lib"' -echo 'export ICU_CFLAGS="-I/usr/local/opt/icu4c/include"' -echo 'export OPENSSL_LIBS="-L/usr/local/opt/openssl@1.1/lib -lcrypto"' -echo 'export OPENSSL_CFLAGS="-I/usr/local/opt/openssl@1.1/include"' -echo 'export OPENSSL_ROOT_DIR="/usr/local/opt/openssl@1.1/"' -echo 'export OPENSSL_LIB_DIR="/usr/local/opt/openssl@1.1/lib"' -echo 'export OPENSSL_INCLUDE_DIR="/usr/local/opt/openssl@1.1/include"' -echo 'export PKG_CONFIG="/usr/local/opt/pkgconfig/bin/pkg-config"' -echo 'export EXTRA_LIBS="/usr/local/opt/readline/lib/libhistory.dylib -/usr/local/opt/readline/lib/libreadline.dylib -/usr/local/opt/openssl@1.1/lib/libssl.dylib -/usr/local/opt/openssl@1.1/lib/libcrypto.dylib -/usr/local/opt/icu4c/lib/libicudata.dylib -/usr/local/opt/icu4c/lib/libicui18n.dylib -/usr/local/opt/icu4c/lib/libicuio.dylib -/usr/local/opt/icu4c/lib/libicutu.dylib -/usr/local/opt/icu4c/lib/libicuuc.dylib"' -} >> ~/.bash_profile -config_file=$2/../src/configs/config.yaml - -step_log "Setup PHPBrew" -curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew >/dev/null 2>&1 -chmod +x ./phpbrew -sudo mv phpbrew /usr/local/bin/phpbrew -sudo mkdir -p /opt/phpbrew -sudo mkdir -p /usr/local/lib -sudo mkdir -p /usr/local/bin -sudo phpbrew init --root=/opt/phpbrew --config="$config_file" >/dev/null 2>&1 -sudo chmod -R 777 /opt/phpbrew -export PHPBREW_ROOT=/opt/phpbrew -export PHPBREW_HOME=/opt/phpbrew -echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> ~/.bashrc -add_log "$tick" "PHPBrew" "Installed" - -source ~/.bash_profile >/dev/null 2>&1 -source ~/.bashrc >/dev/null 2>&1 - -step_log "Setup PHP and Composer" -phpbrew install -j 6 github:php/php-src@PHP-$version as php-$version +dev >/dev/null 2>&1 -phpbrew switch $version -sudo ln -sf /opt/phpbrew/php/php-$version/bin/* /usr/local/bin/ -sudo ln -sf /opt/phpbrew/php/php-$version/etc/php.ini /etc/php.ini -ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") -ext_dir=$(php -i | grep "extension_dir => /opt" | sed -e "s|.*=> s*||") -pecl config-set php_ini "$ini_file" >/dev/null 2>&1 -pear config-set php_ini "$ini_file" >/dev/null 2>&1 -sudo chmod 777 "$ini_file" -brew install composer >/dev/null 2>&1 - -add_log "$tick" "PHP" "Installed PHP$version" -add_log "$tick" "Composer" "Installed" - -add_extension() { - extension=$1 - install_command=$2 - prefix=$3 - if ! php -m | grep -i -q "$extension" && [ -e "$ext_dir/$extension.so" ]; then - echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" - elif php -m | grep -i -q "$extension"; then - add_log "$tick" "$extension" "Enabled" - elif ! php -m | grep -i -q "$extension"; then - exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null) - if [ "$exists" = "200" ]; then - ( - eval "$install_command" && \ - add_log "$tick" "$extension" "Installed and enabled" - ) || add_log "$cross" "$extension" "Could not install $extension on PHP$version" - else - if ! php -m | grep -i -q "$extension"; then - add_log "$cross" "$extension" "Could not find $extension for PHP$version on PECL" - fi - fi - fi -} \ No newline at end of file diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index e4d68bba..b3a78a36 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -27,7 +27,7 @@ add_extension() { add_log "$tick" "$extension" "Enabled" elif ! php -m | grep -i -q -w "$extension"; then exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null) - if [ "$exists" = "200" ]; then + if [ "$exists" = "200" ] || [[ "$extension" == "phalcon"* ]]; then ( eval "$install_command" && \ add_log "$tick" "$extension" "Installed and enabled" @@ -40,20 +40,11 @@ add_extension() { fi } -add_phalcon() { +# Function to remove extensions +remove_extension() { extension=$1 - sudo pecl install psr >/dev/null 2>&1 - brew install autoconf automake libtool >/dev/null 2>&1 - git clone https://github.com/phalcon/cphalcon.git >/dev/null 2>&1 - cd cphalcon || echo "could not cd" - git checkout "$(git branch -r | grep -E "origin/${extension: -1}\.\d\.x" | sort -r | head -n 1 | sed "s/ //g")" >/dev/null 2>&1 - sed -i '' 's/zend_ulong/ulong/' build/php7/64bits/phalcon.zep.c - sed -i '' 's/ulong/zend_ulong/' build/php7/64bits/phalcon.zep.c - cd build/php7/64bits && sudo phpize >/dev/null 2>&1 - sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-phalcon >/dev/null 2>&1 - sudo glibtoolize --force >/dev/null 2>&1 && sudo autoreconf >/dev/null 2>&1 - sudo make -i -j2 >/dev/null 2>&1 && sudo make install >/dev/null 2>&1 - echo "extension=phalcon.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled" + sudo sed -i '' "/$1/d" "$ini_file" + sudo rm -rf "$ext_dir"/"$1".so >/dev/null 2>&1 } # Function to setup PHP and composer diff --git a/src/scripts/gearman.sh b/src/scripts/ext/gearman.sh similarity index 100% rename from src/scripts/gearman.sh rename to src/scripts/ext/gearman.sh diff --git a/src/scripts/pcov.sh b/src/scripts/ext/pcov.sh similarity index 100% rename from src/scripts/pcov.sh rename to src/scripts/ext/pcov.sh diff --git a/src/scripts/ext/phalcon.ps1 b/src/scripts/ext/phalcon.ps1 new file mode 100644 index 00000000..977a7005 --- /dev/null +++ b/src/scripts/ext/phalcon.ps1 @@ -0,0 +1,27 @@ +Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateSet('phalcon3', 'phalcon4')] + [string] + $extension, + [Parameter(Position = 1, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $version +) +$tick = ([char]8730) +$domain = 'https://github.com' +$php_dir = 'C:\tools\php' +$ext_dir = $php_dir + '\ext' +$installed = Get-Php -Path $php_dir +$extension_version = $extension.substring($extension.Length - 1) +$nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" } +$match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" +$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 +Install-Phpextension psr -MinimumStability stable -Path $php_dir +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" \ No newline at end of file diff --git a/src/scripts/phalcon.sh b/src/scripts/ext/phalcon.sh similarity index 100% rename from src/scripts/phalcon.sh rename to src/scripts/ext/phalcon.sh diff --git a/src/scripts/ext/phalcon_darwin.sh b/src/scripts/ext/phalcon_darwin.sh new file mode 100644 index 00000000..bdd17d8e --- /dev/null +++ b/src/scripts/ext/phalcon_darwin.sh @@ -0,0 +1,16 @@ +extension=$1 +ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") +sudo pecl install psr +brew install autoconf automake libtool +git clone https://github.com/phalcon/cphalcon.git +cd cphalcon || echo "could not cd" +git checkout "$(git branch -r | grep -E "origin/${extension: -1}\.\d\.x" | sort -r | head -n 1 | sed "s/ //g")" +sed -i '' 's/zend_ulong/ulong/' build/php7/64bits/phalcon.zep.c +sed -i '' 's/ulong/zend_ulong/' build/php7/64bits/phalcon.zep.c +cd build/php7/64bits && sudo phpize +sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-phalcon +sudo glibtoolize --force +sudo autoreconf +sudo make -i -j6 +sudo make install +echo "extension=phalcon.so" >>"$ini_file" \ No newline at end of file diff --git a/src/scripts/xdebug.sh b/src/scripts/ext/xdebug.sh similarity index 100% rename from src/scripts/xdebug.sh rename to src/scripts/ext/xdebug.sh diff --git a/src/scripts/xdebug_darwin.sh b/src/scripts/ext/xdebug_darwin.sh similarity index 100% rename from src/scripts/xdebug_darwin.sh rename to src/scripts/ext/xdebug_darwin.sh diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index b18346c8..d22c3259 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -24,7 +24,7 @@ update_ppa() { fi } -# Function to setup extension +# Function to setup extensions add_extension() { extension=$1 install_command=$2 @@ -40,6 +40,16 @@ add_extension() { fi } +# Function to remove extensions +remove_extension() { + extension=$1 + if [ -e /etc/php/"$version"/mods-available/$1.ini ]; then + sudo phpdismod -v "$version" $1 + fi + sudo sed -i "/$1/d" "$ini_file" + sudo DEBIAN_FRONTEND=noninteractive apt-get remove php-$1 -y >/dev/null 2>&1 +} + # Function to setup the nightly build from master branch setup_master() { tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 5d67c86d..66e5849c 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -1,16 +1,16 @@ param ( - [Parameter(Mandatory = $true)][string]$version = "7.4", - [Parameter(Mandatory=$true)][string]$dir + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $version = '7.4', + [Parameter(Position = 1, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $dir ) -$tick = ([char]8730) -$cross = ([char]10007) -$php_dir = 'C:\tools\php' -$ext_dir = $php_dir + '\ext' -$ProgressPreference = 'SilentlyContinue' -$master_version = '8.0' -$arch='x64' - Function Step-Log($message) { printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message } @@ -20,49 +20,6 @@ Function Add-Log($mark, $subject, $message) { printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message } -Step-Log "Setup PhpManager" -Install-Module -Name PhpManager -Force -Scope CurrentUser -Add-Log $tick "PhpManager" "Installed" - -$installed = $null -if (Test-Path -LiteralPath $php_dir -PathType Container) { - try { - $installed = Get-Php -Path $php_dir - } - catch { - } -} -Step-Log "Setup PHP and Composer" -if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) { - if ($version -lt '7.0') { - Install-Module -Name VcRedist -Force - $arch='x86' - } - if ($version -eq $master_version) { - $version = 'master' - } - - Install-Php -Version $version -Architecture $arch -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 - $installed = Get-Php -Path $php_dir - $status = "Installed PHP $($installed.FullVersion)" -} -else { - $status = "PHP $($installed.FullVersion) Found" -} - -Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir -Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir -Update-PhpCAInfo -Path $php_dir -Source CurrentUser -Add-Log $tick "PHP" $status - -Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir -Add-Log $tick "Composer" "Installed" -if ($version -eq 'master') { - Copy-Item $dir"\..\src\ext\php_pcov.dll" -Destination $ext_dir"\php_pcov.dll" - Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir - Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir -} - Function Add-Extension { Param ( [Parameter(Position = 0, Mandatory = $true)] @@ -102,28 +59,70 @@ Function Add-Extension { } } -Function Add-Phalcon { +Function Remove-Extension() { Param ( [Parameter(Position = 0, Mandatory = $true)] [ValidateNotNull()] - [ValidateSet('phalcon3', 'phalcon4')] + [ValidateLength(1, [int]::MaxValue)] [string] $extension ) - $extension_version = $extension.substring($extension.Length - 1) - $nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" } - $domain = "https://github.com" - Install-Phpextension psr - try - { - $match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" - $zip_file = $match.Matches[0].Groups[1].Value - Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $PSScriptRoot\phalcon.zip - Expand-Archive -Path $PSScriptRoot\phalcon.zip -DestinationPath $PSScriptRoot\phalcon -Force > $null 2>&1 - New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $PSScriptRoot\phalcon\php_phalcon.dll > $null 2>&1 - Enable-PhpExtension -Extension phalcon -Path $php_dir - Add-Log $tick $extension "Installed and enabled" - } catch { - Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)" + if(php -m | findstr -i $extension) { + Disable-PhpExtension $extension $php_dir + } + if (Test-Path $ext_dir\php_$extension.dll) { + Remove-Item $ext_dir\php_$extension.dll } } + +# Variables +$tick = ([char]8730) +$cross = ([char]10007) +$php_dir = 'C:\tools\php' +$ext_dir = $php_dir + '\ext' +$ProgressPreference = 'SilentlyContinue' +$master_version = '8.0' +$arch='x64' + +Step-Log "Setup PhpManager" +Install-Module -Name PhpManager -Force -Scope CurrentUser +Add-Log $tick "PhpManager" "Installed" + +$installed = $null +if (Test-Path -LiteralPath $php_dir -PathType Container) { + try { + $installed = Get-Php -Path $php_dir + } + catch { + } +} +Step-Log "Setup PHP and Composer" +if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) { + if ($version -lt '7.0') { + Install-Module -Name VcRedist -Force + $arch='x86' + } + if ($version -eq $master_version) { + $version = 'master' + } + + Install-Php -Version $version -Architecture $arch -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 + $installed = Get-Php -Path $php_dir + $status = "Installed PHP $($installed.FullVersion)" +} +else { + $status = "PHP $($installed.FullVersion) Found" +} + +Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir +Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir +Update-PhpCAInfo -Path $php_dir -Source CurrentUser +if ($version -eq 'master') { + Copy-Item $dir"\..\src\bin\php_pcov.dll" -Destination $ext_dir"\php_pcov.dll" + Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir + Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir +} +Add-Log $tick "PHP" $status + +Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir +Add-Log $tick "Composer" "Installed" From de32d8b95f218204426f670bbf8cd19080676ae2 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 27 Dec 2019 06:56:49 +0530 Subject: [PATCH 04/11] Add tools support --- README.md | 41 ++++++-- __tests__/install.test.ts | 45 +++++---- __tests__/tools.test.ts | 61 ++++++++++++ __tests__/utils.test.ts | 6 +- action.yml | 8 +- dist/index.js | 204 ++++++++++++++++++++++++++++++++++---- src/config.ts | 4 +- src/install.ts | 15 +-- src/scripts/darwin.sh | 21 +++- src/scripts/linux.sh | 53 ++++------ src/scripts/win32.ps1 | 37 ++++++- src/tools.ts | 141 ++++++++++++++++++++++++++ src/utils.ts | 32 +++--- 13 files changed, 556 insertions(+), 112 deletions(-) create mode 100644 __tests__/tools.test.ts create mode 100644 src/tools.ts diff --git a/README.md b/README.md index 400e2b2c..e3150497 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support - [PHP Support](#tada-php-support) - [OS/Platform Support](#cloud-osplatform-support) -- [PHP Extension Support](#wrench-php-extension-support) +- [PHP Extension Support](#heavy_plus_sign-php-extension-support) +- [Tools Support](#wrench-tools-support) - [Coverage support](#signal_strength-coverage-support) - [Xdebug](#xdebug) - [PCOV](#pcov) @@ -60,13 +61,36 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support |Ubuntu 16.04|`ubuntu-16.04`| |macOS X Catalina 10.15|`macOS-latest` or `macOS-10.15`| -## :wrench: PHP Extension Support -- On `ubuntu` by default extensions which are available as a package can be installed. If the extension is not available as a package but it is on `PECL`, it can be installed by specifying `pecl: true`. +## :heavy_plus_sign: PHP Extension Support +- On `ubuntu` by default extensions which are available as a package can be installed. If the extension is not available as a package but it is on `PECL`, it can be installed by specifying `pecl` in the tools input. - On `windows` extensions which have `windows` binary on `PECL` can be installed. - On `macOS` extensions which are on `PECL` can be 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 interrupted. +## :wrench: Tools Support + +The following tools can be setup globally using the `tools` input + +- `php-cs-fixer` +- `phpcs` +- `phpcbf` +- `phpcpd` +- `phpstan` +- `phpmd` +- `codeception` +- `phpunit` +- `deployer` +- `prestissimo` +- `pecl` + +```yml +uses: shivammathur/setup-php@v1 +with: + php-version: '7.4' + tools: php-cs-fixer, phpunit +``` + ## :signal_strength: Coverage support ### Xdebug @@ -121,7 +145,7 @@ Inputs supported by this GitHub Action. - extensions `optional` - ini-values `optional` - coverage `optional` -- pecl `optional` +- tools `optional` See [action.yml](action.yml "Metadata for this GitHub Action") and usage below for more info. @@ -141,7 +165,7 @@ steps: extensions: mbstring, intl #optional, setup extensions ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration coverage: xdebug #optional, setup coverage driver - pecl: false #optional, setup PECL + tools: php-cs-fixer, phpunit #optional, setup tools globally ``` ### Matrix Setup @@ -168,7 +192,7 @@ jobs: extensions: mbstring, intl #optional, setup extensions ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration coverage: xdebug #optional, setup coverage driver - pecl: false #optional, setup PECL + tools: php-cs-fixer, phpunit #optional, setup tools globally ``` ### Experimental Setup @@ -191,7 +215,8 @@ steps: php-version: '8.0' extensions: mbstring #optional, setup extensions ini-values: opcache.jit_buffer_size=256M, opcache.jit=1235, pcre.jit=1 #optional, setup php.ini configuration - coverage: pcov #optional, setup PCOV, Xdebug does not support this version yet. + coverage: pcov #optional, setup PCOV, Xdebug does not support this version yet. + tools: php-cs-fixer, phpunit #optional, setup tools globally ``` ### Cache dependencies @@ -208,7 +233,7 @@ You can persist composer's internal cache directory using the [`action/cache`](h - name: Cache dependencies uses: actions/cache@v1 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/__tests__/install.test.ts b/__tests__/install.test.ts index 76616051..5c272af2 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -13,6 +13,11 @@ jest.mock('../src/install', () => ({ const extension_csv: string = process.env['extensions'] || ''; const ini_values_csv: string = process.env['ini-values'] || ''; const coverage_driver: string = process.env['coverage'] || ''; + let tools_csv: string = process.env['tools'] || ''; + const pecl: string = process.env['pecl'] || ''; + if (pecl == 'true') { + tools_csv = 'pecl, ' + tools_csv; + } let script = 'initial script ' + filename + version + os_version; if (extension_csv) { @@ -24,6 +29,9 @@ jest.mock('../src/install', () => ({ if (coverage_driver) { script += 'set coverage driver'; } + if (tools_csv) { + script += 'add_tool'; + } return script; } @@ -36,15 +44,10 @@ jest.mock('../src/install', () => ({ let script = ''; switch (os_version) { case 'darwin': + case 'linux': script = await install.build(os_version + '.sh', version, os_version); script += 'sh script.sh ' + version + ' ' + __dirname; break; - case 'linux': { - const pecl: string = process.env['pecl'] || ''; - script = await install.build(os_version + '.sh', version, os_version); - script += 'sh script.sh ' + version + ' ' + pecl + ' ' + __dirname; - break; - } case 'win32': script = await install.build(os_version + '.sh', version, os_version); script += 'pwsh script.ps1 ' + version + ' ' + __dirname; @@ -73,6 +76,7 @@ function setEnv( extension_csv: string, ini_values_csv: string, coverage_driver: string, + tools: string, pecl: string ): void { process.env['php-version'] = version.toString(); @@ -80,24 +84,25 @@ function setEnv( process.env['extensions'] = extension_csv; process.env['ini-values'] = ini_values_csv; process.env['coverage'] = coverage_driver; + process.env['tools'] = tools; process.env['pecl'] = pecl; } describe('Install', () => { it('Test install on windows', async () => { - setEnv('7.0', 'win32', '', '', '', ''); + setEnv('7.0', 'win32', '', '', '', '', ''); // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname); - setEnv('7.3', 'win32', '', '', '', ''); + setEnv('7.3', 'win32', '', '', '', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname); - setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', ''); + setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); @@ -108,39 +113,41 @@ describe('Install', () => { }); it('Test install on linux', async () => { - setEnv('7.3', 'linux', '', '', '', ''); + setEnv('7.3', 'linux', '', '', '', '', ''); // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('sh script.sh 7.3 '); - setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true'); + setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true'); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('install extensions'); expect(script).toContain('edit php.ini'); expect(script).toContain('set coverage driver'); - expect(script).toContain('sh script.sh 7.3 true'); + expect(script).toContain('sh script.sh 7.3'); + expect(script).toContain('add_tool'); - setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true'); + setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('install extensions'); expect(script).toContain('edit php.ini'); expect(script).toContain('set coverage driver'); - expect(script).toContain('sh script.sh 7.3 true'); + expect(script).toContain('sh script.sh 7.3'); + expect(script).toContain('add_tool'); }); it('Test install on darwin', async () => { - setEnv('7.3', 'darwin', '', '', '', ''); + setEnv('7.3', 'darwin', '', '', '', '', ''); // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('sh script.sh 7.3 ' + __dirname); - setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', ''); + setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); @@ -151,19 +158,19 @@ describe('Install', () => { }); it('Test malformed version inputs', async () => { - setEnv('7.4.1', 'darwin', '', '', '', ''); + setEnv('7.4.1', 'darwin', '', '', '', '', ''); // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('sh script.sh 7.4 ' + __dirname); - setEnv(8.0, 'darwin', '', '', '', ''); + setEnv(8.0, 'darwin', '', '', '', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); expect(script).toContain('sh script.sh 8.0 ' + __dirname); - setEnv(8, 'darwin', '', '', '', ''); + setEnv(8, 'darwin', '', '', '', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts new file mode 100644 index 00000000..debb2de9 --- /dev/null +++ b/__tests__/tools.test.ts @@ -0,0 +1,61 @@ +import * as tools from '../src/tools'; + +describe('Tools tests', () => { + it('checking getToolCommand', async () => { + expect(await tools.getToolCommand('linux')).toBe('add_tool '); + expect(await tools.getToolCommand('darwin')).toBe('add_tool '); + expect(await tools.getToolCommand('win32')).toBe('Add-Tool '); + expect(await tools.getToolCommand('fedora')).toContain( + 'Platform fedora is not supported' + ); + }); + + it('checking getPECLCommand', async () => { + expect(await tools.getPECLCommand('linux')).toBe('add_pecl '); + expect(await tools.getPECLCommand('darwin')).toBe('add_pecl '); + expect(await tools.getPECLCommand('win32')).toBe('Add-PECL '); + expect(await tools.getPECLCommand('fedora')).toContain( + 'Platform fedora is not supported' + ); + }); + + it('checking addTools', async () => { + let script: string = await tools.addTools( + 'php-cs-fixer, phpstan, phpunit, pecl', + 'linux' + ); + expect(script).toContain('add_tool https://getcomposer.org/composer.phar'); + expect(script).toContain( + 'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar' + ); + expect(script).toContain( + 'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar' + ); + expect(script).toContain('add_tool https://phar.phpunit.de/phpunit.phar'); + expect(script).toContain('add_pecl'); + + script = await tools.addTools('phpcs, phpcbf, phpcpd, phpmd', 'darwin'); + expect(script).toContain('add_tool https://getcomposer.org/composer.phar'); + expect(script).toContain( + 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar' + ); + expect(script).toContain( + 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar' + ); + expect(script).toContain( + 'add_tool https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar' + ); + expect(script).toContain( + 'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar' + ); + + script = await tools.addTools( + 'codeception, deployer, prestissimo, phpmd, does_not_exit', + 'win32' + ); + expect(script).toContain('Add-Tool https://getcomposer.org/composer.phar'); + expect(script).toContain('Add-Tool https://deployer.org/deployer.phar'); + expect(script).toContain('composer global require hirak/prestissimo'); + expect(script).toContain('Tool does_not_exit is not supported'); + }); +}); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 39aa3636..59dcb80e 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -87,13 +87,13 @@ describe('Utils tests', () => { }); it('checking INIArray', async () => { - expect(await utils.INIArray('a=1, b=2, c=3')).toEqual([ + expect(await utils.CSVArray('a=1, b=2, c=3')).toEqual([ 'a=1', 'b=2', 'c=3' ]); - expect(await utils.INIArray('')).toEqual([]); - expect(await utils.INIArray(' ')).toEqual([]); + expect(await utils.CSVArray('')).toEqual([]); + expect(await utils.CSVArray(' ')).toEqual([]); }); it('checking log', async () => { diff --git a/action.yml b/action.yml index 673c7e8b..70ab7a44 100644 --- a/action.yml +++ b/action.yml @@ -17,8 +17,8 @@ inputs: coverage: description: 'Setup code coverage driver.' required: false - pecl: - description: 'Setup PECL on ubuntu' + tools: + description: 'Setup popular tools globally.' required: false # Deprecated options, do not use. Will not be supported after February 1, 2020. extension-csv: @@ -29,6 +29,10 @@ inputs: description: 'Deprecated! Use ini-values instead.' deprecationMessage: 'The ini-values-csv property will not be supported after February 1, 2020. Use ini-values instead.' required: false + pecl: + description: 'Deprecated! Use tools instead to setup PECL.' + deprecationMessage: 'The pecl property will not be supported after February 1, 2020. Specify pecl in tools instead.' + required: false runs: using: 'node12' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index fdcdabc9..d7e4a7d6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1172,36 +1172,42 @@ function extensionArray(extension_csv) { case ' ': return []; default: - return extension_csv.split(',').map(function (extension) { + return extension_csv + .split(',') + .map(function (extension) { return extension .trim() .replace('php-', '') .replace('php_', ''); - }); + }) + .filter(Boolean); } }); } exports.extensionArray = extensionArray; /** - * Function to break ini values csv into an array + * Function to break csv into an array * - * @param ini_values_csv + * @param values_csv * @constructor */ -function INIArray(ini_values_csv) { +function CSVArray(values_csv) { return __awaiter(this, void 0, void 0, function* () { - switch (ini_values_csv) { + switch (values_csv) { case '': case ' ': return []; default: - return ini_values_csv.split(',').map(function (ini_value) { - return ini_value.trim(); - }); + return values_csv + .split(',') + .map(function (value) { + return value.trim(); + }) + .filter(Boolean); } }); } -exports.INIArray = INIArray; +exports.CSVArray = CSVArray; /** * Function to get prefix required to load an extension. * @@ -1524,6 +1530,165 @@ function getState(name) { exports.getState = getState; //# sourceMappingURL=core.js.map +/***/ }), + +/***/ 534: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const utils = __importStar(__webpack_require__(163)); +function getToolCommand(os_version) { + return __awaiter(this, void 0, void 0, function* () { + switch (os_version) { + case 'linux': + case 'darwin': + return 'add_tool '; + case 'win32': + return 'Add-Tool '; + default: + return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); + } + }); +} +exports.getToolCommand = getToolCommand; +function getPECLCommand(os_version) { + return __awaiter(this, void 0, void 0, function* () { + switch (os_version) { + case 'linux': + case 'darwin': + return 'add_pecl '; + case 'win32': + return 'Add-PECL '; + default: + return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); + } + }); +} +exports.getPECLCommand = getPECLCommand; +/** + * Setup tools + * + * @param tool_csv + * @param os_version + */ +function addTools(tools_csv, os_version) { + return __awaiter(this, void 0, void 0, function* () { + let script = yield utils.stepLog('Setup Tools', os_version); + let tools = yield utils.CSVArray(tools_csv); + tools = tools.filter(tool => tool !== 'composer'); + tools.unshift('composer'); + yield utils.asyncForEach(tools, function (tool) { + return __awaiter(this, void 0, void 0, function* () { + script += '\n'; + switch (tool) { + case 'php-cs-fixer': + script += + (yield getToolCommand(os_version)) + + 'https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar' + + ' ' + + 'php-cs-fixer'; + break; + case 'phpcs': + script += + (yield getToolCommand(os_version)) + + 'https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar' + + ' ' + + 'phpcs'; + break; + case 'phpcbf': + script += + (yield getToolCommand(os_version)) + + 'https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar' + + ' ' + + 'phpcbf'; + break; + case 'phpcpd': + script += + (yield getToolCommand(os_version)) + + 'https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar' + + ' ' + + 'phpcpd'; + break; + case 'phpstan': + script += + (yield getToolCommand(os_version)) + + 'https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar' + + ' ' + + 'phpstan'; + break; + case 'phpmd': + script += + (yield getToolCommand(os_version)) + + 'https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar' + + ' ' + + 'phpmd'; + break; + case 'composer': + script += + (yield getToolCommand(os_version)) + + 'https://getcomposer.org/composer.phar' + + ' ' + + 'composer'; + break; + case 'codeception': + script += + (yield getToolCommand(os_version)) + + 'https://codeception.com/codecept.phar' + + ' ' + + 'codeception'; + break; + case 'phpunit': + script += + (yield getToolCommand(os_version)) + + 'https://phar.phpunit.de/phpunit.phar' + + ' ' + + 'phpunit'; + break; + case 'deployer': + script += + (yield getToolCommand(os_version)) + + 'https://deployer.org/deployer.phar' + + ' ' + + 'deployer'; + break; + case 'prestissimo': + script += + 'composer global require hirak/prestissimo' + + (yield utils.suppressOutput(os_version)); + break; + case 'pecl': + script += yield getPECLCommand(os_version); + break; + default: + script += yield utils.log('Tool ' + tool + ' is not supported', os_version, 'error'); + break; + } + }); + }); + return script; + }); +} +exports.addTools = addTools; + + /***/ }), /***/ 614: @@ -1714,7 +1879,7 @@ const utils = __importStar(__webpack_require__(163)); */ function addINIValuesUnix(ini_values_csv) { return __awaiter(this, void 0, void 0, function* () { - const ini_values = yield utils.INIArray(ini_values_csv); + const ini_values = yield utils.CSVArray(ini_values_csv); let script = '\n'; yield utils.asyncForEach(ini_values, function (line) { return __awaiter(this, void 0, void 0, function* () { @@ -1733,7 +1898,7 @@ exports.addINIValuesUnix = addINIValuesUnix; */ function addINIValuesWindows(ini_values_csv) { return __awaiter(this, void 0, void 0, function* () { - const ini_values = yield utils.INIArray(ini_values_csv); + const ini_values = yield utils.CSVArray(ini_values_csv); let script = '\n'; yield utils.asyncForEach(ini_values, function (line) { return __awaiter(this, void 0, void 0, function* () { @@ -1812,6 +1977,7 @@ const core = __importStar(__webpack_require__(470)); const config = __importStar(__webpack_require__(641)); const coverage = __importStar(__webpack_require__(635)); const extensions = __importStar(__webpack_require__(911)); +const tools = __importStar(__webpack_require__(534)); const utils = __importStar(__webpack_require__(163)); const matchers = __importStar(__webpack_require__(86)); /** @@ -1829,7 +1995,11 @@ function build(filename, version, os_version) { const ini_values_csv = (yield utils.getInput('ini-values', false)) || (yield utils.getInput('ini-values-csv', false)); const coverage_driver = yield utils.getInput('coverage', false); - const setup_matchers = yield utils.getInput('matchers', false); + const pecl = yield utils.getInput('pecl', false); + let tools_csv = yield utils.getInput('tools', false); + if (pecl == 'true') { + tools_csv = 'pecl, ' + tools_csv; + } let script = yield utils.readScript(filename, version, os_version); if (extension_csv) { script += yield extensions.addExtension(extension_csv, version, os_version); @@ -1840,6 +2010,7 @@ function build(filename, version, os_version) { if (coverage_driver) { script += yield coverage.addCoverage(coverage_driver, version, os_version); } + script += yield tools.addTools(tools_csv, os_version); return yield utils.writeScript(filename, script); }); } @@ -1857,15 +2028,10 @@ function run() { let script_path = ''; switch (os_version) { case 'darwin': + case 'linux': script_path = yield build(os_version + '.sh', version, os_version); yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname); break; - case 'linux': { - const pecl = yield utils.getInput('pecl', false); - script_path = yield build(os_version + '.sh', version, os_version); - yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + pecl); - break; - } case 'win32': script_path = yield build('win32.ps1', version, os_version); yield exec_1.exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); diff --git a/src/config.ts b/src/config.ts index a8cfe4af..66c209ba 100644 --- a/src/config.ts +++ b/src/config.ts @@ -8,7 +8,7 @@ import * as utils from './utils'; export async function addINIValuesUnix( ini_values_csv: string ): Promise { - const ini_values: Array = await utils.INIArray(ini_values_csv); + const ini_values: Array = await utils.CSVArray(ini_values_csv); let script = '\n'; await utils.asyncForEach(ini_values, async function(line: string) { script += @@ -25,7 +25,7 @@ export async function addINIValuesUnix( export async function addINIValuesWindows( ini_values_csv: string ): Promise { - const ini_values: Array = await utils.INIArray(ini_values_csv); + const ini_values: Array = await utils.CSVArray(ini_values_csv); let script = '\n'; await utils.asyncForEach(ini_values, async function(line: string) { script += diff --git a/src/install.ts b/src/install.ts index c0b8f97f..eccc25d7 100644 --- a/src/install.ts +++ b/src/install.ts @@ -3,6 +3,7 @@ import * as core from '@actions/core'; import * as config from './config'; import * as coverage from './coverage'; import * as extensions from './extensions'; +import * as tools from './tools'; import * as utils from './utils'; import * as matchers from './matchers'; @@ -26,7 +27,11 @@ export async function build( (await utils.getInput('ini-values', false)) || (await utils.getInput('ini-values-csv', false)); const coverage_driver: string = await utils.getInput('coverage', false); - const setup_matchers: string = await utils.getInput('matchers', false); + const pecl: string = await utils.getInput('pecl', false); + let tools_csv: string = await utils.getInput('tools', false); + if (pecl == 'true') { + tools_csv = 'pecl, ' + tools_csv; + } let script: string = await utils.readScript(filename, version, os_version); if (extension_csv) { @@ -38,6 +43,7 @@ export async function build( if (coverage_driver) { script += await coverage.addCoverage(coverage_driver, version, os_version); } + script += await tools.addTools(tools_csv, os_version); return await utils.writeScript(filename, script); } @@ -54,15 +60,10 @@ export async function run(): Promise { let script_path = ''; switch (os_version) { case 'darwin': + case 'linux': script_path = await build(os_version + '.sh', version, os_version); await exec('sh ' + script_path + ' ' + version + ' ' + __dirname); break; - case 'linux': { - const pecl: string = await utils.getInput('pecl', false); - script_path = await build(os_version + '.sh', version, os_version); - await exec('sh ' + script_path + ' ' + version + ' ' + pecl); - break; - } case 'win32': script_path = await build('win32.ps1', version, os_version); await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index b3a78a36..d7421287 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -47,11 +47,27 @@ remove_extension() { sudo rm -rf "$ext_dir"/"$1".so >/dev/null 2>&1 } +# Function to setup a remote tool +add_tool() { + url=$1 + tool=$2 + if [ ! -e /usr/local/bin/"$tool" ]; then + rm -rf /usr/local/bin/"${tool:?}" + fi + sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1 + sudo chmod a+x /usr/local/bin/"$tool" + add_log "$tick" "$tool" "Added" +} + +add_pecl() { + add_log "$tick" "PECL" "Added" +} + # Function to setup PHP and composer setup_php_and_composer() { export HOMEBREW_NO_INSTALL_CLEANUP=TRUE brew tap shivammathur/homebrew-php >/dev/null 2>&1 - brew install shivammathur/php/php@"$version" composer >/dev/null 2>&1 + brew install shivammathur/php/php@"$version" >/dev/null 2>&1 brew link --force --overwrite php@"$version" >/dev/null 2>&1 } @@ -61,7 +77,7 @@ cross="✗" version=$1 # Setup PHP and composer -step_log "Setup PHP and Composer" +step_log "Setup PHP" setup_php_and_composer ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") echo "date.timezone=UTC" >> "$ini_file" @@ -70,4 +86,3 @@ 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" -add_log "$tick" "Composer" "Installed" diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index d22c3259..b65490c0 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -43,11 +43,23 @@ add_extension() { # Function to remove extensions remove_extension() { extension=$1 - if [ -e /etc/php/"$version"/mods-available/$1.ini ]; then - sudo phpdismod -v "$version" $1 + if [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then + sudo phpdismod -v "$version" "$extension" fi - sudo sed -i "/$1/d" "$ini_file" - sudo DEBIAN_FRONTEND=noninteractive apt-get remove php-$1 -y >/dev/null 2>&1 + sudo sed -i "/$extension/d" "$ini_file" + sudo DEBIAN_FRONTEND=noninteractive apt-get remove php-"$extension" -y >/dev/null 2>&1 +} + +# Function to setup a remote tool +add_tool() { + url=$1 + tool=$2 + if [ ! -e /usr/local/bin/"$tool" ]; then + rm -rf /usr/local/bin/"${tool:?}" + fi + sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1 + sudo chmod a+x /usr/local/bin/"$tool" + add_log "$tick" "$tool" "Added" } # Function to setup the nightly build from master branch @@ -64,30 +76,18 @@ setup_master() { } # Function to setup PECL -setup_pecl() { +add_pecl() { + update_ppa $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1 sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1 sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1 wget https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar >/dev/null 2>&1 sudo php install-pear-nozlib.phar >/dev/null 2>&1 + sudo rm -rf install-pear-nozlib.phar >/dev/null 2>&1 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 -} - -# Function to setup composer -setup_composer() { - if [ ! -e "/usr/bin/composer" ]; then - curl -s -L https://getcomposer.org/installer >composer-setup.php - if [ "$(curl -s https://composer.github.io/installer.sig)" != "$(php -r "echo hash_file('sha384', 'composer-setup.php');")" ]; then - echo >&2 'ERROR: Invalid installer signature' - else - export COMPOSER_ALLOW_SUPERUSER=1 - sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer - fi - rm composer-setup.php - fi - add_log "$tick" "Composer" "Installed" + add_log "$tick" "PECL" "Added" } # Function to switch versions of PHP binaries @@ -104,13 +104,12 @@ tick="✓" cross="✗" ppa_updated="false" version=$1 -pecl=$2 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 and Composer" +step_log "Setup PHP" sudo mkdir -p /var/run sudo mkdir -p /run/php @@ -150,13 +149,3 @@ ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") sudo chmod 777 "$ini_file" add_log "$tick" "PHP" "$status" - -# Setup PECL -if [ "$pecl" = "true" ]; then - update_ppa - setup_pecl - add_log "$tick" "PECL" "Installed" -fi - -# Setup composer -setup_composer diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 66e5849c..3e8bd4ca 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -75,6 +75,38 @@ Function Remove-Extension() { } } +# Function to setup a remote tool +Function Add-Tool() { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $url, + [Parameter(Position = 1, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $tool + ) + if (Test-Path $php_dir\$tool) { + Remove-Item $php_dir\$tool + } + Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1 + $bat_content = @() + $bat_content += "@ECHO off" + $bat_content += "setlocal DISABLEDELAYEDEXPANSION" + $bat_content += "SET BIN_TARGET=%~dp0/" + $tool + $bat_content += "php %BIN_TARGET% %*" + Set-Content -Path $php_dir\$tool.bat -Value $bat_content + Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat" + Add-Log $tick $tool "Added" +} + +Function Add-PECL() { + Add-Log $tick "PECL" "Use extensions input or Install-PhpExtension to setup PECL extensions on windows" +} + # Variables $tick = ([char]8730) $cross = ([char]10007) @@ -96,7 +128,7 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) { catch { } } -Step-Log "Setup PHP and Composer" +Step-Log "Setup PHP" if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) { if ($version -lt '7.0') { Install-Module -Name VcRedist -Force @@ -123,6 +155,3 @@ if ($version -eq 'master') { Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir } Add-Log $tick "PHP" $status - -Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir -Add-Log $tick "Composer" "Installed" diff --git a/src/tools.ts b/src/tools.ts new file mode 100644 index 00000000..41805e77 --- /dev/null +++ b/src/tools.ts @@ -0,0 +1,141 @@ +import * as utils from './utils'; + +export async function getToolCommand(os_version: string): Promise { + switch (os_version) { + case 'linux': + case 'darwin': + return 'add_tool '; + case 'win32': + return 'Add-Tool '; + default: + return await utils.log( + 'Platform ' + os_version + ' is not supported', + os_version, + 'error' + ); + } +} + +export async function getPECLCommand(os_version: string): Promise { + switch (os_version) { + case 'linux': + case 'darwin': + return 'add_pecl '; + case 'win32': + return 'Add-PECL '; + default: + return await utils.log( + 'Platform ' + os_version + ' is not supported', + os_version, + 'error' + ); + } +} + +/** + * Setup tools + * + * @param tool_csv + * @param os_version + */ +export async function addTools( + tools_csv: string, + os_version: string +): Promise { + let script = await utils.stepLog('Setup Tools', os_version); + let tools: Array = await utils.CSVArray(tools_csv); + tools = tools.filter(tool => tool !== 'composer'); + tools.unshift('composer'); + await utils.asyncForEach(tools, async function(tool: string) { + script += '\n'; + switch (tool) { + case 'php-cs-fixer': + script += + (await getToolCommand(os_version)) + + 'https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar' + + ' ' + + 'php-cs-fixer'; + break; + case 'phpcs': + script += + (await getToolCommand(os_version)) + + 'https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar' + + ' ' + + 'phpcs'; + break; + case 'phpcbf': + script += + (await getToolCommand(os_version)) + + 'https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar' + + ' ' + + 'phpcbf'; + break; + case 'phpcpd': + script += + (await getToolCommand(os_version)) + + 'https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar' + + ' ' + + 'phpcpd'; + break; + case 'phpstan': + script += + (await getToolCommand(os_version)) + + 'https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar' + + ' ' + + 'phpstan'; + break; + case 'phpmd': + script += + (await getToolCommand(os_version)) + + 'https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar' + + ' ' + + 'phpmd'; + break; + case 'composer': + script += + (await getToolCommand(os_version)) + + 'https://getcomposer.org/composer.phar' + + ' ' + + 'composer'; + break; + case 'codeception': + script += + (await getToolCommand(os_version)) + + 'https://codeception.com/codecept.phar' + + ' ' + + 'codeception'; + break; + case 'phpunit': + script += + (await getToolCommand(os_version)) + + 'https://phar.phpunit.de/phpunit.phar' + + ' ' + + 'phpunit'; + break; + case 'deployer': + script += + (await getToolCommand(os_version)) + + 'https://deployer.org/deployer.phar' + + ' ' + + 'deployer'; + break; + case 'prestissimo': + script += + 'composer global require hirak/prestissimo' + + (await utils.suppressOutput(os_version)); + break; + case 'pecl': + script += await getPECLCommand(os_version); + break; + default: + script += await utils.log( + 'Tool ' + tool + ' is not supported', + os_version, + 'error' + ); + break; + } + }); + + return script; +} diff --git a/src/utils.ts b/src/utils.ts index ec17b782..af305504 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -191,30 +191,36 @@ export async function extensionArray( case ' ': return []; default: - return extension_csv.split(',').map(function(extension: string) { - return extension - .trim() - .replace('php-', '') - .replace('php_', ''); - }); + return extension_csv + .split(',') + .map(function(extension: string) { + return extension + .trim() + .replace('php-', '') + .replace('php_', ''); + }) + .filter(Boolean); } } /** - * Function to break ini values csv into an array + * Function to break csv into an array * - * @param ini_values_csv + * @param values_csv * @constructor */ -export async function INIArray(ini_values_csv: string): Promise> { - switch (ini_values_csv) { +export async function CSVArray(values_csv: string): Promise> { + switch (values_csv) { case '': case ' ': return []; default: - return ini_values_csv.split(',').map(function(ini_value: string) { - return ini_value.trim(); - }); + return values_csv + .split(',') + .map(function(value: string) { + return value.trim(); + }) + .filter(Boolean); } } From 8e1cde2d0af6d8d3d38939fae7747d62579a5110 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sat, 28 Dec 2019 00:23:51 +0530 Subject: [PATCH 05/11] Improve examples and documentation --- README.md | 31 +++++++++++++++---------------- examples/bedrock.yml | 2 ++ examples/codeigniter.yml | 2 ++ examples/laravel-mysql.yml | 2 ++ examples/laravel-postgres.yml | 2 ++ examples/laravel.yml | 2 ++ examples/lumen-mysql.yml | 2 ++ examples/lumen-postgres.yml | 2 ++ examples/lumen.yml | 2 ++ examples/phalcon-mysql.yml | 4 ++++ examples/phalcon-postgres.yml | 4 ++++ examples/sage.yml | 2 ++ examples/slim-framework.yml | 2 ++ examples/symfony-mysql.yml | 7 ++++--- examples/symfony-postgres.yml | 7 ++++--- examples/symfony.yml | 7 ++++--- examples/yii2-mysql.yml | 2 ++ examples/yii2-postgres.yml | 2 ++ examples/zend-framework.yml | 2 ++ 19 files changed, 61 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index e3150497..63b0770c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ PHP Versions Supported

-Setup PHP with required extensions, php.ini configuration, code-coverage support and composer in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action gives you a cross platform interface to setup the PHP environment you need to test your application. Refer to [Usage](#memo-usage "How to use this") section and [examples](#examples "Examples of use") to see how to use this. +Setup PHP with required extensions, php.ini configuration, code-coverage support and tools like composer in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action gives you a cross platform interface to setup the PHP environment you need to test your application. Refer to [Usage](#memo-usage "How to use this") section and [examples](#examples "Examples of use") to see how to use this. ## Contents @@ -50,7 +50,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support |7.4|`Stable`|`Active`| |8.0|`Experimental`|`In development`| -**Note:** Specifying `8.0` in `php-version` input installs a nightly build of `PHP 8.0.0-dev` with `PHP JIT` support. See [experimental setup](#experimental-setup) for more information. +**Note:** Specifying `8.0` in `php-version` input installs a nightly build of `PHP 8.0.0-dev` with `PHP JIT`, `Union Types v2` and other [new features](https://wiki.php.net/rfc#php_80 "New features implemented in PHP 8"). See [experimental setup](#experimental-setup) for more information. ## :cloud: OS/Platform Support @@ -70,19 +70,9 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support ## :wrench: Tools Support -The following tools can be setup globally using the `tools` input +The latest version of the following tools can be setup globally using the `tools` input -- `php-cs-fixer` -- `phpcs` -- `phpcbf` -- `phpcpd` -- `phpstan` -- `phpmd` -- `codeception` -- `phpunit` -- `deployer` -- `prestissimo` -- `pecl` +`composer`, `codeception`, `deployer`, `pecl`, `phpcbf`, `phpcpd`, `php-cs-fixer`, `phpcs`, `phpmd`, `phpstan`, `phpunit`, `prestissimo` ```yml uses: shivammathur/setup-php@v1 @@ -91,6 +81,8 @@ with: tools: php-cs-fixer, phpunit ``` +**Note:** `composer` is setup by default, so that is not required to be specified. + ## :signal_strength: Coverage support ### Xdebug @@ -127,7 +119,7 @@ Specify `coverage: none` to disable both `Xdebug` and `PCOV`. Consider disabling the coverage using this PHP action for these reasons. - You are not generating coverage reports while testing. -- It will disable `Xdebug`, which will have a positive impact on PHP performance. +- It will remove `Xdebug`, which will have a positive impact on PHP performance. - You are using `phpdbg` for running your tests. ```yaml @@ -203,6 +195,7 @@ jobs: - `PECL` is installed by default with this version on `ubuntu`. - Some extensions might not support this version currently. - Refer to this [RFC](https://wiki.php.net/rfc/jit "PHP JIT RFC configuration") for configuring `PHP JIT` on this version. +- Refer to this [list of RFCs](https://wiki.php.net/rfc#php_80 "List of RFCs implemented in PHP8") implemented in this version. ```yaml steps: @@ -233,7 +226,7 @@ You can persist composer's internal cache directory using the [`action/cache`](h - name: Cache dependencies uses: actions/cache@v1 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- @@ -241,6 +234,12 @@ You can persist composer's internal cache directory using the [`action/cache`](h run: composer install --prefer-dist ``` +In the above example, if you support a range of `composer` dependencies and do not commit `composer.lock`, you can use the hash of `composer.json` as the key for your cache. + +```yml +key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} +``` + ### Problem Matchers You can setup problem matchers for your `PHPUnit` output. This will scan the errors in your tests and surface that information prominently in the GitHub Actions UI by creating annotations and log file decorations. diff --git a/examples/bedrock.yml b/examples/bedrock.yml index 658a1787..1e55d66b 100644 --- a/examples/bedrock.yml +++ b/examples/bedrock.yml @@ -22,6 +22,8 @@ jobs: - uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/codeigniter.yml b/examples/codeigniter.yml index 3f98f315..7c22bc1c 100644 --- a/examples/codeigniter.yml +++ b/examples/codeigniter.yml @@ -24,6 +24,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies diff --git a/examples/laravel-mysql.yml b/examples/laravel-mysql.yml index 7314bc94..12e0cd1c 100644 --- a/examples/laravel-mysql.yml +++ b/examples/laravel-mysql.yml @@ -48,6 +48,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/laravel-postgres.yml b/examples/laravel-postgres.yml index 1c9769bc..7a32dfa7 100644 --- a/examples/laravel-postgres.yml +++ b/examples/laravel-postgres.yml @@ -50,6 +50,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/laravel.yml b/examples/laravel.yml index c58146b2..b63f7a4c 100644 --- a/examples/laravel.yml +++ b/examples/laravel.yml @@ -26,6 +26,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/lumen-mysql.yml b/examples/lumen-mysql.yml index 8913834d..54849a38 100644 --- a/examples/lumen-mysql.yml +++ b/examples/lumen-mysql.yml @@ -48,6 +48,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/lumen-postgres.yml b/examples/lumen-postgres.yml index 5863c1a5..fc0146a5 100644 --- a/examples/lumen-postgres.yml +++ b/examples/lumen-postgres.yml @@ -50,6 +50,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/lumen.yml b/examples/lumen.yml index e187bdd8..64618dd6 100644 --- a/examples/lumen.yml +++ b/examples/lumen.yml @@ -26,6 +26,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/phalcon-mysql.yml b/examples/phalcon-mysql.yml index 88f8d821..cb126bfe 100644 --- a/examples/phalcon-mysql.yml +++ b/examples/phalcon-mysql.yml @@ -30,6 +30,8 @@ jobs: fail-fast: false matrix: php-versions: ['7.2', '7.3', '7.4'] + # For phalcon 3.x, use + # php-versions: ['7.0', '7.1', '7.2', '7.3'] steps: - name: Checkout uses: actions/checkout@v1 @@ -46,6 +48,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/phalcon-postgres.yml b/examples/phalcon-postgres.yml index 159888ab..c0f38965 100644 --- a/examples/phalcon-postgres.yml +++ b/examples/phalcon-postgres.yml @@ -31,6 +31,8 @@ jobs: fail-fast: false matrix: php-versions: ['7.2', '7.3', '7.4'] + # For phalcon 3.x, use + # php-versions: ['7.0', '7.1', '7.2', '7.3'] steps: - name: Checkout uses: actions/checkout@v1 @@ -47,6 +49,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/sage.yml b/examples/sage.yml index b22ae0f3..d37253d7 100644 --- a/examples/sage.yml +++ b/examples/sage.yml @@ -39,6 +39,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install yarn dependencies diff --git a/examples/slim-framework.yml b/examples/slim-framework.yml index 4ef37518..5ef36613 100644 --- a/examples/slim-framework.yml +++ b/examples/slim-framework.yml @@ -24,6 +24,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies diff --git a/examples/symfony-mysql.yml b/examples/symfony-mysql.yml index e5049359..95aba36c 100644 --- a/examples/symfony-mysql.yml +++ b/examples/symfony-mysql.yml @@ -28,6 +28,7 @@ jobs: php-version: ${{ matrix.php-versions }} extensions: mbstring, xml, ctype, iconv, mysql coverage: xdebug #optional + tools: phpunit - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -35,6 +36,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies @@ -48,6 +51,4 @@ jobs: env: DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony - name: Run Tests - run: | - composer require phpunit - php bin/phpunit --coverage-text \ No newline at end of file + run: phpunit --coverage-text \ No newline at end of file diff --git a/examples/symfony-postgres.yml b/examples/symfony-postgres.yml index aadf58b9..94aeb1fa 100644 --- a/examples/symfony-postgres.yml +++ b/examples/symfony-postgres.yml @@ -28,6 +28,7 @@ jobs: php-version: ${{ matrix.php-versions }} extensions: mbstring, xml, ctype, iconv, pgsql coverage: xdebug #optional + tools: phpunit - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -35,6 +36,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies @@ -48,6 +51,4 @@ jobs: env: DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?charset=UTF-8 - name: Run Tests - run: | - composer require phpunit - php bin/phpunit --coverage-text \ No newline at end of file + run: phpunit --coverage-text \ No newline at end of file diff --git a/examples/symfony.yml b/examples/symfony.yml index 75454992..169b74f1 100644 --- a/examples/symfony.yml +++ b/examples/symfony.yml @@ -19,6 +19,7 @@ jobs: php-version: ${{ matrix.php-versions }} extensions: mbstring, xml, ctype, iconv coverage: xdebug #optional + tools: phpunit - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -26,6 +27,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies @@ -33,6 +36,4 @@ jobs: composer require symfony/orm-pack composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader - name: Run Tests - run: | - composer require phpunit - php bin/phpunit --coverage-text \ No newline at end of file + run: phpunit --coverage-text \ No newline at end of file diff --git a/examples/yii2-mysql.yml b/examples/yii2-mysql.yml index 117a7797..ebb3b827 100644 --- a/examples/yii2-mysql.yml +++ b/examples/yii2-mysql.yml @@ -45,6 +45,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/yii2-postgres.yml b/examples/yii2-postgres.yml index 87c58f3a..03539b4b 100644 --- a/examples/yii2-postgres.yml +++ b/examples/yii2-postgres.yml @@ -45,6 +45,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies diff --git a/examples/zend-framework.yml b/examples/zend-framework.yml index 4858d350..c293aeb0 100644 --- a/examples/zend-framework.yml +++ b/examples/zend-framework.yml @@ -24,6 +24,8 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies From 6a70f864ec6a11f77a680cbaf4e22d68d5224cb1 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sat, 28 Dec 2019 00:42:00 +0530 Subject: [PATCH 06/11] Improve tools support --- README.md | 2 +- __tests__/tools.test.ts | 45 ++++++++++++++++++++++++++++------------- dist/index.js | 16 +++++++++++++-- src/scripts/darwin.sh | 12 +++++++---- src/scripts/win32.ps1 | 25 ++++++++++++++--------- src/tools.ts | 16 +++++++++++++-- 6 files changed, 83 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 63b0770c..414dfc36 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support The latest version of the following tools can be setup globally using the `tools` input -`composer`, `codeception`, `deployer`, `pecl`, `phpcbf`, `phpcpd`, `php-cs-fixer`, `phpcs`, `phpmd`, `phpstan`, `phpunit`, `prestissimo` +`composer`, `codeception`, `deployer`, `pecl`, `phinx`, `phpcbf`, `phpcpd`, `php-cs-fixer`, `phpcs`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `psalm` ```yml uses: shivammathur/setup-php@v1 diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index debb2de9..2add3b35 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -21,40 +21,57 @@ describe('Tools tests', () => { it('checking addTools', async () => { let script: string = await tools.addTools( - 'php-cs-fixer, phpstan, phpunit, pecl', + 'php-cs-fixer, phpstan, phpunit, pecl, phinx', 'linux' ); - expect(script).toContain('add_tool https://getcomposer.org/composer.phar'); expect(script).toContain( - 'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar' + 'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer' ); expect(script).toContain( - 'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar' + 'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer' + ); + expect(script).toContain( + 'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan' + ); + expect(script).toContain( + 'add_tool https://phar.phpunit.de/phpunit.phar phpunit' ); - expect(script).toContain('add_tool https://phar.phpunit.de/phpunit.phar'); expect(script).toContain('add_pecl'); + expect(script).toContain('composer global require robmorgan/phinx'); - script = await tools.addTools('phpcs, phpcbf, phpcpd, phpmd', 'darwin'); - expect(script).toContain('add_tool https://getcomposer.org/composer.phar'); - expect(script).toContain( - 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar' + script = await tools.addTools( + 'phpcs, phpcbf, phpcpd, phpmd, psalm', + 'darwin' ); expect(script).toContain( - 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar' + 'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer' ); expect(script).toContain( - 'add_tool https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar' + 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs' ); expect(script).toContain( - 'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar' + 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf' + ); + expect(script).toContain( + 'add_tool https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar phpcpd' + ); + expect(script).toContain( + 'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd' + ); + expect(script).toContain( + 'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm' ); script = await tools.addTools( 'codeception, deployer, prestissimo, phpmd, does_not_exit', 'win32' ); - expect(script).toContain('Add-Tool https://getcomposer.org/composer.phar'); - expect(script).toContain('Add-Tool https://deployer.org/deployer.phar'); + expect(script).toContain( + 'Add-Tool https://github.com/composer/composer/releases/latest/download/composer.phar composer' + ); + expect(script).toContain( + 'Add-Tool https://deployer.org/deployer.phar deployer' + ); expect(script).toContain('composer global require hirak/prestissimo'); expect(script).toContain('Tool does_not_exit is not supported'); }); diff --git a/dist/index.js b/dist/index.js index d7e4a7d6..f91b8883 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1591,7 +1591,7 @@ exports.getPECLCommand = getPECLCommand; */ function addTools(tools_csv, os_version) { return __awaiter(this, void 0, void 0, function* () { - let script = yield utils.stepLog('Setup Tools', os_version); + let script = '\n' + (yield utils.stepLog('Setup Tools', os_version)); let tools = yield utils.CSVArray(tools_csv); tools = tools.filter(tool => tool !== 'composer'); tools.unshift('composer'); @@ -1641,10 +1641,22 @@ function addTools(tools_csv, os_version) { ' ' + 'phpmd'; break; + case 'psalm': + script += + (yield getToolCommand(os_version)) + + 'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar' + + ' ' + + 'psalm'; + break; + case 'phinx': + script += + 'composer global require robmorgan/phinx' + + (yield utils.suppressOutput(os_version)); + break; case 'composer': script += (yield getToolCommand(os_version)) + - 'https://getcomposer.org/composer.phar' + + 'https://github.com/composer/composer/releases/latest/download/composer.phar' + ' ' + 'composer'; break; diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index d7421287..95b1ac95 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -51,11 +51,15 @@ remove_extension() { add_tool() { url=$1 tool=$2 - if [ ! -e /usr/local/bin/"$tool" ]; then - rm -rf /usr/local/bin/"${tool:?}" + if [ "$tool" = "composer" ]; then + brew install composer >/dev/null 2>&1 + else + if [ ! -e /usr/local/bin/"$tool" ]; then + rm -rf /usr/local/bin/"${tool:?}" + fi + sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1 + sudo chmod a+x /usr/local/bin/"$tool" fi - sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1 - sudo chmod a+x /usr/local/bin/"$tool" add_log "$tick" "$tool" "Added" } diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 3e8bd4ca..7e29f4ef 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -89,17 +89,22 @@ Function Add-Tool() { [string] $tool ) - if (Test-Path $php_dir\$tool) { - Remove-Item $php_dir\$tool + if($tool -eq "composer") { + Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir + } else { + if (Test-Path $php_dir\$tool) + { + Remove-Item $php_dir\$tool + } + Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1 + $bat_content = @() + $bat_content += "@ECHO off" + $bat_content += "setlocal DISABLEDELAYEDEXPANSION" + $bat_content += "SET BIN_TARGET=%~dp0/" + $tool + $bat_content += "php %BIN_TARGET% %*" + Set-Content -Path $php_dir\$tool.bat -Value $bat_content + Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat" } - Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1 - $bat_content = @() - $bat_content += "@ECHO off" - $bat_content += "setlocal DISABLEDELAYEDEXPANSION" - $bat_content += "SET BIN_TARGET=%~dp0/" + $tool - $bat_content += "php %BIN_TARGET% %*" - Set-Content -Path $php_dir\$tool.bat -Value $bat_content - Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat" Add-Log $tick $tool "Added" } diff --git a/src/tools.ts b/src/tools.ts index 41805e77..dfc3aa1d 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -42,7 +42,7 @@ export async function addTools( tools_csv: string, os_version: string ): Promise { - let script = await utils.stepLog('Setup Tools', os_version); + let script = '\n' + (await utils.stepLog('Setup Tools', os_version)); let tools: Array = await utils.CSVArray(tools_csv); tools = tools.filter(tool => tool !== 'composer'); tools.unshift('composer'); @@ -91,10 +91,22 @@ export async function addTools( ' ' + 'phpmd'; break; + case 'psalm': + script += + (await getToolCommand(os_version)) + + 'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar' + + ' ' + + 'psalm'; + break; + case 'phinx': + script += + 'composer global require robmorgan/phinx' + + (await utils.suppressOutput(os_version)); + break; case 'composer': script += (await getToolCommand(os_version)) + - 'https://getcomposer.org/composer.phar' + + 'https://github.com/composer/composer/releases/latest/download/composer.phar' + ' ' + 'composer'; break; From 7d026bfa6b5cc8dc3936c244d12836a04cb6a0db Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sat, 28 Dec 2019 02:18:01 +0530 Subject: [PATCH 07/11] Update symfony examples --- examples/symfony-mysql.yml | 5 ++--- examples/symfony-postgres.yml | 5 ++--- examples/symfony.yml | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/symfony-mysql.yml b/examples/symfony-mysql.yml index 95aba36c..eae1da31 100644 --- a/examples/symfony-mysql.yml +++ b/examples/symfony-mysql.yml @@ -26,9 +26,8 @@ jobs: uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, xml, ctype, iconv, mysql + extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql coverage: xdebug #optional - tools: phpunit - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -51,4 +50,4 @@ jobs: env: DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony - name: Run Tests - run: phpunit --coverage-text \ No newline at end of file + run: php bin/phpunit --coverage-text \ No newline at end of file diff --git a/examples/symfony-postgres.yml b/examples/symfony-postgres.yml index 94aeb1fa..77870058 100644 --- a/examples/symfony-postgres.yml +++ b/examples/symfony-postgres.yml @@ -26,9 +26,8 @@ jobs: uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, xml, ctype, iconv, pgsql + extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pgsql coverage: xdebug #optional - tools: phpunit - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -51,4 +50,4 @@ jobs: env: DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?charset=UTF-8 - name: Run Tests - run: phpunit --coverage-text \ No newline at end of file + run: php bin/phpunit --coverage-text \ No newline at end of file diff --git a/examples/symfony.yml b/examples/symfony.yml index 169b74f1..8158518b 100644 --- a/examples/symfony.yml +++ b/examples/symfony.yml @@ -17,9 +17,8 @@ jobs: uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, xml, ctype, iconv + extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite coverage: xdebug #optional - tools: phpunit - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -36,4 +35,4 @@ jobs: composer require symfony/orm-pack composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader - name: Run Tests - run: phpunit --coverage-text \ No newline at end of file + run: php bin/phpunit --coverage-text \ No newline at end of file From dd4f0db7bfc26f699ab386b4b1559942c752cd6f Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 29 Dec 2019 00:29:28 +0530 Subject: [PATCH 08/11] Update to latest version on windows. Fixes #132 --- src/scripts/win32.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 7e29f4ef..fc120837 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -144,13 +144,12 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version } Install-Php -Version $version -Architecture $arch -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 - $installed = Get-Php -Path $php_dir - $status = "Installed PHP $($installed.FullVersion)" } else { - $status = "PHP $($installed.FullVersion) Found" + Update-Php $php_dir >$null 2>&1 } +$installed = Get-Php -Path $php_dir Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir Update-PhpCAInfo -Path $php_dir -Source CurrentUser @@ -159,4 +158,4 @@ if ($version -eq 'master') { Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir } -Add-Log $tick "PHP" $status +Add-Log $tick "PHP" "Installed PHP $($installed.FullVersion)" From 3f42b7d5fb13a696c66e461f4e36aa2c2c7aac16 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Tue, 31 Dec 2019 04:26:18 +0530 Subject: [PATCH 09/11] Link tools installed using composer --- __tests__/tools.test.ts | 36 +++++++++++++++++++++++++++++-- dist/index.js | 33 +++++++++++++++++++++++++++-- src/tools.ts | 47 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 110 insertions(+), 6 deletions(-) diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 2add3b35..5904e05e 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -19,6 +19,24 @@ describe('Tools tests', () => { ); }); + it('checking linkTool', async () => { + expect(await tools.linkTool('tool', 'linux')).toContain( + 'sudo ln -s "$(composer -q global config home)"/vendor/bin/tool /usr/local/bin/tool' + ); + expect(await tools.linkTool('tool', 'darwin')).toContain( + 'sudo ln -s "$(composer -q global config home)"/vendor/bin/tool /usr/local/bin/tool' + ); + expect(await tools.linkTool('tool', 'win32')).toContain( + '$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}' + ); + expect(await tools.linkTool('tool', 'win32')).toContain( + 'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias tool $composer_dir\\vendor\\bin\\tool.bat"' + ); + expect(await tools.linkTool('tool', 'fedora')).toContain( + 'Platform fedora is not supported' + ); + }); + it('checking addTools', async () => { let script: string = await tools.addTools( 'php-cs-fixer, phpstan, phpunit, pecl, phinx', @@ -38,9 +56,12 @@ describe('Tools tests', () => { ); expect(script).toContain('add_pecl'); expect(script).toContain('composer global require robmorgan/phinx'); + expect(script).toContain( + 'sudo ln -s "$(composer -q global config home)"/vendor/bin/phinx /usr/local/bin/phinx' + ); script = await tools.addTools( - 'phpcs, phpcbf, phpcpd, phpmd, psalm', + 'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx', 'darwin' ); expect(script).toContain( @@ -61,9 +82,13 @@ describe('Tools tests', () => { expect(script).toContain( 'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm' ); + expect(script).toContain('composer global require robmorgan/phinx'); + expect(script).toContain( + 'sudo ln -s "$(composer -q global config home)"/vendor/bin/phinx /usr/local/bin/phinx' + ); script = await tools.addTools( - 'codeception, deployer, prestissimo, phpmd, does_not_exit', + 'codeception, deployer, prestissimo, phpmd, phinx, does_not_exit', 'win32' ); expect(script).toContain( @@ -73,6 +98,13 @@ describe('Tools tests', () => { 'Add-Tool https://deployer.org/deployer.phar deployer' ); expect(script).toContain('composer global require hirak/prestissimo'); + expect(script).toContain('composer global require robmorgan/phinx'); + expect(script).toContain( + '$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}' + ); + expect(script).toContain( + 'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias phinx $composer_dir\\vendor\\bin\\phinx.bat"' + ); expect(script).toContain('Tool does_not_exit is not supported'); }); }); diff --git a/dist/index.js b/dist/index.js index f91b8883..3e440052 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1583,6 +1583,29 @@ function getPECLCommand(os_version) { }); } exports.getPECLCommand = getPECLCommand; +function linkTool(tool, os_version) { + return __awaiter(this, void 0, void 0, function* () { + switch (os_version) { + case 'linux': + case 'darwin': + return ('sudo ln -s "$(composer -q global config home)"/vendor/bin/' + + tool + + ' /usr/local/bin/' + + tool); + case 'win32': + return ('$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}' + + '\n' + + 'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias ' + + tool + + ' $composer_dir\\vendor\\bin\\' + + tool + + '.bat"'); + default: + return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); + } + }); +} +exports.linkTool = linkTool; /** * Setup tools * @@ -1651,7 +1674,11 @@ function addTools(tools_csv, os_version) { case 'phinx': script += 'composer global require robmorgan/phinx' + - (yield utils.suppressOutput(os_version)); + (yield utils.suppressOutput(os_version)) + + '\n' + + (yield linkTool('phinx', os_version)) + + '\n' + + (yield utils.addLog('$tick', 'phinx', 'Added', os_version)); break; case 'composer': script += @@ -1684,7 +1711,9 @@ function addTools(tools_csv, os_version) { case 'prestissimo': script += 'composer global require hirak/prestissimo' + - (yield utils.suppressOutput(os_version)); + (yield utils.suppressOutput(os_version)) + + '\n' + + (yield utils.addLog('$tick', 'hirak/prestissimo', 'Added', os_version)); break; case 'pecl': script += yield getPECLCommand(os_version); diff --git a/src/tools.ts b/src/tools.ts index dfc3aa1d..7a3e97d0 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -32,6 +32,38 @@ export async function getPECLCommand(os_version: string): Promise { } } +export async function linkTool( + tool: string, + os_version: string +): Promise { + switch (os_version) { + case 'linux': + case 'darwin': + return ( + 'sudo ln -s "$(composer -q global config home)"/vendor/bin/' + + tool + + ' /usr/local/bin/' + + tool + ); + case 'win32': + return ( + '$composer_dir = composer -q global config home | % {$_ -replace "/", "\\"}' + + '\n' + + 'Add-Content -Path $PsHome\\profile.ps1 -Value "New-Alias ' + + tool + + ' $composer_dir\\vendor\\bin\\' + + tool + + '.bat"' + ); + default: + return await utils.log( + 'Platform ' + os_version + ' is not supported', + os_version, + 'error' + ); + } +} + /** * Setup tools * @@ -101,7 +133,11 @@ export async function addTools( case 'phinx': script += 'composer global require robmorgan/phinx' + - (await utils.suppressOutput(os_version)); + (await utils.suppressOutput(os_version)) + + '\n' + + (await linkTool('phinx', os_version)) + + '\n' + + (await utils.addLog('$tick', 'phinx', 'Added', os_version)); break; case 'composer': script += @@ -134,7 +170,14 @@ export async function addTools( case 'prestissimo': script += 'composer global require hirak/prestissimo' + - (await utils.suppressOutput(os_version)); + (await utils.suppressOutput(os_version)) + + '\n' + + (await utils.addLog( + '$tick', + 'hirak/prestissimo', + 'Added', + os_version + )); break; case 'pecl': script += await getPECLCommand(os_version); From 58fbc33c3a605cee88a81fd5c87857eb3c22892e Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Tue, 31 Dec 2019 05:46:33 +0530 Subject: [PATCH 10/11] Use tap shivammathur/homebrew-phalcon on darwin --- __tests__/extensions.test.ts | 4 ++-- dist/index.js | 2 ++ src/extensions.ts | 2 ++ src/scripts/ext/phalcon_darwin.sh | 19 ++++--------------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 61c41e2d..9a676cb9 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -80,10 +80,10 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install pcov'); darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); - expect(darwin).toContain('phalcon_darwin.sh phalcon3'); + expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0'); darwin = await extensions.addExtension('phalcon4', '7.3', 'darwin'); - expect(darwin).toContain('phalcon_darwin.sh phalcon4'); + expect(darwin).toContain('phalcon_darwin.sh phalcon4 7.3'); darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); expect(darwin).toContain('sudo pecl install pcov'); diff --git a/dist/index.js b/dist/index.js index 3e440052..8d996a67 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2362,6 +2362,8 @@ function addExtensionDarwin(extension_csv, version, pipe) { path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + ' ' + extension + + ' ' + + version + pipe; break; default: diff --git a/src/extensions.ts b/src/extensions.ts index 36583669..35ea232b 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -33,6 +33,8 @@ export async function addExtensionDarwin( path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + ' ' + extension + + ' ' + + version + pipe; break; default: diff --git a/src/scripts/ext/phalcon_darwin.sh b/src/scripts/ext/phalcon_darwin.sh index bdd17d8e..3ad34a6c 100644 --- a/src/scripts/ext/phalcon_darwin.sh +++ b/src/scripts/ext/phalcon_darwin.sh @@ -1,16 +1,5 @@ extension=$1 -ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") -sudo pecl install psr -brew install autoconf automake libtool -git clone https://github.com/phalcon/cphalcon.git -cd cphalcon || echo "could not cd" -git checkout "$(git branch -r | grep -E "origin/${extension: -1}\.\d\.x" | sort -r | head -n 1 | sed "s/ //g")" -sed -i '' 's/zend_ulong/ulong/' build/php7/64bits/phalcon.zep.c -sed -i '' 's/ulong/zend_ulong/' build/php7/64bits/phalcon.zep.c -cd build/php7/64bits && sudo phpize -sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-phalcon -sudo glibtoolize --force -sudo autoreconf -sudo make -i -j6 -sudo make install -echo "extension=phalcon.so" >>"$ini_file" \ No newline at end of file +extension_major=${extension: -1} +php_version=$2 +brew tap shivammathur/homebrew-phalcon +brew install phalcon@"$php_version"_"$extension_major" \ No newline at end of file From 1705daea72fb0b9c2f98c83af1bfba292f354ac1 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Tue, 31 Dec 2019 06:30:11 +0530 Subject: [PATCH 11/11] Bump version to 1.7.0 --- package-lock.json | 171 ++++++++++++++++++++++------------------------ package.json | 2 +- 2 files changed, 83 insertions(+), 90 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7fef2da4..8f32ec6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "setup-php", - "version": "1.6.2", + "version": "1.7.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -503,24 +503,24 @@ } }, "@types/jest": { - "version": "24.0.24", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.24.tgz", - "integrity": "sha512-vgaG968EDPSJPMunEDdZvZgvxYSmeH8wKqBlHSkBt1pV2XlLEVDzsj1ZhLuI4iG4Pv841tES61txSBF0obh4CQ==", + "version": "24.0.25", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.25.tgz", + "integrity": "sha512-hnP1WpjN4KbGEK4dLayul6lgtys6FPz0UfxMeMQCv0M+sTnzN3ConfiO72jHgLxl119guHgI8gLqDOrRLsyp2g==", "dev": true, "requires": { "jest-diff": "^24.3.0" } }, "@types/json-schema": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.3.tgz", - "integrity": "sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz", + "integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==", "dev": true }, "@types/node": { - "version": "12.12.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.21.tgz", - "integrity": "sha512-8sRGhbpU+ck1n0PGAUgVrWrWdjSW2aqNeyC15W88GRsMpSwzv6RJGlLhE7s2RhVSOdyDmxbqlWSeThq4/7xqlA==", + "version": "12.12.22", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.22.tgz", + "integrity": "sha512-r5i93jqbPWGXYXxianGATOxTelkp6ih/U0WVnvaqAvTqM+0U6J3kw6Xk6uq/dWNRkEVw/0SLcO5ORXbVNz4FMQ==", "dev": true }, "@types/normalize-package-data": { @@ -536,9 +536,9 @@ "dev": true }, "@types/yargs": { - "version": "13.0.3", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.3.tgz", - "integrity": "sha512-K8/LfZq2duW33XW/tFwEAfnZlqIfVsoyRB3kfXdPXYhl0nfM8mmh7GS0jg7WrX2Dgq/0Ha/pR1PaR+BvmWwjiQ==", + "version": "13.0.4", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.4.tgz", + "integrity": "sha512-Ke1WmBbIkVM8bpvsNEcGgQM70XcEh/nbpxQhW7FhrsbCsXSY9BmLB1+LHtD7r9zrsOcFlLiF+a/UeJsdfw3C5A==", "dev": true, "requires": { "@types/yargs-parser": "*" @@ -551,12 +551,12 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.12.0.tgz", - "integrity": "sha512-1t4r9rpLuEwl3hgt90jY18wJHSyb0E3orVL3DaqwmpiSDHmHiSspVsvsFF78BJ/3NNG3qmeso836jpuBWYziAA==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.14.0.tgz", + "integrity": "sha512-sneOJ3Hu0m5whJiVIxGBZZZMxMJ7c0LhAJzeMJgHo+n5wFs+/6rSR/gl7crkdR2kNwfOOSdzdc0gMvatG4dX2Q==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "2.12.0", + "@typescript-eslint/experimental-utils": "2.14.0", "eslint-utils": "^1.4.3", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", @@ -564,32 +564,32 @@ } }, "@typescript-eslint/experimental-utils": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.12.0.tgz", - "integrity": "sha512-jv4gYpw5N5BrWF3ntROvCuLe1IjRenLy5+U57J24NbPGwZFAjhnM45qpq0nDH1y/AZMb3Br25YiNVwyPbz6RkA==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.14.0.tgz", + "integrity": "sha512-KcyKS7G6IWnIgl3ZpyxyBCxhkBPV+0a5Jjy2g5HxlrbG2ZLQNFeneIBVXdaBCYOVjvGmGGFKom1kgiAY75SDeQ==", "dev": true, "requires": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "2.12.0", + "@typescript-eslint/typescript-estree": "2.14.0", "eslint-scope": "^5.0.0" } }, "@typescript-eslint/parser": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.12.0.tgz", - "integrity": "sha512-lPdkwpdzxEfjI8TyTzZqPatkrswLSVu4bqUgnB03fHSOwpC7KSerPgJRgIAf11UGNf7HKjJV6oaPZI4AghLU6g==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.14.0.tgz", + "integrity": "sha512-haS+8D35fUydIs+zdSf4BxpOartb/DjrZ2IxQ5sR8zyGfd77uT9ZJZYF8+I0WPhzqHmfafUBx8MYpcp8pfaoSA==", "dev": true, "requires": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "2.12.0", - "@typescript-eslint/typescript-estree": "2.12.0", + "@typescript-eslint/experimental-utils": "2.14.0", + "@typescript-eslint/typescript-estree": "2.14.0", "eslint-visitor-keys": "^1.1.0" } }, "@typescript-eslint/typescript-estree": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.12.0.tgz", - "integrity": "sha512-rGehVfjHEn8Frh9UW02ZZIfJs6SIIxIu/K1bbci8rFfDE/1lQ8krIJy5OXOV3DVnNdDPtoiPOdEANkLMrwXbiQ==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.14.0.tgz", + "integrity": "sha512-pnLpUcMNG7GfFFfNQbEX6f1aPa5fMnH2G9By+A1yovYI4VIOK2DzkaRuUlIkbagpAcrxQHLqovI1YWqEcXyRnA==", "dev": true, "requires": { "debug": "^4.1.1", @@ -729,13 +729,14 @@ "dev": true }, "array-includes": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.0.tgz", - "integrity": "sha512-ONOEQoKrvXPKk7Su92Co0YMqYO32FfqJTzkKU9u2UpIXyYZIzLSvpdg4AwvSw4mSUW0czu6inK+zby6Oj6gDjQ==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.1.tgz", + "integrity": "sha512-c2VXaCHl7zPsvpkFsw4nxvFie4fh1ur9bpcgsVkIjqn0H/Xwdg+7fv3n2r/isyS8EBj5b06M9kHyZuIr4El6WQ==", "dev": true, "requires": { "define-properties": "^1.1.3", - "es-abstract": "^1.17.0-next.0" + "es-abstract": "^1.17.0", + "is-string": "^1.0.5" } }, "array-unique": { @@ -1586,22 +1587,22 @@ } }, "es-abstract": { - "version": "1.17.0-next.1", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.0-next.1.tgz", - "integrity": "sha512-7MmGr03N7Rnuid6+wyhD9sHNE2n4tFSwExnU2lQl3lIo2ShXWGePY80zYaoMOmILWv57H0amMjZGHNzzGG70Rw==", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.0.tgz", + "integrity": "sha512-yYkE07YF+6SIBmg1MsJ9dlub5L48Ek7X0qz+c/CPCHS9EBXfESorzng4cJQjJW5/pB6vDF41u7F8vUhLVDqIug==", "dev": true, "requires": { "es-to-primitive": "^1.2.1", "function-bind": "^1.1.1", "has": "^1.0.3", "has-symbols": "^1.0.1", - "is-callable": "^1.1.4", - "is-regex": "^1.0.4", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", "object-inspect": "^1.7.0", "object-keys": "^1.1.1", "object.assign": "^4.1.0", - "string.prototype.trimleft": "^2.1.0", - "string.prototype.trimright": "^2.1.0" + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" } }, "es-to-primitive": { @@ -1643,9 +1644,9 @@ } }, "eslint": { - "version": "6.7.2", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.7.2.tgz", - "integrity": "sha512-qMlSWJaCSxDFr8fBPvJM9kJwbazrhNcBU3+DszDW1OlEwKBBRWsJc7NJFelvwQpanHCR14cOLD41x8Eqvo3Nng==", + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.8.0.tgz", + "integrity": "sha512-K+Iayyo2LtyYhDSYwz5D5QdWw0hCacNzyq1Y821Xna2xSJj7cijoLLYmLxTQgcgZ9mC61nryMy9S7GRbYpI5Ig==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -1696,9 +1697,9 @@ } }, "eslint-config-prettier": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.7.0.tgz", - "integrity": "sha512-FamQVKM3jjUVwhG4hEMnbtsq7xOIDm+SY5iBPfR8gKsJoAB2IQnNF+bk1+8Fy44Nq7PPJaLvkRxILYdJWoguKQ==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.9.0.tgz", + "integrity": "sha512-k4E14HBtcLv0uqThaI6I/n1LEqROp8XaPu6SO9Z32u5NlGRC07Enu1Bh2KEFw4FNHbekH8yzbIU9kUGxbiGmCA==", "dev": true, "requires": { "get-stdin": "^6.0.0" @@ -1806,9 +1807,9 @@ } }, "eslint-plugin-jest": { - "version": "23.1.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.1.1.tgz", - "integrity": "sha512-2oPxHKNh4j1zmJ6GaCBuGcb8FVZU7YjFUOJzGOPnl9ic7VA/MGAskArLJiRIlnFUmi1EUxY+UiATAy8dv8s5JA==", + "version": "23.2.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.2.0.tgz", + "integrity": "sha512-/jbCUW+g0jejXAvsytgcNhii6uEgolt0RO2e4+mhmXybfkcram5V3XIyrHCnUsb0vCmDKgHhJ1lYSm7F3VCEDA==", "dev": true, "requires": { "@typescript-eslint/experimental-utils": "^2.5.0" @@ -2287,14 +2288,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2309,20 +2308,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -2439,8 +2435,7 @@ "inherits": { "version": "2.0.4", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -2452,7 +2447,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2467,7 +2461,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2475,14 +2468,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.9.0", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2501,7 +2492,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2591,8 +2581,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -2604,7 +2593,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2726,7 +2714,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3286,9 +3273,9 @@ "dev": true }, "is-callable": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", - "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.5.tgz", + "integrity": "sha512-ESKv5sMCJB2jnHTWZ3O5itG+O128Hsus4K4Qh1h2/cgn2vbgnLSVqfV46AeJA9D5EeeLa9w81KUXMtn34zhX+Q==", "dev": true }, "is-ci": { @@ -3434,6 +3421,12 @@ "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", "dev": true }, + "is-string": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz", + "integrity": "sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==", + "dev": true + }, "is-symbol": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", @@ -4892,9 +4885,9 @@ } }, "psl": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.6.0.tgz", - "integrity": "sha512-SYKKmVel98NCOYXpkwUqZqh0ahZeeKfmisiLIcEZdsb+WbLv02g/dI5BUmZnIyOe7RzZtLax81nnb2HbvC2tzA==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.7.0.tgz", + "integrity": "sha512-5NsSEDv8zY70ScRnOTn7bK7eanl2MvFrOrS/R6x+dBt5g1ghnj9Zv90kO8GwT8gxcu2ANyFprnFYB85IogIJOQ==", "dev": true }, "pump": { @@ -5152,9 +5145,9 @@ "dev": true }, "rxjs": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.3.tgz", - "integrity": "sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", + "integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", "dev": true, "requires": { "tslib": "^1.9.0" @@ -5446,12 +5439,12 @@ "dev": true }, "source-map-resolve": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.2.tgz", - "integrity": "sha512-MjqsvNwyz1s0k81Goz/9vRBe9SZdB09Bdw+/zYyO+3CuPk6fouTaxscHkgtE8jKvf01kVfl8riHzERQ/kefaSA==", + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.3.tgz", + "integrity": "sha512-Htz+RnsXWk5+P2slx5Jh3Q66vhQj1Cllm0zvnaY98+NFx+Dv2CF/f5O/t8x+KaNdrdIAsruNzoh/KpialbqAnw==", "dev": true, "requires": { - "atob": "^2.1.1", + "atob": "^2.1.2", "decode-uri-component": "^0.2.0", "resolve-url": "^0.2.1", "source-map-url": "^0.4.0", @@ -6027,15 +6020,15 @@ "dev": true }, "typescript": { - "version": "3.7.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", - "integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==", + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", + "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==", "dev": true }, "uglify-js": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.7.2.tgz", - "integrity": "sha512-uhRwZcANNWVLrxLfNFEdltoPNhECUR3lc+UdJoG9CBpMcSnKyWA94tc3eAujB1GcMY5Uwq8ZMp4qWpxWYDQmaA==", + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.7.3.tgz", + "integrity": "sha512-7tINm46/3puUA4hCkKYo4Xdts+JDaVC9ZPRcG8Xw9R4nhO/gZgUM3TENq8IF4Vatk8qCig4MzP/c8G4u2BkVQg==", "dev": true, "optional": true, "requires": { diff --git a/package.json b/package.json index 8615419b..3e0404d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-php", - "version": "1.6.2", + "version": "1.7.0", "private": false, "description": "Setup PHP for use with GitHub Actions", "main": "dist/index.js",