forked from symfony/symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-modified-packages.php
75 lines (61 loc) · 2.19 KB
/
get-modified-packages.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* Given a list of all packages, find the package that have been modified.
*/
if (3 > $_SERVER['argc']) {
echo "Usage: app-packages modified-files\n";
exit(1);
}
$allPackages = json_decode($_SERVER['argv'][1], true, 512, \JSON_THROW_ON_ERROR);
$modifiedFiles = json_decode($_SERVER['argv'][2], true, 512, \JSON_THROW_ON_ERROR);
// Sort to get the longest name first (match bridge not component)
usort($allPackages, function($a, $b) {
return strlen($b) <=> strlen($a) ?: $a <=> $b;
});
function getPackageType(string $packageDir): string
{
if (preg_match('@Symfony/Bridge/@', $packageDir)) {
return 'bridge';
}
if (preg_match('@Symfony/Bundle/@', $packageDir)) {
return 'bundle';
}
if (preg_match('@Symfony/Component/[^/]+/Bridge/@', $packageDir)) {
return 'component_bridge';
}
if (preg_match('@Symfony/Component/@', $packageDir)) {
return 'component';
}
if (preg_match('@Symfony/Contracts/@', $packageDir)) {
return 'contract';
}
if (preg_match('@Symfony/Contracts$@', $packageDir)) {
return 'contracts';
}
throw new \LogicException();
}
$newPackage = [];
$modifiedPackages = [];
foreach ($modifiedFiles as $file) {
foreach ($allPackages as $package) {
if (0 === strpos($file, $package)) {
$modifiedPackages[$package] = true;
if ('LICENSE' === substr($file, -7)) {
/*
* There is never a reason to modify the LICENSE file, this diff
* must be adding a new package
*/
$newPackage[$package] = true;
}
break;
}
}
}
$output = [];
foreach ($modifiedPackages as $directory => $bool) {
$composerData = json_decode(file_get_contents($directory.'/composer.json'), true);
$name = $composerData['name'] ?? 'unknown';
$requiresDeprecationContracts = isset($composerData['require']['symfony/deprecation-contracts']);
$output[] = ['name' => $name, 'directory' => $directory, 'new' => $newPackage[$directory] ?? false, 'type' => getPackageType($directory), 'requires_deprecation_contracts' => $requiresDeprecationContracts];
}
echo json_encode($output);