Skip to content

Commit

Permalink
Update update-version.sh to match package names less greedily
Browse files Browse the repository at this point in the history
  • Loading branch information
kwxm committed Jun 4, 2024
1 parent bbeb1a4 commit 2f9242f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 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,18 @@ 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 exactly the package name followed by anything
# up to ^. We need [^-A-Za-z0-1] to prevent eg `plutus-tx` from 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 by whitespace) at the start of the line:
# it won't work with commas 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]*, $PACKAGE[^-A-Za-z0-1][^^]*\).*/\1^>=$major_version/" {} \; \
-exec sed -i "s/\(^[ \t]*, $PACKAGE$\)/\1 ^>=$major_version/" {} \;

0 comments on commit 2f9242f

Please sign in to comment.