diff options
author | Kunal Mehta <legoktm@gmail.com> | 2014-12-08 12:08:52 -0800 |
---|---|---|
committer | BryanDavis <bdavis@wikimedia.org> | 2014-12-29 23:20:30 +0000 |
commit | ce49874d9f71962a9a026b76162b93791e94fe3c (patch) | |
tree | 5b156e2eee8ec356541bbf1793a5700e356476b8 /maintenance | |
parent | 4051e77a3e41f4323206c2c836691c71106aeacf (diff) | |
download | mediawikicore-ce49874d9f71962a9a026b76162b93791e94fe3c.tar.gz mediawikicore-ce49874d9f71962a9a026b76162b93791e94fe3c.zip |
Add checkComposerLockUpToDate.php script
Checks whether your composer.lock file is up to date
with the current composer.json file.
Bug: T77388
Change-Id: I528d63172c238cf1ea9bc02e8eb39b93225865de
Diffstat (limited to 'maintenance')
-rw-r--r-- | maintenance/checkComposerLockUpToDate.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/maintenance/checkComposerLockUpToDate.php b/maintenance/checkComposerLockUpToDate.php new file mode 100644 index 000000000000..5ef2de6f24bc --- /dev/null +++ b/maintenance/checkComposerLockUpToDate.php @@ -0,0 +1,63 @@ +<?php + +require_once __DIR__ . '/Maintenance.php'; + +/** + * 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->mDescription = 'Checks whether your composer.lock file is up to date with the current composer.json'; + } + + 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->error( 'Could not find composer.lock file. Have you run "composer install"?', 1 ); + } + } + + $lock = new ComposerLock( $lockLocation ); + $json = new ComposerJson( $jsonLocation ); + + if ( $lock->getHash() === $json->getHash() ) { + $this->output( "Your composer.lock file is up to date with current dependencies!\n" ); + return; + } + // Out of date, lets figure out which dependencies are old + $found = false; + $installed = $lock->getInstalledDependencies(); + foreach ( $json->getRequiredDependencies() as $name => $version ) { + if ( isset( $installed[$name] ) ) { + if ( $installed[$name] !== $version ) { + $this->output( "$name: {$installed[$name]} installed, $version required.\n" ); + $found = true; + } + } else { + $this->output( "$name: not installed, $version required.\n" ); + $found = true; + } + } + if ( $found ) { + $this->error( 'Error: your composer.lock file is not up to date, run "composer update" to install newer dependencies', 1 ); + } else { + // The hash is the entire composer.json file, so it can be updated without any of the dependencies changing + // 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'; +require_once RUN_MAINTENANCE_IF_MAIN;
\ No newline at end of file |