-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.sh
executable file
·87 lines (82 loc) · 1.83 KB
/
manage.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
#!/bin/sh
projects() {
for child in $(ls); do
if ! [ -d "$child" ]; then
continue
fi
if ! [ -f "$child"/Cargo.toml ]; then
continue
fi
echo $child
done
}
get_version() {
version=""
for proj in $(projects); do
if [ -z "$version" ]; then
version="$(sed -rn '/^\s*version\s*=\s*"/p' "$proj"/Cargo.toml | cut -d'"' -f2)"
else
new_ver="$(sed -rn '/^\s*version\s*=\s*"/p' "$proj"/Cargo.toml | cut -d'"' -f2)"
if [ "$new_ver" != "$version" ]; then
echo "Versions mismatch"
exit 1
fi
fi
done
}
bump_version() {
major="$(cut -d. -f1 <<<"$version")"
minor="$(cut -d. -f2 <<<"$version")"
patch="$(cut -d. -f3 <<<"$version")"
case "$1" in
major)
major=$(($major+1))
minor=0
patch=0
;;
minor)
minor=$(($minor+1))
patch=0
;;
patch)
patch=$(($patch+1))
;;
*)
echo "Unknown/missing version part $1"
exit 1
;;
esac
version="$major.$minor.$patch"
}
set -e
case "$1" in
ver)
if ! git diff --exit-code >/dev/null; then
echo 'Not everything is checked in!'
exit 1
fi
get_version
bump_version "$2"
for proj in $(projects); do
sed -i -E '
s/^version.*$/version = "'"$version"'"/
s/^hexpawb\s*=\s*".*$/hexpawb = "'"$version"'"/
s/^(hexpawb\s*=\s*\{.*version\s*=\s*)"[^"]+"/\1"'"$version"'"/
' "$proj"/Cargo.toml
done
echo "Bumped version to $version"
;;
check)
get_version
echo "Versions match"
;;
publish)
for proj in $(projects); do
cargo publish -p "$proj" &
done
wait
;;
*)
echo "Unknown/missing command $cmd"
;;
esac