From 0eb3718c5d7dd13926d58c8fbf614b24cfd9abbf Mon Sep 17 00:00:00 2001 From: Yuval Kogman Date: Thu, 10 Jul 2025 01:36:29 +0200 Subject: [PATCH] CI: Enforce BIP 2 & 3 field ordering requirements The specified field order is consistent with both BIPs 2 and 3. The ordering of fields which are only present in one or the other is ambiguous, e.g. as in `Proposed-Replacement` and `Superseded-By` but only one of these applies to a given BIP. The `Editor` field is spurious, only being used in BIP 69, and appears after Author. --- scripts/buildtable.pl | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/scripts/buildtable.pl b/scripts/buildtable.pl index acec8acf..bc9e4b5f 100755 --- a/scripts/buildtable.pl +++ b/scripts/buildtable.pl @@ -37,6 +37,30 @@ my %MiscField = ( 'Requires' => undef, 'Superseded-By' => undef, ); +my @FieldOrder = qw( + BIP + Layer + Title + Author + Authors + Editor + Deputies + Discussions-To + Comments-Summary + Comments-URI + Status + Type + Created + License + License-Code + Discussion + Post-History + Version + Requires + Replaces + Proposed-Replacement + Superseded-By +); my %ValidLayer = ( 'Consensus (soft fork)' => undef, @@ -114,7 +138,7 @@ while (++$bipnum <= $topbip) { } my %found; my ($title, $author, $status, $type, $layer); - my ($field, $val); + my ($field, $val, @field_order); while (<$F>) { last if ($is_markdown && m[^```$]); last if (!$is_markdown && m[^$]); @@ -182,6 +206,7 @@ while (++$bipnum <= $topbip) { die "Unknown field $field in $fn"; } ++$found{$field}; + push @field_order, $field unless @field_order and $field_order[-1] eq $field; } if (not $found{License}) { die "Missing License in $fn" unless exists $TolerateMissingLicense{$bipnum}; @@ -189,6 +214,10 @@ while (++$bipnum <= $topbip) { for my $field (keys %RequiredFields) { die "Missing $field in $fn" unless $found{$field}; } + my @expected_field_order = grep { exists $found{$_} } @FieldOrder; + if ("@expected_field_order" ne "@field_order") { + die "Field order is incorrect in $fn, should be:\n\t" . join(", ", @expected_field_order) . "\nbut contains:\n\t" . join(", ", @field_order); + } print "|-"; if (defined $ValidStatus{$status}) { print " style=\"" . $ValidStatus{$status} . "\"";