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; - } -}