Created
February 21, 2017 05:12
-
-
Save robbieaverill/cad0260414226645b404c45b2059fdf9 to your computer and use it in GitHub Desktop.
A VERY quick and rough tool to check your project for SilverStripe upgradability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Test (roughly) your SilverStripe 4 upgradability. Ensure you run "composer require composer/semver" first. | |
* | |
* @author Robbie Averill <[email protected]> | |
*/ | |
require_once __DIR__ . '/vendor/autoload.php'; | |
use Composer\Semver\Semver; | |
$composerConfig = @file_get_contents(__DIR__ . '/composer.json'); | |
if ($composerConfig === false || !json_decode($composerConfig)) { | |
echo 'composer.json not found or invalid. Please run this from your project root.', PHP_EOL; | |
exit(1); | |
} | |
$composerConfig = json_decode($composerConfig); | |
echo 'Checking your dependencies for SilverStripe 4 compatibility...', PHP_EOL; | |
$results = [ | |
'pass' => 0, | |
'fail' => 0, | |
'skipped' => 0 | |
]; | |
foreach ($composerConfig->require as $package => $constraint) { | |
echo ' * Testing ' . $package . '... '; | |
if (in_array($package, ['silverstripe/framework', 'silverstripe/cms'])) { | |
$results['pass']++; | |
echo 'Pass.', PHP_EOL; | |
continue; | |
} | |
$result = @file_get_contents('https://packagist.org/p/' . $package . '.json'); | |
if ($result === false || !json_decode($result)) { | |
$results['skipped']++; | |
echo 'Skipped - not found.', PHP_EOL; | |
continue; | |
} | |
$result = json_decode($result); | |
if (empty($result->packages->$package->{'dev-master'})) { | |
$results['skipped']++; | |
echo 'Skipped - master branch not found.', PHP_EOL; | |
continue; | |
} | |
$valid = false; | |
$master = $result->packages->$package->{'dev-master'}; | |
foreach ($master->require as $required => $version) { | |
if (!in_array($required, ['silverstripe/framework', 'silverstripe/cms'])) { | |
continue; | |
} | |
if (Semver::satisfies('4.0.0', $version)) { | |
$results['pass']++; | |
echo 'Pass.', PHP_EOL; | |
continue 2; | |
} | |
$results['fail']++; | |
echo 'Fail.', PHP_EOL; | |
continue; | |
} | |
} | |
echo PHP_EOL; | |
echo <<<RESULTS | |
Results: | |
--- | |
Compatible: {$results['pass']} | |
Non-compatible: {$results['fail']} | |
Skipped: {$results['skipped']} | |
RESULTS; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment