Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 1 | #!/bin/env perl |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 2 | |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 3 | use strict; |
| 4 | |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 5 | use Getopt::Long; |
| 6 | use 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. |
| 10 | my $db = "dbi:SQLite:dbname=release-notes.sqlite"; |
| 11 | #my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:","",""); |
| 12 | my $dbh = DBI->connect($db,undef,undef, {AutoCommit => 1, RaiseError=>1}); |
| 13 | |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 14 | my $repos = |
| 15 | { |
| 16 | 'op-build' => { REPO => "http://github.com/open-power/op-build" }, |
| 17 | 'hostboot' => { REPO => "http://github.com/open-power/hostboot" , |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 18 | DIR => "openpower/package/hostboot" }, |
Sachin Gupta | df0b6a0 | 2017-03-16 08:59:51 -0500 | [diff] [blame] | 19 | 'sbe' => { REPO => "http://github.com/open-power/sbe" , |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 20 | DIR => "openpower/package/sbe"}, |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 21 | 'skiboot' => { REPO => "http://github.com/open-power/skiboot" , |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 22 | DIR => "openpower/package/skiboot"}, |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 23 | 'occ' => { REPO => "http://github.com/open-power/occ" , |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 24 | DIR => "openpower/package/occ"}, |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 25 | 'pnor' => { REPO => "http://github.com/open-power/pnor" , |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 26 | DIR => "openpower/package/openpower-pnor"}, |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 27 | 'petitboot' => { REPO => "http://github.com/open-power/petitboot" , |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 28 | DIR => "openpower/package/petitboot"}, |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 29 | }; |
| 30 | |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 31 | my $begin_release; |
| 32 | my $end_release; |
| 33 | my $begin_worktree; |
| 34 | my $end_worktree; |
| 35 | my $platform; |
| 36 | |
| 37 | GetOptions("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 | |
| 44 | die "Required argument missing" unless ($begin_release and $end_release and $begin_worktree and $end_worktree); |
| 45 | |
| 46 | open(OUTPUT, "> RELEASE.md") || die "Failed to open RELEASE.md"; |
| 47 | |
| 48 | print OUTPUT "# Release Notes for OpenPower Firmware $end_release\n"; |
| 49 | |
| 50 | if (-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 | |
| 56 | if (-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 | |
| 62 | opendir (my $dh, "$begin_worktree/openpower/configs") |
| 63 | or die "can't scan $begin_worktree defconfigs"; |
| 64 | my @begin_platforms = grep { /.*_defconfig/ } readdir($dh); |
| 65 | closedir $dh; |
| 66 | |
| 67 | opendir (my $dh, "$end_worktree/openpower/configs") |
| 68 | or die "can't scan $end_worktree defconfigs"; |
| 69 | my @end_platforms = grep { /.*_defconfig/ } readdir($dh); |
| 70 | closedir $dh; |
| 71 | |
| 72 | s/_defconfig// foreach (@begin_platforms); |
| 73 | s/_defconfig// foreach (@end_platforms); |
| 74 | |
| 75 | if ($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 | |
| 101 | my @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 | |
| 110 | foreach 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 | |
| 118 | foreach 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 | |
| 124 | foreach 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 "$!"; |
| 131 | CREATE TABLE package_upgrades ( |
| 132 | PACKAGE TEXT, |
| 133 | OLDVERSION TEXT, |
| 134 | NEWVERSION TEXT, |
| 135 | PLATFORM TEXT |
| 136 | ) |
| 137 | SQL |
| 138 | |
| 139 | foreach 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 "$!"; |
| 144 | CREATE TABLE new_package ( |
| 145 | PACKAGE TEXT, |
| 146 | VERSION TEXT, |
| 147 | PLATFORM TEXT |
| 148 | ) |
| 149 | SQL |
| 150 | |
| 151 | foreach 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 "$!"; |
| 156 | CREATE TABLE removed_package ( |
| 157 | PACKAGE TEXT, |
| 158 | VERSION TEXT, |
| 159 | PLATFORM TEXT |
| 160 | ) |
| 161 | SQL |
| 162 | |
| 163 | foreach 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 | |
| 167 | my $old_level = {}; |
| 168 | my $new_level = {}; |
| 169 | |
| 170 | { |
| 171 | my $q = <<'SQL'; |
| 172 | select package as pk ,oldversion as o ,newversion as n, |
| 173 | GROUP_CONCAT(platform) as ps |
| 174 | FROM package_upgrades |
| 175 | GROUP BY package,oldversion,newversion |
| 176 | ORDER BY package,platform |
| 177 | SQL |
| 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'; |
| 198 | select package as pk ,version as v, |
| 199 | GROUP_CONCAT(platform) as ps |
| 200 | FROM new_package |
| 201 | GROUP BY package,version |
| 202 | ORDER BY package,platform |
| 203 | SQL |
| 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'; |
| 220 | select package as pk ,version as v, |
| 221 | GROUP_CONCAT(platform) as ps |
| 222 | FROM removed_package |
| 223 | GROUP BY package,version |
| 224 | ORDER BY package,platform |
| 225 | SQL |
| 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 Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 240 | |
| 241 | foreach 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 | |
| 254 | system("cd op-build; git checkout $end_release --force; git reset HEAD --hard"); |
| 255 | |
| 256 | |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 257 | my $op_url = $repos->{'op-build'}->{REPO}; |
| 258 | |
| 259 | foreach my $repo (sort keys %{$repos}) |
| 260 | { |
Stewart Smith | f76e7f9 | 2017-05-19 10:42:01 +1000 | [diff] [blame] | 261 | my $package = $repo; |
Patrick Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 262 | 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 Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 269 | # 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 Williams | 37567b7 | 2015-06-08 15:25:40 -0500 | [diff] [blame] | 303 | 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 | } |