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