wiki.techinc.nl/maintenance/checkComposerLockUpToDate.php
Lucas Werkmeister 59504ca2eb checkComposerLockUpToDate: Don’t suggest --no-dev during tests
If we’re in a PHPUnit test run, we’ll need the dev dependencies
(otherwise PHPUnit itself will be missing), so it doesn’t make sense to
suggest --no-dev in that case IMHO.

Change-Id: If105e00870a37a4f39b8b88982ec259108bf81de
2024-07-31 14:20:27 +02:00

73 lines
2.4 KiB
PHP

<?php
require_once __DIR__ . '/Maintenance.php';
use MediaWiki\Composer\LockFileChecker;
use Wikimedia\Composer\ComposerJson;
use Wikimedia\Composer\ComposerLock;
/**
* Checks whether your composer-installed dependencies are up to date
*
* Composer creates a "composer.lock" file which specifies which versions are installed
* (via `composer install`). It has a hash, which can be compared to the value of
* the composer.json file to see if dependencies are up to date.
*/
class CheckComposerLockUpToDate extends Maintenance {
public function __construct() {
parent::__construct();
$this->addDescription(
'Checks whether your composer.lock file is up to date with the current composer.json' );
}
public function canExecuteWithoutLocalSettings(): bool {
return true;
}
public function execute() {
global $IP;
$lockLocation = "$IP/composer.lock";
$jsonLocation = "$IP/composer.json";
if ( !file_exists( $lockLocation ) ) {
// Maybe they're using mediawiki/vendor?
$lockLocation = "$IP/vendor/composer.lock";
if ( !file_exists( $lockLocation ) ) {
$this->fatalError(
'Could not find composer.lock file. Have you run "composer install --no-dev"?'
);
}
}
$lock = new ComposerLock( $lockLocation );
$json = new ComposerJson( $jsonLocation );
// Check all the dependencies to see if any are old
$checker = new LockFileChecker( $json, $lock );
$errors = $checker->check();
// NOTE: This is used by TestSetup before MediaWikiServices is initialized and thus
// may not rely on global singletons.
// NOTE: This is used by maintenance/update.php and thus may not rely on
// database connections, including e.g. interface messages without useDatabase=false,
// which would call MessageCache.
if ( $errors ) {
foreach ( $errors as $error ) {
$this->error( $error . "\n" );
}
$suggestedCommand = 'composer update';
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
$suggestedCommand .= ' --no-dev';
}
$this->fatalError(
'Error: your composer.lock file is not up to date. ' .
'Run "' . $suggestedCommand . '" to install newer dependencies'
);
} else {
// We couldn't find any out-of-date dependencies, so assume everything is ok!
$this->output( "Your composer.lock file is up to date with current dependencies!\n" );
}
}
}
$maintClass = CheckComposerLockUpToDate::class;
require_once RUN_MAINTENANCE_IF_MAIN;