Skip to content

Commit ac43daa

Browse files
Danielius1922Daniel Adam
authored andcommitted
Add helper script to update all dependencies
1 parent eb4ad2f commit ac43daa

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
3+
#
4+
# Helper script to uprade repository dependencies:
5+
# - golang modules
6+
# - git submodules
7+
#
8+
9+
set -e
10+
11+
usage() {
12+
local readonly EXIT_STATUS=$1
13+
14+
cat << HELP_USAGE
15+
Usage: $(basename $0) [-aghs]
16+
17+
Description:
18+
Helper script to upgrade repository dependecies
19+
20+
Options:
21+
-h / --help show help
22+
-g / --golang-only upgrade only golang dependencies
23+
-a / --golang-all upgrade all golang dependecies (both direct and indirect)
24+
-s / --submodules-only upgrade only git submodules
25+
HELP_USAGE
26+
27+
exit ${EXIT_STATUS}
28+
}
29+
30+
UPGRADE_GOLANG_ONLY=0
31+
UPGRADE_GOLANG_ALL_DEPENDENCIES=0
32+
UPGRADE_SUBMODULES_ONLY=0
33+
34+
while getopts "aghs-:" optchar; do
35+
case "${optchar}" in
36+
-)
37+
case "${OPTARG}" in
38+
golang-all)
39+
UPGRADE_GOLANG_ALL_DEPENDENCIES=1
40+
;;
41+
golang-only)
42+
UPGRADE_GOLANG_ONLY=1
43+
;;
44+
help)
45+
usage 0
46+
;;
47+
submodules-only)
48+
UPGRADE_SUBMODULES_ONLY=1
49+
;;
50+
*)
51+
echo "ERROR: Unknown option --${OPTARG}" >&2
52+
echo ""
53+
usage 1
54+
;;
55+
esac
56+
;;
57+
a)
58+
UPGRADE_GOLANG_ALL_DEPENDENCIES=1
59+
;;
60+
g)
61+
UPGRADE_GOLANG_ONLY=1
62+
;;
63+
h)
64+
usage 0
65+
;;
66+
s)
67+
UPGRADE_SUBMODULES_ONLY=1
68+
;;
69+
*)
70+
echo "ERROR: Unknown option -${OPTARG}" >&2
71+
echo ""
72+
usage 1
73+
;;
74+
esac
75+
done
76+
77+
if [ $UPGRADE_GOLANG_ONLY -eq 1 -a $UPGRADE_SUBMODULES_ONLY -eq 1 ]; then
78+
echo "ERROR: Cannot combine -g (--golang-only) and -s (--submodules-only) options " >&2
79+
usage 1
80+
fi
81+
82+
if [ $UPGRADE_GOLANG_ALL_DEPENDENCIES -eq 1 -a $UPGRADE_SUBMODULES_ONLY -eq 1 ]; then
83+
echo "ERROR: Cannot combine -a (--golang-all) and -s (--submodules-only) options " >&2
84+
usage 1
85+
fi
86+
87+
readonly SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
88+
89+
if [ $UPGRADE_SUBMODULES_ONLY -ne 1 ]; then
90+
readonly UPGRADE_MODULES_SH=$SCRIPT_DIR/upgrade-go-modules.sh
91+
if [ $UPGRADE_GOLANG_ALL_DEPENDENCIES -eq 1 ]; then
92+
"$UPGRADE_MODULES_SH" --all
93+
else
94+
"$UPGRADE_MODULES_SH"
95+
fi
96+
fi
97+
98+
99+
if [ $UPGRADE_GOLANG_ONLY -ne 1 ]; then
100+
readonly REPOSITORY_DIR=$(cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd)
101+
cd "${REPOSITORY_DIR}"
102+
git submodule update --remote
103+
fi

0 commit comments

Comments
 (0)