summaryrefslogtreecommitdiff
path: root/Porting/make-rmg-checklist
blob: 86616079277bf18c8be562eddd3dda86407b1627 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long qw< :config no_ignore_case >;

sub pod {
    my $filename = shift;

    open my $fh, '<', $filename
        or die "Cannot open file ($filename): $!\n";

    my @lines = <$fh>;

    close $fh
        or die "Cannot close file ($filename): $!\n";

    return \@lines;
}

sub _help {
    my $msg = shift;
    if ($msg) {
        print "Error: $msg\n\n";
    }

    print << "_END_HELP";
$0 --version VERSION

This script creates a release checklist as a simple HTML document. It accepts
the following arguments:

  --version     The version you are working on. This will infer the type
                of release you want to have

  --html        Output HTML instead of POD
_END_HELP

    exit;
}

sub _type_from_version {
    my $version = shift;

    # 5.26.0      = BLEAD-FINAL
    # 5.26.0-RC1  = RC
    # 5.26.1      = MAINT
    # 5.27.0      = BLEAD-POINT
    # 5.27.1      = BLEAD-POINT
    $version =~ m{^ 5\. (\d{1,2}) \. (\d{1,2}) (?: -RC(\d) )? $}xms
        or die "Version must be 5.x.y or 5.x.y-RC#\n";

    my ( $major, $minor, $rc ) = ( $1, $2, $3 );

    # Dev release
    if ( $major % 2 != 0 ) {
        defined $rc
            and die "Cannot have BLEAD-POINT RC release\n";

        return 'BLEAD-POINT';
    }

    defined $rc
        and return 'RC';

    return $minor == 0 ? 'BLEAD-FINAL' : 'MAINT';
}

sub iterate_items {
    my ( $items, $type, $cb ) = @_;

    ITEM:
    foreach my $item ( @{$items} ) {
        foreach my $meta ( @{ $item->{'metadata'} || [] } ) {
            if ( $meta =~ /skip .+ $type/xms ) {
                next ITEM;
            }
            elsif ( $meta =~ /skip/xms ) {
                $item->{content} =~
                    s/^ [^\n]* \b MUST\ SKIP\ this\ step \b [^\n]* \n\n//xms;
            }
        }

        $cb->($item);
    }
}

sub create_checklist {
    my ( $type, $items ) = @_;

    my $collect;
    my $prev_head = 0;
    my $over_level;
    iterate_items( $items, $type, sub {
        my $item = shift;

        foreach my $meta ( @{ $item->{'metadata'} || [] } ) {
            $meta =~ /checklist \s+ begin/xmsi
                and $collect = 1;

            $meta =~ /checklist \s+ end/xmsi
                and $collect = 0;

        }

        $collect
            or return;

        $over_level = ( $item->{'head'} - 1 ) * 4;

        print $prev_head < $item->{'head'} ? "=over $over_level\n\n"
            : $prev_head > $item->{'head'} ? "=back\n\n"
            :                                '';

        chomp( my $name = $item->{'name'} );
        print "=item * L<< /$name >>\n\n";

        $prev_head = $item->{'head'};
    });

    print "=back\n\n" x ( $over_level / 4 );
}

my ($version, $html);
GetOptions(
    'version|v=s' => \$version,
    'html'        => \$html,
    'help|h'      => sub { _help(); },
);

defined $version
    or _help('You must provide a version number');

my $pod_output = '';
if ($html) {
    require Pod::Simple::HTML;
    open my $fh, '>', \$pod_output
        or die "Can't create fh to string: $!\n";
    select $fh;
}

my $type = _type_from_version($version);

chomp( my @pod_lines = @{ pod('Porting/release_managers_guide.pod') } );

my ( @items, $current_element, @leading_attrs );
my $skip_headers     = qr/^=encoding/xms;
my $passthru_headers = qr/^= (?: over | item | back | cut )/xms;

# version used when generating diffs (acknowledgements, Module::CoreList etc)
# 5.36.0 -> 5.34.0
# 5.36.1 -> 5.36.0
my ($major, $minor, $point) = split(/\./, $version);
my $last_version = join('.', $major, ($point == 0 ? ($minor - 2, 0) : ($minor, $point-1)));


foreach my $line (@pod_lines) {
    $line =~ $skip_headers
        and next;

    if ( $line =~ /^ =head(\d) \s+ (.+) $/xms ) {
        my ( $head_num, $head_title ) = ( $1, $2 );

        my $elem = {
            'head' => $head_num,
            'name' => $head_title,
        };

        if (@leading_attrs) {
            $elem->{'metadata'} = [ @leading_attrs ];
            @leading_attrs = ();
        }

        $current_element = $elem;
        push @items, $elem;

        next;
    }

    if ( $line =~ /^ =for \s+ (.+) $ /xms ) {
        push @leading_attrs, $1;
        next;
    }

    $line =~ $passthru_headers
        or length $line == 0 # allow empty lines
        or $line =~ /^[^=]/xms
        or die "Cannot recognize line: '$line'\n";

    $line =~ s/\Q5.X.Y\E/$version/g;
    $line =~ s/\Q5.LAST\E/$last_version/g;
    $line =~ s/\Q5.X\E\b/$major.$minor/g;

    $current_element->{'content'} .= "\n" . $line;
}

print << "_END_BEGINNING";
=head1 NAME

Release Manager's Guide with Checklist for $version ($type)

=head2 Checklist

_END_BEGINNING

# Remove beginning
# This can also be done with a '=for introduction' in the future
$items[0]{'name'} =~ /^NAME/xmsi
    and shift @items;

$items[0]{'name'} =~ /^MAKING \s+ A \s+ CHECKLIST/xmsi
    and shift @items;

create_checklist( $type, \@items );

iterate_items( \@items, $type, sub {
    my $item = shift;
    print "=head$item->{'head'} $item->{'name'}";
    print "$item->{'content'}\n";
} );

if ($html) {
    my $simple = Pod::Simple::HTML->new;
    $simple->output_fh(*STDOUT);
    $simple->parse_string_document($pod_output);
}