Skip to content

Commit

Permalink
Trigger composer task also when composer.lock changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vever001 committed Jun 12, 2024
1 parent 0106169 commit 3d53d2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Task/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ public function canRunInContext(ContextInterface $context): bool
public function run(ContextInterface $context): TaskResultInterface
{
$config = $this->getConfig()->getOptions();
$composerDir = pathinfo($config['file'], PATHINFO_DIRNAME);
$composerFile = pathinfo($config['file'], PATHINFO_BASENAME);
$composerLockFile = $this->getLockFile($composerFile);
$files = $context->getFiles()
->path(pathinfo($config['file'], PATHINFO_DIRNAME))
->name(pathinfo($config['file'], PATHINFO_BASENAME));
->path($composerDir)
->names([$composerFile, $composerLockFile]);
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}
Expand Down Expand Up @@ -116,4 +119,14 @@ private function hasLocalRepository(SplFileInfo $composerFile): bool

return false;
}

/**
* Verbatim copy from \Composer\Factory::getLockFile.
*/
private static function getLockFile(string $composerFile): string
{
return 'json' === pathinfo($composerFile, PATHINFO_EXTENSION)
? substr($composerFile, 0, -4) . 'lock'
: $composerFile . '.lock';
}
}
9 changes: 9 additions & 0 deletions test/Unit/Task/ComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ public function provideExternalTaskRuns(): iterable
'./composer.json',
]
];
yield 'lock-only' => [
[],
$this->mockContext(RunContext::class, ['composer.lock']),
'composer',
[
'validate',
'./composer.json',
]
];
yield 'no-check-all' => [
[
'no_check_all' => true,
Expand Down

0 comments on commit 3d53d2c

Please sign in to comment.