Skip to content

Commit

Permalink
changelogger: Support symfony/console 7.0 (#36861)
Browse files Browse the repository at this point in the history
When I tried using stub-generator from Packagist, it broke because it
wasn't actually compatible with symfony/console 7.0 (it needed
specification of a return type on a method). Turns out this is because
changelogger only specified working with up to 6.0, so 7.0 wasn't being
used when it should have been.

Fortunately all the changes are still more-or-less backwards compatible
all the way back to the 3.4 version we need for PHP 7.0 support. We wind
up having to specify the commands' names and descriptions twice now,
but 🤷.
  • Loading branch information
anomiex authored Apr 12, 2024
1 parent 08bd01b commit 3857d1d
Show file tree
Hide file tree
Showing 44 changed files with 204 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Support symfony/console 7.0.
4 changes: 2 additions & 2 deletions projects/packages/changelogger/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
],
"require": {
"php": ">=7.0",
"symfony/console": "^3.4 || ^4.4 || ^5.2 || ^6.0",
"symfony/process": "^3.4 || ^4.4 || ^5.2 || ^6.0"
"symfony/console": "^3.4 || ^4.4 || ^5.2 || ^6.0 || ^7.0",
"symfony/process": "^3.4 || ^4.4 || ^5.2 || ^6.0 || ^7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
Expand Down
13 changes: 11 additions & 2 deletions projects/packages/changelogger/src/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Automattic\Jetpack\Changelogger;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\MissingInputException;
use Symfony\Component\Console\Helper\QuestionHelper;
Expand All @@ -19,6 +20,7 @@
/**
* "Add" command for the changelogger tool CLI.
*/
#[AsCommand( 'add', 'Adds a change file' )]
class AddCommand extends Command {

/**
Expand Down Expand Up @@ -56,6 +58,13 @@ class AddCommand extends Command {
*/
protected static $defaultName = 'add';

/**
* The default command description
*
* @var string|null
*/
protected static $defaultDescription = 'Adds a change file';

/**
* Configures the command.
*/
Expand All @@ -73,7 +82,7 @@ function ( $k, $v ) {
);
};

$this->setDescription( 'Adds a change file' )
$this->setDescription( static::$defaultDescription )
->addOption( 'filename', 'f', InputOption::VALUE_REQUIRED, 'Name for the change file. If not provided, a default will be determined from the current timestamp or git branch name.' )
->addOption( 'filename-auto-suffix', null, InputOption::VALUE_NONE, 'If the specified file already exists in non-interactive mode, add a numeric suffix so the new entry can be created.' )
->addOption( 'significance', 's', InputOption::VALUE_REQUIRED, "Significance of the change, in the style of semantic versioning. One of the following:\n" . $joiner( self::$significances ) )
Expand Down Expand Up @@ -173,7 +182,7 @@ private function getQuestionHelper() {
* @param OutputInterface $output OutputInterface.
* @return int 0 if everything went fine, or an exit code.
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
protected function execute( InputInterface $input, OutputInterface $output ): int {
try {
$dir = Config::changesDir();
if ( ! is_dir( $dir ) ) {
Expand Down
4 changes: 2 additions & 2 deletions projects/packages/changelogger/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class Application extends SymfonyApplication {

const VERSION = '4.2.0';
const VERSION = '4.2.1-alpha';

/**
* Constructor.
Expand All @@ -36,7 +36,7 @@ public function __construct() {
* @param OutputInterface $output OutputInterface.
* @return int
*/
public function doRun( InputInterface $input, OutputInterface $output ) {
public function doRun( InputInterface $input, OutputInterface $output ): int {
$output->getFormatter()->setStyle( 'warning', new OutputFormatterStyle( 'black', 'yellow' ) );
// @phan-suppress-next-line PhanUndeclaredMethodInCallable,PhanUndeclaredMethod -- Being checked before being called.
$errout = is_callable( array( $output, 'getErrorOutput' ) ) ? $output->getErrorOutput() : $output;
Expand Down
13 changes: 11 additions & 2 deletions projects/packages/changelogger/src/SquashCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

use Automattic\Jetpack\Changelog\ChangeEntry;
use InvalidArgumentException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* "Squash" command for the changelogger tool CLI.
*/
#[AsCommand( 'squash', 'Squash changelog entries in the changelog file' )]
class SquashCommand extends WriteCommand {

/**
Expand All @@ -25,11 +27,18 @@ class SquashCommand extends WriteCommand {
*/
protected static $defaultName = 'squash';

/**
* The default command description
*
* @var string|null
*/
protected static $defaultDescription = 'Squash changelog entries in the changelog file';

/**
* Configures the command.
*/
protected function configure() {
$this->setDescription( 'Squash changelog entries in the changelog file' )
$this->setDescription( static::$defaultDescription )
->addOption( 'regex', null, InputOption::VALUE_REQUIRED, 'PCRE regex to match the versions to squash, including delimiters' )
->addOption( 'count', null, InputOption::VALUE_REQUIRED, 'Number of versions to squash' )
->addOption( 'use-version', null, InputOption::VALUE_REQUIRED, 'Use this version instead of determining the version automatically' )
Expand Down Expand Up @@ -132,7 +141,7 @@ protected function mergeChanges( array $a, array $b ) {
* @param OutputInterface $output OutputInterface.
* @return int 0 If everything went fine, or an exit code.
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
protected function execute( InputInterface $input, OutputInterface $output ): int {
try {
$this->formatter = Config::formatterPlugin();
$this->formatter->setIO( $input, $output );
Expand Down
13 changes: 11 additions & 2 deletions projects/packages/changelogger/src/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Automattic\Jetpack\Changelogger;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -16,6 +17,7 @@
/**
* "Validate" command for the changelogger tool CLI.
*/
#[AsCommand( 'validate', 'Validates changelog entry files' )]
class ValidateCommand extends Command {

/**
Expand All @@ -25,6 +27,13 @@ class ValidateCommand extends Command {
*/
protected static $defaultName = 'validate';

/**
* The default command description
*
* @var string|null
*/
protected static $defaultDescription = 'Validates changelog entry files';

/**
* The InputInterface to use.
*
Expand Down Expand Up @@ -57,7 +66,7 @@ class ValidateCommand extends Command {
* Configures the command.
*/
protected function configure() {
$this->setDescription( 'Validates changelog entry files' )
$this->setDescription( static::$defaultDescription )
->addOption( 'gh-action', null, InputOption::VALUE_NONE, 'Output validation issues using GitHub Action command syntax.' )
->addOption( 'basedir', null, InputOption::VALUE_REQUIRED, 'Output file paths in this directory relative to it.' )
->addOption( 'no-strict', null, InputOption::VALUE_NONE, 'Do not exit with a failure code if only warnings are found.' )
Expand Down Expand Up @@ -178,7 +187,7 @@ function ( $a, $b ) {
* @param OutputInterface $output OutputInterface.
* @return int 0 if everything went fine, or an exit code.
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
protected function execute( InputInterface $input, OutputInterface $output ): int {
$this->input = $input;
$this->output = $output;
$this->counts = array(
Expand Down
13 changes: 11 additions & 2 deletions projects/packages/changelogger/src/VersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Automattic\Jetpack\Changelogger;

use Automattic\Jetpack\Changelog\ChangeEntry;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,6 +18,7 @@
/**
* "Version" command for the changelogger tool CLI.
*/
#[AsCommand( 'version', 'Displays versions from the changelog and change files' )]
class VersionCommand extends Command {

/**
Expand All @@ -26,11 +28,18 @@ class VersionCommand extends Command {
*/
protected static $defaultName = 'version';

/**
* The default command description
*
* @var string|null
*/
protected static $defaultDescription = 'Displays versions from the changelog and change files';

/**
* Configures the command.
*/
protected function configure() {
$this->setDescription( 'Displays versions from the changelog and change files' )
$this->setDescription( static::$defaultDescription )
->addArgument( 'which', InputArgument::REQUIRED, 'Version to fetch: <info>previous</>, <info>current</>, or <info>next</>' )
->addOption( 'use-version', null, InputOption::VALUE_REQUIRED, 'When fetching the next version, use this instead of the current version in the changelog' )
->addOption( 'use-significance', null, InputOption::VALUE_REQUIRED, 'When fetching the next version, use this significance instead of using the actual change files' )
Expand Down Expand Up @@ -112,7 +121,7 @@ public static function getNextVersion( array $versions, array $changes, array $e
* @param OutputInterface $output OutputInterface.
* @return int 0 if everything went fine, or an exit code.
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
protected function execute( InputInterface $input, OutputInterface $output ): int {
try {
$formatter = Config::formatterPlugin();
$formatter->setIO( $input, $output );
Expand Down
13 changes: 11 additions & 2 deletions projects/packages/changelogger/src/WriteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Automattic\Jetpack\Changelog\ChangeEntry;
use Automattic\Jetpack\Changelog\Changelog;
use InvalidArgumentException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\MissingInputException;
use Symfony\Component\Console\Helper\QuestionHelper;
Expand All @@ -22,6 +23,7 @@
/**
* "Write" command for the changelogger tool CLI.
*/
#[AsCommand( 'write', 'Updates the changelog from change files' )]
class WriteCommand extends Command {

const OK_EXIT = 0;
Expand All @@ -37,6 +39,13 @@ class WriteCommand extends Command {
*/
protected static $defaultName = 'write';

/**
* The default command description
*
* @var string|null
*/
protected static $defaultDescription = 'Updates the changelog from change files';

/**
* The FormatterPlugin in use.
*
Expand All @@ -62,7 +71,7 @@ class WriteCommand extends Command {
* Configures the command.
*/
protected function configure() {
$this->setDescription( 'Updates the changelog from change files' )
$this->setDescription( static::$defaultDescription )
->addOption( 'amend', null, InputOption::VALUE_NONE, 'Amend the latest version instead of creating a new one' )
->addOption( 'yes', null, InputOption::VALUE_NONE, 'Default all questions to "yes" instead of "no". Particularly useful for non-interactive mode' )
->addOption( 'use-version', null, InputOption::VALUE_REQUIRED, 'Use this version instead of determining the version automatically' )
Expand Down Expand Up @@ -602,7 +611,7 @@ protected function nextVersion( InputInterface $input, OutputInterface $output,
* @param OutputInterface $output OutputInterface.
* @return int 0 If everything went fine, or an exit code.
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
protected function execute( InputInterface $input, OutputInterface $output ): int {
try {
$this->formatter = Config::formatterPlugin();
$this->formatter->setIO( $input, $output );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Properly support symfony/console 7.0.
9 changes: 1 addition & 8 deletions projects/packages/stub-generator/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ class Application extends SingleCommandApplication {
*/
private $exitCode = 0;

/**
* Default description.
*
* @var string
*/
protected static $defaultDescription = 'Generate stubs for specific functions/classes/etc from a codebase.';

/**
* Constructor.
*/
Expand Down Expand Up @@ -90,7 +83,7 @@ classes, and such to extract from each one. By default this should be a PHP
* @param OutputInterface $output OutputInterface.
* @return int 0 if everything went fine, or an exit code.
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
protected function execute( InputInterface $input, OutputInterface $output ): int {
$output->getFormatter()->setStyle( 'warning', new OutputFormatterStyle( 'black', 'yellow' ) );
// @phan-suppress-next-line PhanUndeclaredMethod,PhanUndeclaredMethodInCallable -- Phan doesn't recognize the `is_callable()` check.
$errout = is_callable( array( $output, 'getErrorOutput' ) ) ? $output->getErrorOutput() : $output;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


6 changes: 3 additions & 3 deletions projects/plugins/automattic-for-agencies-client/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/backup/changelog/update-symfony-console
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


6 changes: 3 additions & 3 deletions projects/plugins/backup/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/beta/changelog/update-symfony-console
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


6 changes: 3 additions & 3 deletions projects/plugins/beta/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/boost/changelog/update-symfony-console
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


6 changes: 3 additions & 3 deletions projects/plugins/boost/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/plugins/crm/changelog/update-symfony-console
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


Loading

0 comments on commit 3857d1d

Please sign in to comment.