-
Notifications
You must be signed in to change notification settings - Fork 1
/
relnote-sync.pl
109 lines (97 loc) · 2.82 KB
/
relnote-sync.pl
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
#!/usr/bin/perl
#
use strict;
use warnings;
use 5.010;
use Data::Dumper;
# merge the RELEASE.md from other branches
# syntax:
# perl relnote-sync.pl <target-branch> <source-branch> <source-branch> ...
sub read_relnotes {
my $branch = $_[0];
my $relnote_source = "branch $branch";
if ($branch =~ /^FILE:(.*)$/) {
my $filename = $1;
open(F, "$filename") || die("Could not open file $filename");
$relnote_source = "file $filename";
} else {
open(F, "git show $branch:RELEASE.md |") || die("Could not open RELEASE.md file in branch $branch");
}
my $curr_page = "";
my $curr_page_data = "";
my $curr_page_title = "";
my $pages = {};
while (<F>) {
chomp();
my $aLine = $_;
# print("L:$aLine\n");
if ($aLine =~ /^\@page\s(\S+)\s(.*?)$/) {
my $aPage = $1;
my $aTitle = $2;
if ($curr_page ne "") {
$pages->{$curr_page} = { "data" => $curr_page_data, "title" => $curr_page_title };
print STDERR " Added page $curr_page from $relnote_source\n";
}
$curr_page = $aPage;
$curr_page_title = $aTitle;
$curr_page_data = "";
} else {
$curr_page_data = $curr_page_data . "$aLine\n";
}
}
if ($curr_page ne "") {
$pages->{$curr_page} = { "data" => $curr_page_data, "title" => $curr_page_title };
print STDERR " Added page $curr_page from $relnote_source\n";
}
close(F);
return $pages;
}
sub print_pages {
my $pages = $_[0];
my $page_keys = [];
foreach my $p (keys(%{$pages})) {
push(@{$page_keys}, $p);
}
@{$page_keys} = reverse(sort(@{$page_keys}));
print("# Release Notes {#release_notes}\n\n");
foreach my $p (@{$page_keys}) {
print("* \@subpage $p\n");
}
print("\n");
foreach my $p (@{$page_keys}) {
my $aTitle = $pages->{$p}->{'title'};
my $aData = $pages->{$p}->{'data'};
print("\@page $p $aTitle\n");
print($aData);
}
}
my $target_branch = shift || die "Need a target branch for RELEASE.md";
print STDERR "Target branch: $target_branch\n";
my $target_pages = read_relnotes($target_branch);
# print Dumper($target_pages);
while (my $aBranch = shift) {
print STDERR " Merge from branch: $aBranch\n";
if ($aBranch =~ /^TBD:(\d\d)\.(\d\d)$/) {
my $VerMajor = $1;
my $VerMinor = $2;
my $aData = "\nTBD\n\n";
my $p = "release_notes_$VerMajor$VerMinor";
my $aTitle = "Release notes for VPP $VerMajor.$VerMinor";
$target_pages->{$p} = { "data" => $aData, 'title' => $aTitle };
continue;
}
my $some_pages = read_relnotes($aBranch);
# print Dumper($some_pages);
foreach my $p (keys(%{$some_pages})) {
if (!exists($target_pages->{$p})) {
print STDERR "Adding page $p from branch $aBranch\n";
$target_pages->{$p} = $some_pages->{$p};
} else {
if ($target_pages->{$p}->{'data'} =~ /^\s*TBD\s*$/sm) {
print STDERR "Replacing TBD with page $p from branch $aBranch\n";
$target_pages->{$p} = $some_pages->{$p};
}
}
}
}
print_pages($target_pages);