Skip to content

Commit

Permalink
Update update-version.sh to match package names less greedily (Inters…
Browse files Browse the repository at this point in the history
…ectMBO#6174)

* Update update-version.sh to match package names less greedily

* Allow whitespace after comma

* Allow whitespace after comma

* Clarify comment
  • Loading branch information
Kenneth MacKenzie authored and v0d1ch committed Dec 6, 2024
1 parent 4079707 commit f776932
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions scripts/update-version.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env bash

usage () {
echo "$(basename $0) PACKAGE VERSION
echo "usage: $(basename $0) PACKAGE VERSION
Updates the version for PACKAGE to VERSION, and updates bounds
on that package in other cabal files."
}

if [ "$#" == "0" ]; then
if [[ $# != 2 ]]; then
echo "Wrong number of arguments"
usage
exit 1
fi
Expand All @@ -24,7 +25,7 @@ echo "Updating version of $PACKAGE to $VERSION"
# update package version in cabal file for package
sed -i "s/\(^version:\s*\).*/\1$VERSION/" "./$PACKAGE/$PACKAGE.cabal"

# update version bounds in all cabal files
# Update version bounds in all cabal files
# It looks for patterns like the following:
#
# - ", plutus-core"
Expand All @@ -33,6 +34,21 @@ sed -i "s/\(^version:\s*\).*/\1$VERSION/" "./$PACKAGE/$PACKAGE.cabal"
# - ", plutus-core:{plutus-core, plutus-core-testlib} ^>=1.0"
#
# and updates the version bounds to "^>={major version}"
#
# The ?* pattern prevents 'find' from attempting to modify ".cabal" (no basename).
#
# The pattern $PACKAGE[^-A-Za-z0-1][^^] matches the package name followed by the rest of the
# line up to but not including the first ^ (if any); anything after that is replaced with the
# new bound. We need [^-A-Za-z0-1] to exactly match the name of the package whose bounds we
# want to update and make sure that we don't get a situation like `plutus-tx` matching
# `plutus-tx-plugin`.
#
# The second sed command is to match the case where the package name is at the end of the line:
# we need this because the first case requires at least one character after the package name.
#
# Note that this all requires a comma (maybe preceded and/or followed by whitespace) at the
# start of the line: it won't work with a comma at the end.

echo "Updating version bounds on $PACKAGE to '^>=$major_version'"
find . -name "?*.cabal" -exec sed -i "s/\(, $PACKAGE[^^]*\).*/\1 ^>=$major_version/" {} \;
find . -name "?*.cabal" -exec sed -i "s/\(^[ \t]*,[ \t]*$PACKAGE[^-A-Za-z0-1][^^]*\).*/\1^>=$major_version/" {} \; \
-exec sed -i "s/\(^[ \t]*,[ \t]*$PACKAGE$\)/\1 ^>=$major_version/" {} \;

0 comments on commit f776932

Please sign in to comment.