-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DrupalTools\Drush\Commands; | ||
|
||
use ComposerLockParser\ComposerInfo; | ||
use Drupal\Component\DependencyInjection\ContainerInterface; | ||
use Drupal\helfi_api_base\Package\VersionChecker; | ||
use Drush\Attributes\Argument; | ||
use Drush\Attributes\Command; | ||
use Drush\Commands\DrushCommands; | ||
|
||
/** | ||
* A drush command to check whether given Helfi packages are up-to-date. | ||
*/ | ||
final class VersionDrushCommands extends DrushCommands { | ||
|
||
/** | ||
* Constructs a new instance. | ||
* | ||
* @param \Drupal\helfi_api_base\Package\VersionChecker $versionChecker | ||
* The version checker service. | ||
*/ | ||
public function __construct( | ||
private readonly VersionChecker $versionChecker, | ||
Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.2)
Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.2)
Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.2)
|
||
) { | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container): self { | ||
Check failure on line 33 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
Check failure on line 33 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.2)
|
||
return new static( | ||
$container->get('helfi_api_base.package_version_checker'), | ||
Check failure on line 35 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
|
||
); | ||
} | ||
|
||
/** | ||
* Checks whether Composer packages are up-to-date. | ||
* | ||
* @param string $file | ||
* The path to composer.lock file. | ||
* | ||
* @return int | ||
* The exit code. | ||
*/ | ||
#[Command(name: 'helfi:tools:check-composer-versions')] | ||
#[Argument(name: 'file', description: 'Path to composer.lock file')] | ||
public function checkVersions(string $file) : int { | ||
$info = new ComposerInfo($file); | ||
Check failure on line 51 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
|
||
|
||
$versions = []; | ||
/** @var \Composer\Package\Package $package */ | ||
foreach (iterator_to_array($info->getPackages()) as $package) { | ||
Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.2)
Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.2)
|
||
$version = $this->versionChecker->get($package->getName(), $package->getVersion()); | ||
Check failure on line 56 in src/Drush/Commands/VersionDrushCommands.php GitHub Actions / tests (8.1)
|
||
|
||
// Skip dev versions since we can't easily verify the latest | ||
// version. | ||
if (!$version || $version->isLatest || str_starts_with($package->getVersion(), 'dev-')) { | ||
continue; | ||
} | ||
$versions[] = [ | ||
'name' => $package->getName(), | ||
'currentVersion' => $package->getVersion(), | ||
'latestVersion' => $version->latestVersion, | ||
]; | ||
} | ||
if (!$versions) { | ||
return DrushCommands::EXIT_SUCCESS; | ||
} | ||
|
||
$this->io()->table( | ||
['Name', 'Version', 'Latest version'], | ||
$versions, | ||
); | ||
return DrushCommands::EXIT_FAILURE_WITH_CLARITY; | ||
} | ||
|
||
} |