diff --git a/projects/packages/changelogger/changelog/fix-changelogger-amend-default-link b/projects/packages/changelogger/changelog/fix-changelogger-amend-default-link new file mode 100644 index 0000000000000..09dc0989a5b9c --- /dev/null +++ b/projects/packages/changelogger/changelog/fix-changelogger-amend-default-link @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +When amending, do not preserve a default link. We'll want the link to be updated to the new default. diff --git a/projects/packages/changelogger/src/WriteCommand.php b/projects/packages/changelogger/src/WriteCommand.php index 900167f64d328..1a23cbdf38090 100644 --- a/projects/packages/changelogger/src/WriteCommand.php +++ b/projects/packages/changelogger/src/WriteCommand.php @@ -412,7 +412,11 @@ protected function doAmendChanges( InputInterface $input, OutputInterface $outpu $input->setOption( 'epilogue', $latest->getEpilogue() ); } if ( $input->getOption( 'link' ) === null ) { - $input->setOption( 'link', $latest->getLink() ); + $oldLink = $latest->getLink(); + $defaultLink = $changelog->getLatestEntry() ? Config::link( $changelog->getLatestEntry()->getVersion(), $latest->getVersion() ) : null; + if ( $oldLink !== $defaultLink ) { + $input->setOption( 'link', $latest->getLink() ); + } } } else { $output->writeln( 'No version to amend, ignoring --amend.', OutputInterface::VERBOSITY_DEBUG ); diff --git a/projects/packages/changelogger/tests/php/tests/src/WriteCommandTest.php b/projects/packages/changelogger/tests/php/tests/src/WriteCommandTest.php index ebb2e105351a6..1ea6e7d0c1f6d 100644 --- a/projects/packages/changelogger/tests/php/tests/src/WriteCommandTest.php +++ b/projects/packages/changelogger/tests/php/tests/src/WriteCommandTest.php @@ -749,6 +749,54 @@ public function provideExecute() { true, "# Changelog\n\n## 1.0.1 - $date\n\nPrologue for v1.0.1\n\n### Added\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n", ), + 'Amend, beta to release' => array( + array( '--amend' => true ), + array( + 'composer.json' => array( 'link-template' => 'https://example.org/diff/${old}..${new}' ), + 'changes' => array(), + 'changelog' => "# Changelog\n\n## [1.0.1-beta] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1-beta]: https://example.org/new-link\n", + ), + array( 'Y' ), + 0, + array( + '{^No changes were found! Proceed\? \[y/N\] $}m', + ), + true, + "# Changelog\n\n## [1.0.1] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1]: https://example.org/new-link\n", + ), + 'Amend, ignore default link' => array( + array( '--amend' => true ), + array( + 'composer.json' => array( 'link-template' => 'https://example.org/diff/${old}..${new}' ), + 'changes' => array(), + 'changelog' => "# Changelog\n\n## [1.0.1-beta] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1-beta]: https://example.org/diff/1.0.0..1.0.1-beta\n", + ), + array( 'Y' ), + 0, + array( + '{^No changes were found! Proceed\? \[y/N\] $}m', + ), + true, + "# Changelog\n\n## [1.0.1] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1]: https://example.org/diff/1.0.0..1.0.1\n", + ), + 'Amend, manually override default link' => array( + array( + '--amend' => true, + '--link' => 'https://example.org/new-link', + ), + array( + 'composer.json' => array( 'link-template' => 'https://example.org/diff/${old}..${new}' ), + 'changes' => array(), + 'changelog' => "# Changelog\n\n## [1.0.1-beta] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1-beta]: https://example.org/diff/1.0.0..1.0.1-beta\n", + ), + array( 'Y' ), + 0, + array( + '{^No changes were found! Proceed\? \[y/N\] $}m', + ), + true, + "# Changelog\n\n## [1.0.1] - $date\n\nPrologue for v1.0.1\n\n### Added\n- New stuff.\n- Stuff.\n- ZZZ.\n\n### Removed\n- Other stuff.\n\n### Fixed\n- Broken stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.1]: https://example.org/new-link\n", + ), '--use-version invalid' => array( array( '--use-version' => '2.0' ), diff --git a/tools/cli/commands/build.js b/tools/cli/commands/build.js index 41d25232bf875..1e85a759326f9 100644 --- a/tools/cli/commands/build.js +++ b/tools/cli/commands/build.js @@ -612,6 +612,15 @@ async function buildProject( t ) { () => false ) ) { + // If we're building changelogger itself, we need to install before we can run it. + if ( t.project === 'packages/changelogger' ) { + await t.execa( 'composer', await getInstallArgs( t.project, 'composer', t.argv ), { + cwd: t.cwd, + stdio: [ 'ignore', 'inherit', 'inherit' ], + buffer: false, + } ); + } + let prerelease = 'alpha'; if ( composerJson.extra?.[ 'dev-releases' ] ) { const m = (