Skip to content

Commit fee8bf0

Browse files
authored
feat(ci): ensure exactly one version bump
Check in CI that the version of a crate has been bumped exactly once since the last release. Based on discussion in #5781. Pull-Request: #5804.
1 parent bd5a2f5 commit fee8bf0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

scripts/ensure-version-bump-and-changelog.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ MERGE_BASE=$(git merge-base "$HEAD_SHA" "$PR_BASE") # Find the merge base. This
1010
SRC_DIFF_TO_BASE=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-status -- "$DIR_TO_CRATE/src" "$DIR_TO_CRATE/Cargo.toml")
1111
CHANGELOG_DIFF=$(git diff "$HEAD_SHA".."$MERGE_BASE" --name-only -- "$DIR_TO_CRATE/CHANGELOG.md")
1212

13+
RELEASED_VERSION=$(git tag --sort=version:refname | grep "^$CRATE-v" | tail -n1 | grep -Po "\d+\.\d+\.\d+")
14+
15+
1316
# If the source files of this crate weren't touched in this PR, exit early.
1417
if [ -z "$SRC_DIFF_TO_BASE" ]; then
1518
exit 0;
@@ -21,8 +24,22 @@ if [ -z "$CHANGELOG_DIFF" ]; then
2124
exit 1
2225
fi
2326

24-
# Code was touched, ensure the version used in the manifest hasn't been released yet.
25-
if git tag | grep -q "^$CRATE-v${CRATE_VERSION}$"; then
26-
echo "v$CRATE_VERSION of '$CRATE' has already been released, please bump the version."
27-
exit 1
28-
fi
27+
IFS='.' read -r -a current <<< "$CRATE_VERSION"
28+
IFS='.' read -r -a released <<< "$RELEASED_VERSION"
29+
30+
for i in $(seq 0 2);
31+
do
32+
case $((current[i]-released[i])) in
33+
0) continue ;;
34+
1) if [[ -n $(printf "%s\n" "${current[@]:i+1}" | grep -vFx '0') ]]; then
35+
echo "Patch version has been bumped even though minor isn't released yet".
36+
exit 1
37+
fi
38+
exit 0 ;;
39+
*) echo "Version of '$CRATE' has been bumped more than once since last release v$RELEASED_VERSION."
40+
exit 1 ;;
41+
esac
42+
done
43+
44+
echo "v$CRATE_VERSION of '$CRATE' has already been released, please bump the version."
45+
exit 1

0 commit comments

Comments
 (0)