Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php 74 for 4x #2662

Closed
wants to merge 9 commits into from
11 changes: 10 additions & 1 deletion .github/workflows/3x.yml → .github/workflows/4x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
run: composer install --dev
- name: Validate Code
run: composer code:lint
- name: Adjust dependencies for PHP 7.4
run: composer config platform.php 7.4.28
- name: Update dependencies
run: composer update
- name: Phar Build
run: |
mkdir $HOME/box
Expand All @@ -58,7 +62,7 @@ jobs:
strategy:
matrix:
operating-system: [ 'macos-latest' ]
php-versions: [ '8.2', '8.4' ]
php-versions: [ '7.4', '8.2', '8.4' ]
max-parallel: 1
env:
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
Expand Down Expand Up @@ -100,6 +104,11 @@ jobs:
uses: actions/download-artifact@v4
with:
name: terminus-phar
- name: Adjust dependencies for PHP 7.4, if necessary
if: ${{ matrix.php-versions == '7.4' }}
run: |
composer config platform.php 7.4.28
composer update
- name: Install Composer Dependencies
run: composer install --no-interaction --prefer-dist
- name: Setup tmate session
Expand Down
94 changes: 19 additions & 75 deletions bin/terminus
Original file line number Diff line number Diff line change
@@ -1,81 +1,25 @@
#!/usr/bin/env php
<?php
#!/usr/bin/env sh

/**
* This script runs Terminus. It does the following:
* - Includes the Composer autoload file
* - Starts a container with the input, output, application, and configuration objects
* - Starts a runner instance and runs the command
* - Exits with a status code
*/
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

// Unset memory limit
ini_set('memory_limit', -1);
TERMINUS_EXECUTABLE="$SCRIPTPATH/terminus.php"

if (version_compare(PHP_VERSION, '8.2.0', '<') === true) {
fwrite(STDERR, "\n");
fwrite(STDERR, 'Sorry, your PHP version (' . PHP_VERSION . ') is no longer supported.' . "\n");
fwrite(STDERR, 'Upgrade to PHP 8.2 or newer to use Terminus 4. For PHP versions prior to 8.2, downgrade to Terminus 3.x.' . "\n\n");
fwrite(STDERR, 'For more information, see https://pantheon.io/docs/terminus/updates#php-version-compatibility-matrix' . "\n\n");
exit(1);
}
# If we can't find `terminus.php` next to `terminus`,
# look for `terminus.php` in the same directory.
if [ ! -f "$TERMINUS_EXECUTABLE" ]; then
TERMINUS_EXECUTABLE="$SCRIPTPATH/terminus.phar"
fi

if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP') && version_compare(PHP_VERSION, '8.5.0', '>=') === true) {
fwrite(STDERR, "\n");
fwrite(STDERR, 'PHP 8.5+ is not supported by this version of Terminus.' . "\n");
fwrite(STDERR, 'Check for new versions at https://github.com/pantheon-systems/terminus/releases' . "\n");
fwrite(STDERR, "\n");
fwrite(STDERR, 'Set environment variable TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP to try continuing anyway.' . "\n");
fwrite(STDERR, "Stopping.\n\n");
exit(1);
}
# If there is no `terminus.phar` nearby, check for one
# in the $PATH.
if [ ! -f "$TERMINUS_EXECUTABLE" ]; then
TERMINUS_EXECUTABLE="terminus.phar"
fi

// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php,
// which is run after every call to composer update.
$terminusPluginsDependenciesVersion = '51e2c517dd';
# Use the PHP binary indicated by $TERMINUS_PHP, or use
# the one in the $PATH if $TERMINUS_PHP is not set.
PHP="${TERMINUS_PHP=php}"

// Cannot use $_SERVER superglobal since that's empty during phpunit testing
// getenv('HOME') isn't set on Windows and generates a Notice.
$home = @getenv('HOME');
if (!empty($home)) {
// home should never end with a trailing slash.
$home = rtrim($home, '/');
}

if (empty($home) && !empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) {
// home on windows
$home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
// If HOMEPATH is a root directory the path can end with a slash. Make sure
// that doesn't happen.
$home = rtrim($home, '\\/');
@putenv("HOME={$home}");
}

$pharPath = \Phar::running(true);
if ($pharPath) {
include_once("$pharPath/vendor/autoload.php");
} elseif (file_exists($path = __DIR__ . '/../vendor/autoload.php')
|| file_exists($path = __DIR__ . '/../../autoload.php')
|| file_exists($path = __DIR__ . '/../../../autoload.php')
) {
include_once($path);
} else {
throw new \Exception('Could not locate autoload.php');
}

use Pantheon\Terminus\Terminus;

$home_tokens_folder = '.terminus' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tokens';

$tokens_dir = $home . DIRECTORY_SEPARATOR . $home_tokens_folder;
if (!is_dir($tokens_dir)) {
mkdir(
$tokens_dir,
0700,
true
);
}

$terminus = Terminus::factory($terminusPluginsDependenciesVersion);
$status_code = $terminus->run();
exit($status_code);
# Run Terminus with the selected version of PHP, passing
# through all parameters.
exec "$TERMINUS_PHP" "$TERMINUS_EXECUTABLE" "$@"
86 changes: 86 additions & 0 deletions bin/terminus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env php
<?php

/**
* This script runs Terminus. It does the following:
* - Includes the Composer autoload file
* - Starts a container with the input, output, application, and configuration objects
* - Starts a runner instance and runs the command
* - Exits with a status code
*/

// Unset memory limit
ini_set('memory_limit', -1);

// Look up minimum PHP version from composer.json.
$composer_json_contents = file_get_contents(dirname(__DIR__) . '/composer.json');
$composer_json_data = json_decode($composer_json_contents, true);
$min_php_version = $composer_json_data['config']['platform']['php'];

if (version_compare(PHP_VERSION, $min_php_version, '<') === true) {
fwrite(STDERR, "\n");
fwrite(STDERR, 'Sorry, your PHP version (' . PHP_VERSION . ') is no longer supported.' . "\n");
fwrite(STDERR, 'Upgrade to PHP ' . $min_php_version . ' or newer to use Terminus 4. For prior PHP versions, downgrade to Terminus 3.x.' . "\n\n");
fwrite(STDERR, 'For more information, see https://pantheon.io/docs/terminus/updates#php-version-compatibility-matrix' . "\n\n");
exit(1);
}

if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP') && version_compare(PHP_VERSION, '8.5.0', '>=') === true) {
fwrite(STDERR, "\n");
fwrite(STDERR, 'PHP 8.5+ is not supported by this version of Terminus.' . "\n");
fwrite(STDERR, 'Check for new versions at https://github.com/pantheon-systems/terminus/releases' . "\n");
fwrite(STDERR, "\n");
fwrite(STDERR, 'Set environment variable TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP to try continuing anyway.' . "\n");
fwrite(STDERR, "Stopping.\n\n");
exit(1);
}

// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php,
// which is run after every call to composer update.
$terminusPluginsDependenciesVersion = '51e2c517dd';

// Cannot use $_SERVER superglobal since that's empty during phpunit testing
// getenv('HOME') isn't set on Windows and generates a Notice.
$home = @getenv('HOME');
if (!empty($home)) {
// home should never end with a trailing slash.
$home = rtrim($home, '/');
}

if (empty($home) && !empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) {
// home on windows
$home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
// If HOMEPATH is a root directory the path can end with a slash. Make sure
// that doesn't happen.
$home = rtrim($home, '\\/');
@putenv("HOME={$home}");
}

$pharPath = \Phar::running(true);
if ($pharPath) {
include_once("$pharPath/vendor/autoload.php");
} elseif (file_exists($path = __DIR__ . '/../vendor/autoload.php')
|| file_exists($path = __DIR__ . '/../../autoload.php')
|| file_exists($path = __DIR__ . '/../../../autoload.php')
) {
include_once($path);
} else {
throw new \Exception('Could not locate autoload.php');
}

use Pantheon\Terminus\Terminus;

$home_tokens_folder = '.terminus' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tokens';

$tokens_dir = $home . DIRECTORY_SEPARATOR . $home_tokens_folder;
if (!is_dir($tokens_dir)) {
mkdir(
$tokens_dir,
0700,
true
);
}

$terminus = Terminus::factory($terminusPluginsDependenciesVersion);
$status_code = $terminus->run();
exit($status_code);
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
]
},
"bin": [
"bin/terminus.php",
"bin/terminus"
],
"scripts": {
Expand Down Expand Up @@ -163,7 +164,7 @@
"preferred-install": "dist",
"sort-packages": true,
"platform": {
"php": "8.2.26"
"php": "7.4.28"
},
"allow-plugins": {
"phpstan/extension-installer": true
Expand Down
Loading
Loading