2016-09-12 11:06:58 +01:00
|
|
|
<?php
|
|
|
|
|
2016-09-13 12:35:02 +01:00
|
|
|
if (3 > $_SERVER['argc']) {
|
|
|
|
echo "Usage: branch dir1 dir2 ... dirN\n";
|
2016-09-12 11:06:58 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
chdir(dirname(__DIR__));
|
|
|
|
|
|
|
|
$dirs = $_SERVER['argv'];
|
|
|
|
array_shift($dirs);
|
|
|
|
$mergeBase = trim(shell_exec(sprintf('git merge-base %s HEAD', array_shift($dirs))));
|
|
|
|
|
|
|
|
$packages = array();
|
2017-06-01 18:56:34 +01:00
|
|
|
$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0;
|
2016-09-12 11:06:58 +01:00
|
|
|
|
|
|
|
foreach ($dirs as $k => $dir) {
|
2018-09-03 10:07:34 +01:00
|
|
|
if (!system("git diff --name-only \"$mergeBase\" -- $dir", $exitStatus)) {
|
2016-09-12 11:06:58 +01:00
|
|
|
if ($exitStatus) {
|
|
|
|
exit($exitStatus);
|
|
|
|
}
|
|
|
|
unset($dirs[$k]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
echo "$dir\n";
|
|
|
|
|
|
|
|
$json = ltrim(file_get_contents($dir.'/composer.json'));
|
|
|
|
if (null === $package = json_decode($json)) {
|
|
|
|
passthru("composer validate $dir/composer.json");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$package->repositories = array(array(
|
|
|
|
'type' => 'composer',
|
|
|
|
'url' => 'file://'.str_replace(DIRECTORY_SEPARATOR, '/', dirname(__DIR__)).'/',
|
|
|
|
));
|
|
|
|
if (false === strpos($json, "\n \"repositories\": [\n")) {
|
|
|
|
$json = rtrim(json_encode(array('repositories' => $package->repositories), $flags), "\n}").','.substr($json, 1);
|
|
|
|
file_put_contents($dir.'/composer.json', $json);
|
|
|
|
}
|
|
|
|
passthru("cd $dir && tar -cf package.tar --exclude='package.tar' *");
|
|
|
|
|
2016-09-13 12:35:02 +01:00
|
|
|
if (!isset($package->extra->{'branch-alias'}->{'dev-master'})) {
|
|
|
|
echo "Missing \"dev-master\" branch-alias in composer.json extra.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-01-03 14:49:55 +00:00
|
|
|
$package->version = str_replace('-dev', '.x-dev', $package->extra->{'branch-alias'}->{'dev-master'});
|
2016-09-12 11:06:58 +01:00
|
|
|
$package->dist['type'] = 'tar';
|
|
|
|
$package->dist['url'] = 'file://'.str_replace(DIRECTORY_SEPARATOR, '/', dirname(__DIR__))."/$dir/package.tar";
|
|
|
|
|
|
|
|
$packages[$package->name][$package->version] = $package;
|
|
|
|
|
2018-01-18 11:52:12 +00:00
|
|
|
$versions = file_get_contents('https://packagist.org/p/'.$package->name.'.json');
|
|
|
|
$versions = json_decode($versions)->packages->{$package->name};
|
2016-09-12 11:06:58 +01:00
|
|
|
|
2017-01-03 14:49:55 +00:00
|
|
|
if ($package->version === str_replace('-dev', '.x-dev', $versions->{'dev-master'}->extra->{'branch-alias'}->{'dev-master'})) {
|
|
|
|
unset($versions->{'dev-master'});
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($versions as $v => $package) {
|
2016-09-12 11:06:58 +01:00
|
|
|
$packages[$package->name] += array($v => $package);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_put_contents('packages.json', json_encode(compact('packages'), $flags));
|
|
|
|
|
|
|
|
if ($dirs) {
|
|
|
|
$json = ltrim(file_get_contents('composer.json'));
|
|
|
|
if (null === $package = json_decode($json)) {
|
|
|
|
passthru("composer validate $dir/composer.json");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$package->repositories = array(array(
|
|
|
|
'type' => 'composer',
|
|
|
|
'url' => 'file://'.str_replace(DIRECTORY_SEPARATOR, '/', dirname(__DIR__)).'/',
|
|
|
|
));
|
|
|
|
if (false === strpos($json, "\n \"repositories\": [\n")) {
|
|
|
|
$json = rtrim(json_encode(array('repositories' => $package->repositories), $flags), "\n}").','.substr($json, 1);
|
|
|
|
file_put_contents('composer.json', $json);
|
|
|
|
}
|
|
|
|
}
|