From 47f5b53be85e6ba3ae7d794ab51e33f11bc1182d Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 8 Mar 2020 11:21:51 +0530 Subject: [PATCH 1/2] Refactor install.sh --- .github/workflows/test.yml | 5 +++ install.sh | 80 +++++++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0632af5..26d0d20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,11 @@ on: push: branches: - master + - develop + pull_request: + branches: + - master + - develop jobs: run: runs-on: macos-latest diff --git a/install.sh b/install.sh index 500a0c2..09a0547 100644 --- a/install.sh +++ b/install.sh @@ -1,27 +1,55 @@ +version=$1 +php_version="php$version" +ini_file="/opt/local/etc/php$version/php.ini" +github_link="https://github.com/" +github_repo="$github_link/shivammathur/php5-darwin" +php_etc_dir="/opt/local/etc/php$version" +tmp_path="/tmp/php$version" export TERM=xterm -curl -o /tmp/php$1.tar.xz -sSL https://github.com/shivammathur/php5-darwin/releases/latest/download/php"$1".tar.xz -sudo tar xf /tmp/php$1.tar.xz -C /tmp -sudo installer -pkg /tmp/php$1/php$1.mpkg -target / -sudo cp /opt/local/etc/php$1/php.ini-development /opt/local/etc/php$1/php.ini -sudo mv /opt/local/bin/php$1 /opt/local/bin/php -sudo mv /opt/local/bin/phpize$1 /opt/local/bin/phpize -sudo mv /opt/local/bin/php-config$1 /opt/local/bin/php-config -sudo ln -sf /opt/local/bin/* /usr/local/bin -ext_dir=$(php -d "date.timezone=UTC" -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||") -ini_file=/opt/local/etc/php"$1"/php.ini -sudo chmod 777 "$ini_file" -echo "date.timezone=UTC" >>"$ini_file" -sudo mkdir -p $ext_dir -sudo cp -a /tmp/php$1/lib/* /opt/local/lib -sudo cp -a /tmp/php$1/ext/*.so $ext_dir -for bin in /tmp/php$1/ext/*.so; do - extension=$(basename $bin | cut -d'.' -f 1) - echo "extension=$extension.so" >>"$ini_file" -done -sudo installer -pkg /tmp/php$1/php$1-opcache.pkg -target / -pecl_version='master' -if [ "$1" = "53" ]; then - pecl_version='v1.9.5' -fi -sudo curl -o /tmp/pear.phar -sSL https://github.com/pear/pearweb_phars/raw/$pecl_version/install-pear-nozlib.phar -sudo php /tmp/pear.phar -d /opt/local/lib/php$1 -b /usr/local/bin \ No newline at end of file + +# Function to switch PHP version +switch_version() { + for tool in php phpize php-config; do + sudo mv /opt/local/bin/"$tool$version" /opt/local/bin/"$tool" + done + sudo ln -sf /opt/local/bin/* /usr/local/bin +} + +# Function to setup PHP +setup_php() { + curl -o "$tmp_path".tar.xz -sSL "$github_repo"/releases/latest/download/"$php_version".tar.xz + sudo tar xf "$tmp_path".tar.xz -C /tmp + sudo installer -pkg "$tmp_path"/"$php_version".mpkg -target / + sudo cp -a "$tmp_path"/lib/* /opt/local/lib + sudo cp "$php_etc_dir"/php.ini-development "$php_etc_dir"/php.ini + sudo chmod 777 "$ini_file" + echo "date.timezone=UTC" >>"$ini_file" +} + +# Function to add extensions +add_extensions() { + ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||") + sudo mkdir -p "$ext_dir" + sudo cp -a "$tmp_path"/ext/*.so "$ext_dir" + sudo installer -pkg "$tmp_path"/"$php_version"-opcache.pkg -target / + for bin in "$tmp_path"/ext/*.so; do + extension=$(basename "$bin" | cut -d'.' -f 1) + echo "extension=$extension.so" >>"$ini_file" + done +} + +# Function to add pear +add_pear() { + pecl_version='master' + if [ "$version" = "53" ]; then + pecl_version='v1.9.5' + fi + pear_github_repo="$github_link/pear/pearweb_phars" + sudo curl -o /tmp/pear.phar -sSL "$pear_github_repo/raw/$pecl_version/install-pear-nozlib.phar" + sudo php /tmp/pear.phar -d /opt/local/lib/"$php_version" -b /usr/local/bin +} + +setup_php +switch_version +add_extensions +add_pear \ No newline at end of file From 64515db74381777d1c35c03415dacb5480ae838c Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 8 Mar 2020 12:40:01 +0530 Subject: [PATCH 2/2] Improve workflow --- .github/workflows/test.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26d0d20..c3b2a5d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,8 +26,21 @@ jobs: bash install.sh ${version/./} - name: Testing PHP version run: | + php --ini php -v + phpize --version + php-config --version php -r "if(strpos(phpversion(), '${{ matrix.php-versions }}') === false) {throw new Exception('Wrong PHP version Installed');}" - - name: Testing + - name: Testing PHP extensions run: | - php -m \ No newline at end of file + php -m + version=${{ matrix.php-versions }} + for bin in /tmp/php"${version/./}"/ext/*.so; do + extension=$(basename "$bin" | cut -d'.' -f 1) + php -r "if(! extension_loaded('$extension')) {throw new Exception('$extension not found');}" + done + php -r "if(! extension_loaded('Zend OPcache')) {throw new Exception('Zend OPcache not found');}" + - name: Testing PECL version + run: pecl -V + - name: Testing SSL in file_get_contents + run: php -r "echo file_get_contents('https://repo.packagist.org/packages.json');" \ No newline at end of file