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('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('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', 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'), new InputOption('set-channel-only', null, InputOption::VALUE_NONE, 'Only store the channel as the default one and then exit'),
)) ))
->setHelp( ->setHelp(
@ -182,8 +183,12 @@ EOT
} }
} }
if ($requestedChannel && is_numeric($requestedChannel) && strpos($latestStable['version'], $requestedChannel) !== 0) { $effectiveChannel = $requestedChannel === null ? $versionsUtil->getChannel() : $requestedChannel;
$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>'); 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) { if (Preg::isMatch('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {

@ -12,6 +12,7 @@
namespace Composer\SelfUpdate; namespace Composer\SelfUpdate;
use Composer\Pcre\Preg;
use Composer\Util\HttpDownloader; use Composer\Util\HttpDownloader;
use Composer\Config; use Composer\Config;
@ -21,7 +22,7 @@ use Composer\Config;
class Versions class Versions
{ {
/** @var string[] */ /** @var string[] */
public static $channels = array('stable', 'preview', 'snapshot', '1', '2'); public static $channels = array('stable', 'preview', 'snapshot', '1', '2', '2.2');
/** @var HttpDownloader */ /** @var HttpDownloader */
private $httpDownloader; private $httpDownloader;
@ -29,7 +30,7 @@ class Versions
private $config; private $config;
/** @var string */ /** @var string */
private $channel; 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; private $versionsData;
public function __construct(Config $config, HttpDownloader $httpDownloader) public function __construct(Config $config, HttpDownloader $httpDownloader)
@ -50,7 +51,7 @@ class Versions
$channelFile = $this->config->get('home').'/update-channel'; $channelFile = $this->config->get('home').'/update-channel';
if (file_exists($channelFile)) { if (file_exists($channelFile)) {
$channel = trim(file_get_contents($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; return $this->channel = $channel;
} }
} }
@ -71,13 +72,14 @@ class Versions
$channelFile = $this->config->get('home').'/update-channel'; $channelFile = $this->config->get('home').'/update-channel';
$this->channel = $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 * @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) 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() private function getVersionsData()
{ {

Loading…
Cancel
Save