Skip to content
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

UHF-9718: Command to check module versions #22

Merged
merged 17 commits into from
Feb 28, 2024
Merged
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ jobs:
container:
image: ghcr.io/city-of-helsinki/drupal-php-docker:${{ matrix.php-versions }}-alpine

services:
db:
image: mysql:8
env:
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: drupal
ports:
- 3306:3306

steps:
- uses: actions/checkout@v3
with:
Expand All @@ -22,7 +33,7 @@ jobs:
run: composer install

- name: Run PHPCS
run: vendor/bin/phpcs --ignore=*/vendor/* .
run: vendor/bin/phpcs --ignore=*/vendor/*,*/sut/* .

- name: Run phpstan
run: vendor/bin/phpstan analyze -c phpstan.neon .
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
vendor/
composer.lock
!tests/fixtures/composer.lock
tests/.phpunit.cache
tests/fixtures/schema
tests/coverage.xml
sut/core
sut/modules
31 changes: 30 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
"license": "GPL-2.0-or-later",
"minimum-stability": "dev",
"require": {
"drush/drush": "^11 || ^12"
"drupal/helfi_api_base": "*",
"drush/drush": "^11 || ^12 || ^13"
},
"require-dev": {
"composer/installers": "^2",
"drupal/core-recommended": "^10.2",
"drupal/core-dev": "^10.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"drupal/coder": "^8.3",
"phpspec/prophecy-phpunit": "^2",
Expand All @@ -27,12 +31,37 @@
"psr-4": {
"DrupalToolsTest\\": "tests/fixtures"
},
"classmap": [
"sut/core",
"sut/modules/contrib"
],
"files": [ "tests/fixtures/migration_fixture.php" ]
},
"repositories": {
"platform": {
"type": "composer",
"url": "https://repository.drupal.hel.ninja"
},
"drupal_org": {
"type": "composer",
"url": "https://packages.drupal.org/8"
}
},
"config": {
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"extra": {
"installer-paths": {
"sut/core": ["type:drupal-core"],
"sut/libraries/{$name}": ["type:drupal-library"],
"sut/modules/contrib/{$name}": ["type:drupal-module"],
"sut/profiles/contrib/{$name}": ["type:drupal-profile"],
"sut/themes/contrib/{$name}": ["type:drupal-theme"],
"sut/drush/contrib/{$name}": ["type:drupal-drush"]
}
}
}
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
paths:
- ./
excludePaths:
- sut
- vendor
- src/Drush/Commands/HelperDrushCommands.php
- src/Drush/Commands/OpenShiftDrushCommands.php
Expand Down
2 changes: 1 addition & 1 deletion src/Drush/Commands/HelperDrushCommands.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace DrupalTools\Drush\Commands;

Expand Down
2 changes: 1 addition & 1 deletion src/Drush/Commands/OpenShiftDrushCommands.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace DrupalTools\Drush\Commands;

Expand Down
85 changes: 85 additions & 0 deletions src/Drush/Commands/PackageScannerDrushCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

namespace DrupalTools\Drush\Commands;

use ComposerLockParser\ComposerInfo;
use Consolidation\AnnotatedCommand\CommandResult;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\Component\DependencyInjection\ContainerInterface;
use Drupal\helfi_api_base\Package\VersionChecker;
use Drush\Attributes\Argument;
use Drush\Attributes\Command;
use Drush\Attributes\FieldLabels;
use Drush\Commands\DrushCommands;

/**
* A drush command to check whether given Helfi packages are up-to-date.
*/
final class PackageScannerDrushCommands 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,
) {
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new self(
$container->get('helfi_api_base.package_version_checker'),
);
}

/**
* Checks whether Composer packages are up-to-date.
*
* @param string $file
* The path to composer.lock file.
* @param array $options
* The options.
*
* @return \Consolidation\AnnotatedCommand\CommandResult
* The result.
*/
#[Command(name: 'helfi:tools:check-composer-versions')]
#[Argument(name: 'file', description: 'Path to composer.lock file')]
#[FieldLabels(labels: [
'name' => 'Name',
'version' => 'Current version',
'latest' => 'Latest version',
])]
public function checkVersions(string $file, array $options = ['format' => 'table']) : CommandResult {
$info = new ComposerInfo($file);

$rows = [];
/** @var \Composer\Package\Package $package */
foreach (iterator_to_array($info->getPackages()) as $package) {
$version = $this->versionChecker->get($package->getName(), $package->getVersion());

// Skip dev versions since we can't easily verify the latest
// version.
if (!$version || $version->isLatest || str_starts_with($package->getVersion(), 'dev-')) {
continue;
}
$rows[] = [
'name' => $package->getName(),
'version' => $package->getVersion(),
'latest' => $version->latestVersion,
];
}

$exitCode = $rows ? DrushCommands::EXIT_FAILURE_WITH_CLARITY : DrushCommands::EXIT_SUCCESS;

return CommandResult::dataWithExitCode(new RowsOfFields($rows), $exitCode);
}

}
Loading
Loading