-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add option to run bump after update #11942
Changes from 4 commits
7328dec
1d13727
8f6427d
298e1d4
4467ba5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ protected function configure() | |
new InputOption('minimal-changes', 'm', InputOption::VALUE_NONE, 'During a partial update with -w/-W, only perform absolutely necessary changes to transitive dependencies (can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var).'), | ||
new InputOption('interactive', 'i', InputOption::VALUE_NONE, 'Interactive interface with autocompletion to select the packages to update.'), | ||
new InputOption('root-reqs', null, InputOption::VALUE_NONE, 'Restricts the update to your first degree dependencies.'), | ||
new InputOption('bump-after-update', null, InputOption::VALUE_OPTIONAL, 'Runs bump after performing the update.', false, ['dev', 'no-dev', 'all']), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using |
||
]) | ||
->setHelp( | ||
<<<EOT | ||
|
@@ -255,7 +256,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
$install->disablePlugins(); | ||
} | ||
|
||
return $install->run(); | ||
$result = $install->run(); | ||
|
||
if ($result === 0) { | ||
$bumpAfterUpdate = $input->getOption('bump-after-update'); | ||
if (false === $bumpAfterUpdate) { | ||
$bumpAfterUpdate = $composer->getConfig()->get('bump-after-update'); | ||
} | ||
|
||
if (false !== $bumpAfterUpdate) { | ||
$io->writeError('<info>Bumping dependencies</info>'); | ||
$bumpCommand = new BumpCommand(); | ||
$bumpCommand->setComposer($composer); | ||
$result = $bumpCommand->doBump( | ||
$io, | ||
$bumpAfterUpdate === 'dev', | ||
$bumpAfterUpdate === 'no-dev', | ||
$input->getOption('dry-run'), | ||
$input->getArgument('packages') | ||
); | ||
} | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,14 @@ class UpdateCommandTest extends TestCase | |
* @param array<mixed> $composerJson | ||
* @param array<mixed> $command | ||
*/ | ||
public function testUpdate(array $composerJson, array $command, string $expected): void | ||
public function testUpdate(array $composerJson, array $command, string $expected, bool $createLock = false): void | ||
{ | ||
$this->initTempComposer($composerJson); | ||
|
||
if ($createLock) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bump command needs that a lock file exists, so when testing the |
||
$this->createComposerLock(); | ||
} | ||
|
||
$appTester = $this->getApplicationTester(); | ||
$appTester->run(array_merge(['command' => 'update', '--dry-run' => true, '--no-audit' => true], $command)); | ||
|
||
|
@@ -126,6 +130,62 @@ public static function provideUpdates(): \Generator | |
Run `composer require root/req` or `composer require root/req:^2` instead to replace the constraint | ||
OUTPUT | ||
]; | ||
|
||
yield 'update & bump' => [ | ||
$rootDepAndTransitiveDep, | ||
['--bump-after-update' => true], | ||
<<<OUTPUT | ||
Loading composer repositories with package information | ||
Updating dependencies | ||
Lock file operations: 2 installs, 0 updates, 0 removals | ||
- Locking dep/pkg (1.0.2) | ||
- Locking root/req (1.0.0) | ||
Installing dependencies from lock file (including require-dev) | ||
Package operations: 2 installs, 0 updates, 0 removals | ||
- Installing dep/pkg (1.0.2) | ||
- Installing root/req (1.0.0) | ||
Bumping dependencies | ||
<warning>Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users.</warning> | ||
<warning>If your package is not a library, you can explicitly specify the "type" by using "composer config type project".</warning> | ||
<warning>Alternatively you can use the dev-only option to only bump dependencies within "require-dev".</warning> | ||
Seldaek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
No requirements to update in ./composer.json. | ||
OUTPUT | ||
, true | ||
]; | ||
|
||
yield 'update & bump dev only' => [ | ||
$rootDepAndTransitiveDep, | ||
['--bump-after-update' => 'dev'], | ||
<<<OUTPUT | ||
Loading composer repositories with package information | ||
Updating dependencies | ||
Lock file operations: 2 installs, 0 updates, 0 removals | ||
- Locking dep/pkg (1.0.2) | ||
- Locking root/req (1.0.0) | ||
Installing dependencies from lock file (including require-dev) | ||
Package operations: 2 installs, 0 updates, 0 removals | ||
- Installing dep/pkg (1.0.2) | ||
- Installing root/req (1.0.0) | ||
Bumping dependencies | ||
No requirements to update in ./composer.json. | ||
OUTPUT | ||
, true | ||
]; | ||
|
||
yield 'update & dump with failing update' => [ | ||
$rootDepAndTransitiveDep, | ||
['--with' => ['dep/pkg:^2'], '--bump-after-update' => true], | ||
<<<OUTPUT | ||
Loading composer repositories with package information | ||
Updating dependencies | ||
Your requirements could not be resolved to an installable set of packages. | ||
|
||
Problem 1 | ||
- Root composer.json requires root/req 1.* -> satisfiable by root/req[1.0.0]. | ||
- root/req 1.0.0 requires dep/pkg ^1 -> found dep/pkg[1.0.0, 1.0.1, 1.0.2] but it conflicts with your temporary update constraint (dep/pkg:^2). | ||
OUTPUT | ||
]; | ||
|
||
} | ||
|
||
public function testInteractiveModeThrowsIfNoPackageToUpdate(): void | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should use
enum
to restrict the supported strings