Add --2.2 flag to self-update for 2.2 LTS as well as EOL marker support

main
Jordi Boggiano 2 years ago
parent b7d9beaa43
commit 956d44c339
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -59,6 +59,7 @@ class SelfUpdateCommand extends BaseCommand
new InputOption('snapshot', null, InputOption::VALUE_NONE, 'Force an update to the snapshot channel'),
new InputOption('1', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 1.x versions'),
new InputOption('2', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 2.x versions'),
new InputOption('2.2', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 2.2.x LTS versions'),
new InputOption('set-channel-only', null, InputOption::VALUE_NONE, 'Only store the channel as the default one and then exit'),
))
->setHelp(
@ -182,8 +183,12 @@ EOT
}
}
if ($requestedChannel && is_numeric($requestedChannel) && strpos($latestStable['version'], $requestedChannel) !== 0) {
$io->writeError('<warning>Warning: You forced the install of '.$latestVersion.' via --'.$requestedChannel.', but '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.</warning>');
$effectiveChannel = $requestedChannel === null ? $versionsUtil->getChannel() : $requestedChannel;
if (is_numeric($effectiveChannel) && strpos($latestStable['version'], $effectiveChannel) !== 0) {
$io->writeError('<warning>Warning: You forced the install of '.$latestVersion.' via --'.$effectiveChannel.', but '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.</warning>');
}
if (isset($latest['eol'])) {
$io->writeError('<warning>Warning: Version '.$latestVersion.' is EOL / End of Life. '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.</warning>');
}
if (Preg::isMatch('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {

@ -12,6 +12,7 @@
namespace Composer\SelfUpdate;
use Composer\Pcre\Preg;
use Composer\Util\HttpDownloader;
use Composer\Config;
@ -21,7 +22,7 @@ use Composer\Config;
class Versions
{
/** @var string[] */
public static $channels = array('stable', 'preview', 'snapshot', '1', '2');
public static $channels = array('stable', 'preview', 'snapshot', '1', '2', '2.2');
/** @var HttpDownloader */
private $httpDownloader;
@ -29,7 +30,7 @@ class Versions
private $config;
/** @var string */
private $channel;
/** @var array<string, array<int, array{path: string, version: string, min-php: int}>> */
/** @var array<string, array<int, array{path: string, version: string, min-php: int, eol?: true}>> */
private $versionsData;
public function __construct(Config $config, HttpDownloader $httpDownloader)
@ -50,7 +51,7 @@ class Versions
$channelFile = $this->config->get('home').'/update-channel';
if (file_exists($channelFile)) {
$channel = trim(file_get_contents($channelFile));
if (in_array($channel, array('stable', 'preview', 'snapshot'), true)) {
if (in_array($channel, array('stable', 'preview', 'snapshot', '2.2'), true)) {
return $this->channel = $channel;
}
}
@ -71,13 +72,14 @@ class Versions
$channelFile = $this->config->get('home').'/update-channel';
$this->channel = $channel;
file_put_contents($channelFile, (is_numeric($channel) ? 'stable' : $channel).PHP_EOL);
// rewrite '2' and '1' channels to stable for future self-updates, but LTS ones like '2.2' remain pinned
file_put_contents($channelFile, (Preg::isMatch('{^\d+$}D', $channel) ? 'stable' : $channel).PHP_EOL);
}
/**
* @param string|null $channel
*
* @return array{path: string, version: string, min-php: int}
* @return array{path: string, version: string, min-php: int, eol?: true}
*/
public function getLatest($channel = null)
{
@ -93,7 +95,7 @@ class Versions
}
/**
* @return array<string, array<int, array{path: string, version: string, min-php: int}>>
* @return array<string, array<int, array{path: string, version: string, min-php: int, eol?: true}>>
*/
private function getVersionsData()
{

Loading…
Cancel
Save