Skip to content

Commit

Permalink
Add script to bump packages versions and dependencies [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Oct 11, 2022
1 parent 5c5013f commit a570f41
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions update-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

shopt -s globstar

###############################################################################
# Functions
###############################################################################

# Find package version
find_package_version() {
grep -Po '^version:\s+\K\d+(?:\.\d+)+' < "$1"
}

VERSION_PATTERN="[0-9]+(\\.[0-9]+)+"

# Bump package version from U.B.M to U.(B+1).0
bump_package_version() {
# Find version
version="$(find_package_version "$1")"
unicode="$(echo "$version" | cut -f1 -d'.')"
major="$(echo "$version" | cut -f2 -d'.')"
# Bump version
major=$((major + 1))
new_version="$unicode.$major.0"
echo "Found: $(basename -s .cabal "$1")-$version; bump to: $new_version."
sed -ri "s/^(version:\s+)$VERSION_PATTERN/\1$new_version/" "$1"
}

###############################################################################
# Bump packages versions
###############################################################################

for cabal in **/*.cabal
do
bump_package_version "$cabal"
done

###############################################################################
# Bump dependencies
###############################################################################

UNICODE_DATA="$(find_package_version unicode-data/unicode-data.cabal)"

UNICODE="$(echo "$UNICODE_DATA" | cut -f1 -d'.')"
UNICODE_DATA_MAJOR="$(echo "$UNICODE_DATA" | cut -f2 -d'.')"
# UNICODE_DATA_MINOR="$(echo "$UNICODE_DATA" | cut -f3 -d'.')"

UNICODE_DATA_MIN_BOUND="$UNICODE.$UNICODE_DATA_MAJOR"
UNICODE_DATA_MAX_BOUND="$UNICODE.$((UNICODE_DATA_MAJOR+1))"

REGEX="s/\
(unicode-data\\s+>= )$VERSION_PATTERN(\\s+&&\\s+< )$VERSION_PATTERN/\
\\1$UNICODE_DATA_MIN_BOUND\\3$UNICODE_DATA_MAX_BOUND/"

for cabal in **/*.cabal
do
echo "Update dependencies of: $(basename -s .cabal "$cabal")"
sed -ri "$REGEX" "$cabal"
done

0 comments on commit a570f41

Please sign in to comment.