-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_drupal9_projects.php
116 lines (103 loc) · 3.67 KB
/
new_drupal9_projects.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// Fresh release list via https://drupal.org/files/releases.tsv
$releases = file_get_contents('releases.tsv');
$results = [
'NEW Drupal 9' => [],
'Already Drupal 9' => [],
'Not yet' => [],
'Other' => [],
];
foreach (explode("\n", $releases) as $release) {
list($d, $name, $version) = explode("\t", $release);
if (preg_match('!^(\d)\\.x!', $version, $found) && $found[1] != '8') {
// Skip processing releases that are not 8.x or semantic.
$results['Other'][] = "$name $version";
continue;
}
// Check out this release.
print "Processing $name $version\n";
exec("rm -rf $name && git clone --progress https://git.drupalcode.org/project/$name.git 2> /dev/null && cd $name && git checkout $version 2> /dev/null", $output);
// If this release was Drupal 9 compatile, we still need to check if this was the first for this project.
if (is_drupal9_compatible($name)) {
$newly_compatible = TRUE;
$tags = $release_date = $tag_date = [];
// Take the date of this checkout so we can compare it to other tags' dates.
exec("cd $name && git show -s --format=%ci", $release_date);
// Get list of tags in project to iterate over.
exec('cd ' . $name . ' && git tag', $tags);
foreach($tags as $tag) {
if (preg_match('!^(\d)\\.x!', $tag, $found) && $found[1] != '8') {
// Skip releases that are not 8.x or semantic.
continue;
}
elseif ($tag == $version) {
// Skip the tag itself that we tested above.
continue;
}
// Get date of this tag, so we can ensure we only compare to older tags.
exec("cd $name && git checkout $tag 2> /dev/null && git show -s --format=%ci", $tag_date);
if ((strtotime($release_date[0]) > strtotime($tag_date[0])) && is_drupal9_compatible($name)) {
$results['Already Drupal 9'][] = "$name $version (already compatible in $tag)";
$newly_compatible = FALSE;
break;
}
}
if ($newly_compatible) {
$day = date('F j', strtotime($d));
$results['NEW Drupal 9'][$day][] = '<a href="https://drupal.org/project/' . $name . '/releases/' . $version . '">' . $name . ' ' . $version . '</a>';
}
}
else {
// This release itself is not yet Drupal 9 compatible.
$results['Not yet'][] = "$name $version";
}
exec("rm -rf $name");
}
foreach ($results['NEW Drupal 9'] as $day => $releases) {
print '<td valign="top"><h3>' . $day . "</h3><ul>\n";
foreach ($releases as $release) {
print '<li>' . $release . "</li>\n";
}
print '</ul></td>';
}
var_dump($results);
/**
* Check info file if a release is Drupal 9 compatible.
*
* @param string $name
* Project name.
*/
function is_drupal9_compatible(string $name) {
$infos = glob($name . '/*.info.yml');
$compatibility = [];
foreach($infos as $file) {
$yaml = file_get_contents($file);
// Very rough pattern to check compatibility for now.
if (preg_match('!^core_version_requirement:.+\^9.*$!m', $yaml)) {
$compatibility[$file] = TRUE;
}
else {
$compatibility[$file] = FALSE;
}
}
// Ideally the project has an info file with the name of the project.
if (!empty($compatibility[$name . '/' . $name . '.info.yml'])) {
return TRUE;
}
// If that is not the case (eg. 'bugtracker' project has a 'bug_tracker' module),
// we should order by length of info files and take the shortest. This is what
// drupal.org does as well for considering compatibility.
elseif (count($compatibility)) {
uksort($compatibility, 'lengthsort');
if (reset($compatibility)) {
return TRUE;
}
}
return FALSE;
}
/**
* Custom short function for length sorting.
*/
function lengthsort($a, $b){
return strlen($a) - strlen($b);
}