Skip to content

Commit 731cf27

Browse files
committed
Compare against the overlay version at the last protocol bump
A protocol bump only needs an overlay bump if overlay hasn't already been bumped since the previous protocol bump. Uses git history rather than release tags, which may not be public yet.
1 parent d466b21 commit 731cf27

3 files changed

Lines changed: 48 additions & 12 deletions

File tree

‎.github/workflows/build-private.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ jobs:
5252
runs-on: ubuntu-24.04
5353
steps:
5454
- uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0
5557
- name: Check protocol bump is accompanied by an overlay version bump
5658
run: |
5759
BASE_SHA='${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}'
58-
git fetch --depth=1 origin "$BASE_SHA"
5960
./scripts/check-protocol-overlay-versions.sh "$BASE_SHA"
6061
6162
build:

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ jobs:
108108
steps:
109109
- uses: namespacelabs/nscloud-checkout-action@v7
110110
with:
111-
fetch-depth: 1
111+
fetch-depth: 0
112112

113113
- name: Check protocol bump is accompanied by an overlay version bump
114114
run: |
115115
BASE_SHA='${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}'
116-
git fetch --depth=1 origin "$BASE_SHA"
117116
./scripts/check-protocol-overlay-versions.sh "$BASE_SHA"
118117
119118
build-linux:

‎scripts/check-protocol-overlay-versions.sh‎

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
# Usage: check-protocol-overlay-versions.sh <base-rev> [<head-rev>]
1111
#
1212
# Compares src/main/Config.cpp at <head-rev> (or the working tree copy if
13-
# <head-rev> is omitted) against <base-rev>, and exits with a non-zero
14-
# status if CURRENT_LEDGER_PROTOCOL_VERSION increased without
15-
# OVERLAY_PROTOCOL_VERSION increasing as well.
13+
# <head-rev> is omitted) against <base-rev>. If CURRENT_LEDGER_PROTOCOL_VERSION
14+
# increased, exits with a non-zero status unless OVERLAY_PROTOCOL_VERSION is
15+
# higher than it was when <base-rev>'s ledger protocol version was introduced.
16+
# Comparing against that commit rather than <base-rev> means a change doesn't
17+
# need to bump the overlay version again if it was already bumped since the
18+
# previous protocol bump. It also doesn't depend on release tags, which may not
19+
# be public yet when the next protocol bump lands.
20+
#
21+
# Requires the history of <base-rev> back to its last ledger protocol bump.
1622

1723
set -e
1824

@@ -63,6 +69,29 @@ extract()
6369
echo "$VAL"
6470
}
6571

72+
# Print the oldest commit in <base-rev>'s history from which
73+
# CURRENT_LEDGER_PROTOCOL_VERSION has had the value it has at <base-rev>.
74+
ledger_bump_commit()
75+
{
76+
FOUND=
77+
for C in $(git log --format=%H -G 'CURRENT_LEDGER_PROTOCOL_VERSION[[:space:]]*=' "$BASE_REV" -- "$CONFIG_CPP")
78+
do
79+
if [ "$(extract "$C" CURRENT_LEDGER_PROTOCOL_VERSION "$LEDGER_EXPR")" != "$BASE_LEDGER" ]
80+
then
81+
break
82+
fi
83+
FOUND=$C
84+
done
85+
# A commit with no parent available is a shallow clone boundary, not
86+
# necessarily the commit that introduced the protocol version.
87+
if [ -z "$FOUND" ] || ! git rev-parse -q --verify "$FOUND^" >/dev/null
88+
then
89+
echo "error: could not find the commit that set CURRENT_LEDGER_PROTOCOL_VERSION to $BASE_LEDGER in the history of $BASE_REV (shallow clone?)" >&2
90+
exit 2
91+
fi
92+
echo "$FOUND"
93+
}
94+
6695
LEDGER_EXPR='s/.*Config::CURRENT_LEDGER_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
6796
OVERLAY_EXPR='s/^[[:space:]]*OVERLAY_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
6897

@@ -74,13 +103,20 @@ HEAD_OVERLAY=$(extract "$HEAD_REV" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR")
74103
echo "CURRENT_LEDGER_PROTOCOL_VERSION: $BASE_LEDGER -> $HEAD_LEDGER"
75104
echo "OVERLAY_PROTOCOL_VERSION: $BASE_OVERLAY -> $HEAD_OVERLAY"
76105

77-
if [ "$HEAD_LEDGER" -gt "$BASE_LEDGER" ] && [ "$HEAD_OVERLAY" -le "$BASE_OVERLAY" ]
106+
if [ "$HEAD_LEDGER" -gt "$BASE_LEDGER" ]
78107
then
79-
echo "error: CURRENT_LEDGER_PROTOCOL_VERSION was bumped from $BASE_LEDGER to $HEAD_LEDGER" >&2
80-
echo "without bumping OVERLAY_PROTOCOL_VERSION (still $HEAD_OVERLAY)." >&2
81-
echo "A ledger protocol bump must be accompanied by a bump of the maximum" >&2
82-
echo "overlay protocol version in $CONFIG_CPP." >&2
83-
exit 1
108+
BUMP_COMMIT=$(ledger_bump_commit)
109+
BUMP_OVERLAY=$(extract "$BUMP_COMMIT" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR")
110+
echo "Protocol $BASE_LEDGER was introduced in $(git log -1 --format='%h (%s)' "$BUMP_COMMIT")"
111+
echo "with OVERLAY_PROTOCOL_VERSION $BUMP_OVERLAY"
112+
if [ "$HEAD_OVERLAY" -le "$BUMP_OVERLAY" ]
113+
then
114+
echo "error: CURRENT_LEDGER_PROTOCOL_VERSION was bumped from $BASE_LEDGER to $HEAD_LEDGER" >&2
115+
echo "but OVERLAY_PROTOCOL_VERSION ($HEAD_OVERLAY) has not been bumped since protocol" >&2
116+
echo "$BASE_LEDGER was introduced. A ledger protocol bump must be accompanied by a" >&2
117+
echo "bump of the maximum overlay protocol version in $CONFIG_CPP." >&2
118+
exit 1
119+
fi
84120
fi
85121

86122
echo "OK"

0 commit comments

Comments
 (0)