From 2ab1bd264d44f76239833b1e7830ca63c77e7a7e Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Thu, 5 Dec 2019 17:39:11 -0500 Subject: [PATCH 1/4] Bump the minimum version of PHP to 7.2 Since PHP 7.1 is now dead, we can remove it from the matrix and include PHP 7.4 in its place. As a bonus, we can upgrade to PHPUnit 8, which is nice. --- .gitignore | 3 ++- .travis.yml | 13 +++---------- composer.json | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 491c2c8..b2e1d05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock vendor -*.tgz \ No newline at end of file +*.tgz +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index 11cddda..0ed2e89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,17 @@ -sudo: true -dist: trusty language: php -notifications: - email: never - php: - - nightly + - 7.4snapshot - 7.3 - 7.2 - - 7.1 - - 7.0 matrix: fast_finish: true allow_failures: - - php: nightly + - php: 7.4snapshot install: - - composer install --prefer-dist + - composer install --prefer-dist --no-interactive before_script: - sudo mkdir -p "/etc/php/${TRAVIS_PHP_VERSION}/mods-available" diff --git a/composer.json b/composer.json index ee9da72..00ed0e5 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "source": "https://github.com/stevegrunwell/runkit7-installer" }, "require-dev": { - "php": "^7.1", - "phpunit/phpunit": ">=6.0" + "php": "^7.2", + "phpunit/phpunit": ">=8.0" }, "bin": [ "bin/install-runkit.sh" From 53550a470eab2e9f9fee07210c121a1f9118a97d Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Wed, 11 Dec 2019 13:18:13 -0500 Subject: [PATCH 2/4] s/interactive/interaction/ for Composer install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0ed2e89..7cd5ffa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ matrix: - php: 7.4snapshot install: - - composer install --prefer-dist --no-interactive + - composer install --prefer-dist --no-interaction before_script: - sudo mkdir -p "/etc/php/${TRAVIS_PHP_VERSION}/mods-available" From b3304d55e6e081e99f72a9420136721af93b4832 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Wed, 21 Oct 2020 14:37:13 -0400 Subject: [PATCH 3/4] Install different versions based on PHP version Runkit7 3.x only supports PHP 7.2 or higher, but earlier versions don't fully support PHP 7.4. This commit changes the script so that users may still specify a version but, if one isn't provided, the version will be selected based on the following: | PHP Version | Runkit7 Branch | | ----------- | -------------- | | 7.0 | 1.x | | 7.1 | 2.x | | 7.2+ | 3.x | Fixes #9. --- .github/workflows/tests.yml | 82 ++++++++++++++++++++++++++++++++++++ .travis.yml | 21 ---------- bin/install-runkit.sh | 83 +++++++++++++++++++++++++++++-------- composer.json | 7 +--- tests/InstallTest.php | 61 --------------------------- 5 files changed, 148 insertions(+), 106 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml delete mode 100644 tests/InstallTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..5aaa4ef --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,82 @@ +name: Tests + +on: + push: + branches: + - develop + - master + pull_request: + +jobs: + coding-standards: + name: Coding standards + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Shellcheck + uses: ludeeus/action-shellcheck@master + with: + scandir: './bin' + + test-installation-runkit7: + name: Test installation of runkit7 + runs-on: ubuntu-latest + strategy: + matrix: + php: [7.0, 7.1, 7.2, 7.3, 7.4] + fail-fast: true + + steps: + - uses: actions/checkout@v2 + + - name: Configure PHP environment + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: pecl + + - name: Create PEAR cache directory + run: | + sudo mkdir -p /tmp/pear/{cache,download,temp} + sudo chmod -R 777 /tmp/pear + pecl update-channels + + - name: Run the installation script + run: sudo sh bin/install-runkit.sh + + - name: Verify that runkit7 has been installed and activated + run: php -m | grep runkit + + test-installation-runkit: + name: Test installation of runkit + runs-on: ubuntu-latest + strategy: + matrix: + php: [5.6] + fail-fast: true + + steps: + - uses: actions/checkout@v2 + + - name: Configure PHP environment + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: pecl + + - name: Create PEAR cache directory + run: | + sudo mkdir -p /tmp/pear/{cache,download,temp} + sudo chmod -R 777 /tmp/pear + pecl update-channels + + - name: Run the installation script + run: sudo sh bin/install-runkit.sh + + - name: Verify that runkit has been installed and activated + run: php -m | grep runkit + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7cd5ffa..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php - -php: - - 7.4snapshot - - 7.3 - - 7.2 - -matrix: - fast_finish: true - allow_failures: - - php: 7.4snapshot - -install: - - composer install --prefer-dist --no-interaction - -before_script: - - sudo mkdir -p "/etc/php/${TRAVIS_PHP_VERSION}/mods-available" - -script: - - ./vendor/bin/phpunit - - shellcheck bin/*.sh diff --git a/bin/install-runkit.sh b/bin/install-runkit.sh index c6e095b..9c671a7 100755 --- a/bin/install-runkit.sh +++ b/bin/install-runkit.sh @@ -1,48 +1,95 @@ #!/usr/bin/env sh # # Automate the installation of Runkit7 in development and testing environments. +# +# USAGE: +# +# install-runkit.sh {version} +# +# If an explicit version is not provided, the latest version compatible with your PHP +# version will be installed. -# Enable users to set an explicit version. -[ "$1" ] && RUNKIT_VERSION=$1 || RUNKIT_VERSION="1.0.9" +# Helpers for printing messages with color. +error() { + printf "\\033[0;31m%s\\033[0;0m\\n" "$1" +} -DOWNLOAD_FILENAME="runkit-${RUNKIT_VERSION}.tgz" +notice() { + printf "\\033[0;33m%s\\033[0;0m\\n" "$1" +} # Download a Runkit7 tarball using either cURL or Wget (depending on environment). download() { echo "Downloading Runkit7 from ${1}" if [ "$(command -v curl)" ]; then - curl -sL "$1" > "$2"; + curl -sSL "$1" > "$2"; elif [ "$(command -v wget)" ]; then wget -nv -O "$2" "$1" else - echo "\\033[0;31mNo suitable download utility was found, unable to proceed!\\033[0;m" + error 'No suitable download utility was found, unable to proceed!' exit 1 fi } # Verify that PECL is installed. if [ ! "$(command -v pecl)" ]; then - echo "\\033[0;31mPECL (and, by extension, PEAR) is required in order to install Runkit7." - echo "Please see http://pear.php.net/manual/en/installation.getting.php for more information.\\033[0;m" + error 'PECL (and, by extension, PEAR) is required in order to install Runkit7. +Please see http://pear.php.net/manual/en/installation.getting.php for more information.' exit 1 fi -# Download and install Runkit7. -echo "\\033[0;33mInstalling Runkit7...\\033[0;m" -download "https://github.com/runkit7/runkit7/releases/download/${RUNKIT_VERSION}/runkit-${RUNKIT_VERSION}.tgz" "$DOWNLOAD_FILENAME" \ - && pecl install "$DOWNLOAD_FILENAME" \ - && rm "$DOWNLOAD_FILENAME" +PHP_MAJOR_VERSION="$(php -r "echo PHP_MAJOR_VERSION;")" +PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;") +EXTENSION="runkit7" + +# Enable users to set an explicit version. +if [ -n "$1" ]; then + RUNKIT_VERSION="runkit7-${1}" +elif [ "$PHP_MAJOR_VERSION" -lt 7 ]; then + RUNKIT_VERSION="runkit" + EXTENSION="runkit" +else + case "$PHP_VERSION" in + "7.0") + RUNKIT_VERSION="runkit7-1.0.11" + TARBALL="https://github.com/runkit7/runkit7/releases/download/1.0.11/runkit-1.0.11.tgz" + EXTENSION="runkit" + ;; + "7.1") + RUNKIT_VERSION="runkit7-3.1.0a1" + ;; + *) + RUNKIT_VERSION="runkit7-alpha" + ;; + esac +fi + +# Install runkit(7) via PECL. +notice "Installing ${RUNKIT_VERSION}..." + +# If we're using a tarball, download it and prepare PECL to install from the downloaded version. +if [ -n "$TARBALL" ]; then + download "$TARBALL" "${RUNKIT_VERSION}.tgz" + echo "> $ pecl install ${RUNKIT_VERSION}.tgz" + pecl install "$RUNKIT_VERSION.tgz" || exit 1 + rm "${RUNKIT_VERSION}.tgz" +else + echo "> $ pecl install ${RUNKIT_VERSION}" + pecl install "$RUNKIT_VERSION" || exit 1 +fi -# Create runkit.ini files for each version of PHP. -MODS=$(find /etc/php/ -name "mods-available" -type d) +# Create .ini files for each version of PHP. +MODS=$(find /etc/php/ -name "mods-available" -type d 2> /dev/null || echo '') for DIR in $MODS; do - if [ ! -f "$DIR/runkit.ini" ]; then - echo "extension=runkit.so" | sudo tee "$DIR/runkit.ini" > /dev/null \ - && echo "Created ${DIR}/runkit.ini" + if [ ! -f "${DIR}/${EXTENSION}.ini" ]; then + echo "extension=${EXTENSION}.so" | sudo tee "${DIR}/${EXTENSION}.ini" > /dev/null \ + && echo "Created ${DIR}/${EXTENSION}.ini" fi done # Attempt to enable the Runkit PHP module. if [ "$(command -v phpenmod)" ]; then - sudo phpenmod runkit && echo "\\033[0;32mRunkit7 has been installed and activated!\\033[0;0m" + sudo phpenmod "$EXTENSION" && echo "\\033[0;32m${EXTENSION} has been installed and activated!\\033[0;0m" +else + notice "${RUNKIT_VERSION} has been installed, but may require manual activation." fi diff --git a/composer.json b/composer.json index 00ed0e5..1a72206 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "stevegrunwell/runkit7-installer", - "description": "Installer for PHP Runkit7", + "description": "Installer for PHP's runkit and runkit7 extensions", "license": "MIT", "keywords": [ "runkit", @@ -9,7 +9,6 @@ "authors": [ { "name": "Steve Grunwell", - "email": "steve@stevegrunwell.com", "homepage": "https://stevegrunwell.com" } ], @@ -17,10 +16,6 @@ "issues": "https://github.com/stevegrunwell/runkit7-installer/issues", "source": "https://github.com/stevegrunwell/runkit7-installer" }, - "require-dev": { - "php": "^7.2", - "phpunit/phpunit": ">=8.0" - }, "bin": [ "bin/install-runkit.sh" ] diff --git a/tests/InstallTest.php b/tests/InstallTest.php deleted file mode 100644 index 39fcd8c..0000000 --- a/tests/InstallTest.php +++ /dev/null @@ -1,61 +0,0 @@ -assertFalse( - extension_loaded('runkit'), - 'Expected the Runkit extension to not yet be loaded.' - ); - - $version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION; - - exec(dirname(__DIR__) . '/bin/install-runkit.sh', $output, $exitCode); - - $this->assertEquals(0, $exitCode, 'Expected an exit code of 0:' . $this->quoteShellOutput($output)); - $this->assertTrue( - (bool) preg_match('/^runkit\s/m', shell_exec('pecl list')), - 'The Runkit extension should have been loaded.' - ); - $this->assertTrue( - file_exists('/etc/php/' . $version . '/mods-available/runkit.ini'), - 'Expected a runkit.ini file to be created for PHP ' . $version . '.' - ); - } - - /** - * @requires extension runkit - * @runInSeparateProcess - */ - public function testRunkitFunctionsAreAvailable() - { - $this->assertTrue(function_exists('runkit_constant_add')); - $this->assertTrue(function_exists('runkit_constant_remove')); - $this->assertTrue(function_exists('runkit_function_add')); - $this->assertTrue(function_exists('runkit_function_remove')); - } - - /** - * Quote the output of the shell script. - * - * @param array $output The output captured by exec(). - * - * @return string A string suitable for printing as a debug message. - */ - protected function quoteShellOutput(array $output): string - { - $result = array_reduce($output, function ($result, $line) { - return $result .= PHP_EOL . ' ' . $line; - }, ''); - - return PHP_EOL . "\033[0;36m$result\033[0;m" . PHP_EOL; - } -} From f3f0fc3b65d501d01ac7c946d9c3e08b23887850 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Sun, 22 Nov 2020 17:07:04 -0500 Subject: [PATCH 4/4] Changelog entry for 1.2.0 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac886aa..7737459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.2.0] — 2020-11-22 + +* Install different versions based on PHP version ([#10]). + + ## [1.1.1] - 2018-12-05 * Add PHP 7.3 support by [upgrading Runkit 7 to version 1.0.9](https://github.com/runkit7/runkit7/releases/tag/1.0.9) ([#8]). + ## [1.1.0] - 2018-06-27 * Attempt to automatically create `runkit.ini` files upon installation ([#1]). @@ -16,11 +22,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * Document that root access might be necessary to run the installer ([#3]). * Include [Shellcheck](https://www.shellcheck.net/) as part of the continuous integration process. + ## [1.0.0] - 2018-03-29 * Initial public release. + [Unreleased]: https://github.com/stevegrunwell/runkit7-installer/compare/master...develop +[1.2.0]: https://github.com/stevegrunwell/runkit7-installer/releases/tag/v1.2.0 [1.1.1]: https://github.com/stevegrunwell/runkit7-installer/releases/tag/v1.1.1 [1.1.0]: https://github.com/stevegrunwell/runkit7-installer/releases/tag/v1.1.0 [1.0.0]: https://github.com/stevegrunwell/runkit7-installer/releases/tag/v1.0.0 @@ -28,3 +37,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [#2]: https://github.com/stevegrunwell/runkit7-installer/issues/2 [#3]: https://github.com/stevegrunwell/runkit7-installer/issues/3 [#8]: https://github.com/stevegrunwell/runkit7-installer/pull/8 +[#10]: https://github.com/stevegrunwell/runkit7-installer/pull/10