Skip to content

Commit b1de81f

Browse files
authored
Merge pull request #96 from composewell/wip/bump_versions_script
Add script to bump packages versions and dependencies
2 parents 5c5013f + 084313a commit b1de81f

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

update-versions.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
3+
shopt -s globstar
4+
5+
###############################################################################
6+
# Utils
7+
###############################################################################
8+
9+
# Find package version
10+
find_package_version() {
11+
grep -Po '^version:\s+\K\d+(?:\.\d+)+' < "$1"
12+
}
13+
14+
get_version_field() {
15+
echo "$2" | cut -f "$1" -d'.'
16+
}
17+
18+
VERSION_PATTERN="[0-9]+(\\.[0-9]+)+"
19+
20+
###############################################################################
21+
# Bump packages versions
22+
###############################################################################
23+
24+
# Bump package version
25+
# from U.B.M to (U+1).0.0 if Unicode is bumped, else U.(B+1).0
26+
bump_package_version() {
27+
# Find version
28+
version="$(find_package_version "$2")"
29+
unicode="$(get_version_field 1 "$version")"
30+
major="$(get_version_field 2 "$version")"
31+
# Bump version
32+
if [ "$1" == "true" ]
33+
then
34+
unicode=$((unicode + 1))
35+
major=0
36+
else
37+
major=$((major + 1))
38+
fi
39+
new_version="$unicode.$major.0"
40+
echo "Found: $(basename -s .cabal "$2")-$version; bump to: $new_version."
41+
sed -ri "s/^(version:\s+)$VERSION_PATTERN/\1$new_version/" "$2"
42+
}
43+
44+
bump_packages_versions () {
45+
for cabal in **/*.cabal
46+
do
47+
bump_package_version "$1" "$cabal"
48+
done
49+
}
50+
51+
###############################################################################
52+
# Bump dependencies
53+
###############################################################################
54+
55+
bump_dependencies() {
56+
version="$(find_package_version unicode-data/unicode-data.cabal)"
57+
58+
unicode_version="$(get_version_field 1 "$version")"
59+
unicode_data_major="$(get_version_field 2 "$version")"
60+
# unicode_data_minor="$(get_version_field 3 "$version")"
61+
62+
unicode_data_min_bound="$unicode_version.$unicode_data_major"
63+
unicode_data_max_bound="$unicode_version.$((unicode_data_major+1))"
64+
65+
regex="s/(unicode-data\\s+>= )$VERSION_PATTERN"
66+
regex+="(\\s+&&\\s+< )$VERSION_PATTERN/"
67+
regex+="\\1$unicode_data_min_bound\\3$unicode_data_max_bound/"
68+
69+
for cabal in **/*.cabal
70+
do
71+
echo "Update dependencies of: $(basename -s .cabal "$cabal")"
72+
sed -ri "$regex" "$cabal"
73+
done
74+
}
75+
76+
# Print help text
77+
print_help() {
78+
echo "Usage: update-versions.sh [options]"
79+
echo
80+
echo "Available options:"
81+
echo "-u Bump Unicode version"
82+
}
83+
84+
# Default options
85+
BUMP_UNICODE=false
86+
87+
# Parse command line
88+
while getopts "hu" opt; do
89+
case "$opt" in
90+
h) print_help; exit 0;;
91+
u) BUMP_UNICODE=true;;
92+
*) print_help; exit 1;;
93+
esac
94+
done
95+
96+
bump_packages_versions "$BUMP_UNICODE"
97+
bump_dependencies

0 commit comments

Comments
 (0)