blob: 4231aa04487f7a0abfc74fdc84f11b3439c97246 [file] [log] [blame]
Patrick Williams37567b72015-06-08 15:25:40 -05001#!/bin/env perl
Stewart Smithf76e7f92017-05-19 10:42:01 +10002
Patrick Williams37567b72015-06-08 15:25:40 -05003use strict;
4
Stewart Smithf76e7f92017-05-19 10:42:01 +10005use Getopt::Long;
6use DBI;
7
8# We use an in-memory SQLite database as SQL is good for doing queries
9# of differences between data sets, and doing that in perl is annoying.
10my $db = "dbi:SQLite:dbname=release-notes.sqlite";
11#my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:","","");
12my $dbh = DBI->connect($db,undef,undef, {AutoCommit => 1, RaiseError=>1});
13
Patrick Williams37567b72015-06-08 15:25:40 -050014my $repos =
15{
16 'op-build' => { REPO => "http://github.com/open-power/op-build" },
17 'hostboot' => { REPO => "http://github.com/open-power/hostboot" ,
Stewart Smithf76e7f92017-05-19 10:42:01 +100018 DIR => "openpower/package/hostboot" },
Sachin Guptadf0b6a02017-03-16 08:59:51 -050019 'sbe' => { REPO => "http://github.com/open-power/sbe" ,
Stewart Smithf76e7f92017-05-19 10:42:01 +100020 DIR => "openpower/package/sbe"},
Patrick Williams37567b72015-06-08 15:25:40 -050021 'skiboot' => { REPO => "http://github.com/open-power/skiboot" ,
Stewart Smithf76e7f92017-05-19 10:42:01 +100022 DIR => "openpower/package/skiboot"},
Patrick Williams37567b72015-06-08 15:25:40 -050023 'occ' => { REPO => "http://github.com/open-power/occ" ,
Stewart Smithf76e7f92017-05-19 10:42:01 +100024 DIR => "openpower/package/occ"},
Patrick Williams37567b72015-06-08 15:25:40 -050025 'pnor' => { REPO => "http://github.com/open-power/pnor" ,
Stewart Smithf76e7f92017-05-19 10:42:01 +100026 DIR => "openpower/package/openpower-pnor"},
Patrick Williams37567b72015-06-08 15:25:40 -050027 'petitboot' => { REPO => "http://github.com/open-power/petitboot" ,
Stewart Smithf76e7f92017-05-19 10:42:01 +100028 DIR => "openpower/package/petitboot"},
Patrick Williams37567b72015-06-08 15:25:40 -050029};
30
Stewart Smithf76e7f92017-05-19 10:42:01 +100031my $begin_release;
32my $end_release;
33my $begin_worktree;
34my $end_worktree;
35my $platform;
36
37GetOptions("begin-release=s" => \$begin_release,
38 "end-release=s" => \$end_release,
39 "begin-worktree=s" => \$begin_worktree,
40 "platform=s" => \$platform,
41 "end-worktree=s" => \$end_worktree)
42 or die("Error in command line arguments");
43
44die "Required argument missing" unless ($begin_release and $end_release and $begin_worktree and $end_worktree);
45
46open(OUTPUT, "> RELEASE.md") || die "Failed to open RELEASE.md";
47
48print OUTPUT "# Release Notes for OpenPower Firmware $end_release\n";
49
50if (-e $begin_worktree) {
51 system("cd $begin_worktree && git checkout $begin_release && git submodule update --reference ../buildroot && git submodule update") and die "Could not update $begin_worktree";
52} else {
53 system("git worktree add $begin_worktree $begin_release && cd $begin_worktree&& git submodule update --reference ../buildroot && git submodule update && rm -rf dl && ln -s ../dl dl") and die "Couldn't init $begin_worktree";
54}
55
56if (-e $end_worktree) {
57 system("cd $end_worktree && git checkout $end_release && git submodule update --reference ../buildroot && git submodule update") and die "Could not update $end_worktree";
58} else {
59 system("git worktree add $end_worktree $end_release && cd $end_worktree && git submodule update --reference ../buildroot && git submodule update && rm -rf dl && ln -s ../dl dl") and die "Couldn't init $end_worktree";
60}
61
62opendir (my $dh, "$begin_worktree/openpower/configs")
63 or die "can't scan $begin_worktree defconfigs";
64my @begin_platforms = grep { /.*_defconfig/ } readdir($dh);
65closedir $dh;
66
67opendir (my $dh, "$end_worktree/openpower/configs")
68 or die "can't scan $end_worktree defconfigs";
69my @end_platforms = grep { /.*_defconfig/ } readdir($dh);
70closedir $dh;
71
72s/_defconfig// foreach (@begin_platforms);
73s/_defconfig// foreach (@end_platforms);
74
75if ($platform) {
76 @begin_platforms = ($platform);
77 @end_platforms = ($platform);
78}
79
80$dbh->do("CREATE TABLE platforms (platform TEXT, version TEXT);") or die "$!";
81{
82 my $q = "INSERT INTO platforms (platform,version) VALUES (?,?)";
83 my $sth = $dbh->prepare($q) or die "$!";
84 $sth->execute($_, $begin_release) foreach (@begin_platforms);
85 $sth->execute($_, $end_release) foreach (@end_platforms);
86}
87
88{
89 my $q = "SELECT platform FROM platforms WHERE version is ? AND platform NOT IN (SELECT platform FROM platforms WHERE version is ?)";
90 my $sth = $dbh->prepare($q) or die $!;
91 $sth->execute($begin_release, $end_release);
92 my $r;
93 print OUTPUT "## Removed platforms\n\n- ".$r->{platform}."\n" if $r = $sth->fetchrow_hashref;
94 print OUTPUT "- ".$_->{platform}."\n" while ($r = $sth->fetchrow_hashref);
95
96 $sth->execute($end_release, $begin_release);
97 print OUTPUT "## New platforms\n\n- ".$r->{platform}."\n" if $r = $sth->fetchrow_hashref;
98 print OUTPUT "- ".$_->{platform}."\n" while($r = $sth->fetchrow_hashref);
99}
100
101my @common_platforms;
102{
103 my $q = "SELECT platform FROM platforms WHERE version is ? AND EXISTS (select platform from platforms where version is ?)";
104 my $sth = $dbh->prepare($q) or die $!;
105 $sth->execute($begin_release, $end_release);
106 my $r;
107 push @common_platforms, $r->{platform} while ($r = $sth->fetchrow_hashref);
108}
109
110foreach my $p (@common_platforms) {
111 next if $p =~ /firenze/;
112 next if $p =~ /^zz$/;
113 next if $p =~ /mambo/;
114 $repos->{"$p-xml"} = { REPO => "http://github.com/open-power/$p-xml" ,
115 DIR => "openpower/package/$p-xml" };
116}
117
118foreach my $p (@begin_platforms) {
119 system("bash -c '(cd $begin_worktree && . op-build-env && op-build ".$p."_defconfig && op-build legal-info)'");
120 # Forgive me for this....
121 system("sqlite3 release-notes.sqlite \".mode csv\" \".import $begin_worktree/output/legal-info/manifest.csv begin_".$p."_manifest\"");
122}
123
124foreach my $p (@end_platforms) {
125 system("bash -c '(cd $end_worktree && . op-build-env && op-build ".$p."_defconfig && op-build legal-info)'");
126 # Forgive me for this....
127 system("sqlite3 release-notes.sqlite \".mode csv\" \".import $end_worktree/output/legal-info/manifest.csv end_".$p."_manifest\"");
128}
129
130$dbh->do(<<'SQL') or die "$!";
131CREATE TABLE package_upgrades (
132 PACKAGE TEXT,
133 OLDVERSION TEXT,
134 NEWVERSION TEXT,
135 PLATFORM TEXT
136)
137SQL
138
139foreach my $p (@common_platforms) {
140 $dbh->do("INSERT INTO package_upgrades select b.package,b.version,e.version,'$p' from begin_".$p."_manifest as b LEFT JOIN end_".$p."_manifest AS e ON b.package=e.package WHERE b.version != e.version") or die $!;
141}
142
143$dbh->do(<<'SQL') or die "$!";
144CREATE TABLE new_package (
145 PACKAGE TEXT,
146 VERSION TEXT,
147 PLATFORM TEXT
148)
149SQL
150
151foreach my $p (@common_platforms) {
152 $dbh->do("INSERT INTO new_package select b.package,b.version,'$p' from end_".$p."_manifest as b WHERE NOT EXISTS(SELECT package FROM begin_".$p."_manifest AS e WHERE b.package=e.package)") or die $!;
153}
154
155$dbh->do(<<'SQL') or die "$!";
156CREATE TABLE removed_package (
157 PACKAGE TEXT,
158 VERSION TEXT,
159 PLATFORM TEXT
160)
161SQL
162
163foreach my $p (@common_platforms) {
164 $dbh->do("INSERT INTO removed_package select b.package,b.version,'$p' from begin_".$p."_manifest as b WHERE NOT EXISTS(SELECT package FROM end_".$p."_manifest AS e WHERE b.package=e.package)") or die $!;
165}
166
167my $old_level = {};
168my $new_level = {};
169
170{
171 my $q = <<'SQL';
172select package as pk ,oldversion as o ,newversion as n,
173 GROUP_CONCAT(platform) as ps
174FROM package_upgrades
175 GROUP BY package,oldversion,newversion
176ORDER BY package,platform
177SQL
178 my $sth = $dbh->prepare($q) or die $!;
179 $sth->execute();
180
181 print OUTPUT "## Updated Packages\n\n";
182 print OUTPUT "Package | Old Version | New Version | Platforms\n";
183 print OUTPUT "--- | --- | --- | ---\n";
184 while (my $r = $sth->fetchrow_hashref) {
185 print OUTPUT join(' | ',($r->{pk}, $r->{o}, $r->{n}, $r->{ps}))."\n" ;
186 if ($r->{pk} eq 'machine-xml') {
187 $old_level->{$r->{ps}."-xml"} = $r->{o};
188 $new_level->{$r->{ps}."-xml"} = $r->{n};
189 } else {
190 $old_level->{$r->{pk}} = $r->{o};
191 $new_level->{$r->{pk}} = $r->{n};
192 }
193 }
194}
195
196{
197 my $q = <<'SQL';
198select package as pk ,version as v,
199 GROUP_CONCAT(platform) as ps
200FROM new_package
201 GROUP BY package,version
202ORDER BY package,platform
203SQL
204 my $sth = $dbh->prepare($q) or die $!;
205 $sth->execute();
206
207 print OUTPUT "\n\n## New Packages\n\n";
208 print OUTPUT "Package | Version | Platforms\n";
209 print OUTPUT "--- | --- | ---\n";
210 while (my $r = $sth->fetchrow_hashref) {
211 print OUTPUT join(' | ',($r->{pk}, $r->{v}, $r->{ps}))."\n" ;
212 if ($r->{pk} eq 'machine-xml') {
213 $new_level->{$r->{ps}."-xml"} = $r->{v};
214 }
215 }
216}
217
218{
219 my $q = <<'SQL';
220select package as pk ,version as v,
221 GROUP_CONCAT(platform) as ps
222FROM removed_package
223 GROUP BY package,version
224ORDER BY package,platform
225SQL
226 my $sth = $dbh->prepare($q) or die $!;
227 $sth->execute();
228
229 print OUTPUT "\n\n## Removed Packages\n\n";
230 print OUTPUT "Package | Version | Platforms\n";
231 print OUTPUT "--- | --- | ---\n";
232 while (my $r = $sth->fetchrow_hashref) {
233 print OUTPUT join(' | ',($r->{pk}, $r->{v}, $r->{ps}))."\n" ;
234 if ($r->{pk} eq $r->{ps}."-xml") {
235 $old_level->{$r->{ps}."-xml"} = $r->{v};
236 }
237 }
238 print OUTPUT "\n\n";
239}
Patrick Williams37567b72015-06-08 15:25:40 -0500240
241foreach my $repo (keys %{$repos})
242{
243 if (-e $repo)
244 {
245 system("cd $repo; git fetch") && die "Could not fetch $repo";
246 }
247 else
248 {
249 system("git clone $repos->{$repo}->{REPO} $repo") &&
250 die "Could not clone $repo";
251 }
252}
253
254system("cd op-build; git checkout $end_release --force; git reset HEAD --hard");
255
256
Patrick Williams37567b72015-06-08 15:25:40 -0500257my $op_url = $repos->{'op-build'}->{REPO};
258
259foreach my $repo (sort keys %{$repos})
260{
Stewart Smithf76e7f92017-05-19 10:42:01 +1000261 my $package = $repo;
Patrick Williams37567b72015-06-08 15:25:40 -0500262 my $url = $repos->{$repo}->{REPO};
263 my $dir = $repos->{$repo}->{DIR};
264
265 print OUTPUT "## Package: $repo\n";
266 print OUTPUT "[Repository]($url)\n";
267 print OUTPUT "\n";
268
Patrick Williams37567b72015-06-08 15:25:40 -0500269 # Display patches.
270 if (open(LSLOG, "ls op-build/$dir/*.patch | ".
271 "xargs -n1 --no-run-if-empty basename |"))
272 {
273 print OUTPUT "### Patches\n";
274 while (my $logline = <LSLOG>)
275 {
276 chomp $logline;
277 print OUTPUT "* [$logline]".
278 "($op_url/tree/$end_release/$dir/$logline)\n";
279 }
280 close LSLOG;
281 print OUTPUT "\n";
282 }
283 else
284 {
285 print OUTPUT "None.\n";
286 }
287
288 # Display changes.
289 print OUTPUT "### Commits\n";
290 if ((not exists $old_level->{$package}) &&
291 (not exists $new_level->{$package}))
292 {
293 # No change identified.
294 print "No changes: $repo\n";
295 print OUTPUT "No changes.\n";
296 next;
297 }
298
299 if ((exists $old_level->{$package}) &&
300 (exists $new_level->{$package}))
301 {
302 print "Changes in $repo...\n";
Patrick Williams37567b72015-06-08 15:25:40 -0500303 open(GITLOG, "cd $repo; git shortlog $old_level->{$package}...".
304 "$new_level->{$package} --no-merges --format=".
305 "\"* [%h]($url/commit/%h) %s\" |");
306
307 while (my $logline = <GITLOG>)
308 {
309 chomp $logline;
310 $logline =~ s/^[[:space:]]*//;
311 print OUTPUT "$logline\n";
312 }
313 close GITLOG;
314 print OUTPUT "\n";
315 next;
316 }
317
318 if (not exists $old_level->{$package})
319 {
320 print "New package $repo.\n";
321 print OUTPUT "New package.\n";
322 next;
323 }
324
325 if (not exists $new_level->{$package})
326 {
327 print "Deleted package $repo.\n";
328 print OUTPUT "Package removed.\n";
329 next;
330 }
331}