Debian Codegraph @

contrib/upgrade-dependency.sh

raw
1 #!/usr/bin/env bash
2
3 # Upgrade a dependency across all dependent submodules.
4 #
5 # Usage:
6 # ./contrib/upgrade-dependency.sh github.com/foo/bar
7 #
8 # Requires ripgrep.
9
10 if [[ -z "$1" ]]; then
11 echo "Usage: ./contrib/upgrade-dependency.sh github.com/foo/bar"
12 exit 1
13 fi
14
15 if [[ -z "$(which rg)" ]]; then
16 echo "This script requires ripgrep. Please visit https://github.com/BurntSushi/ripgrep to learn how to install this utility."
17 exit 1
18 fi
19
20 set -euo pipefail
21
22 DEPENDENCY="$1"
23 printf "%s\n" "Upgrading \"$DEPENDENCY\"."
24
25 ROOT="$(git rev-parse --show-toplevel)"
26
27 GO_MOD_FILES=$(rg -l "$DEPENDENCY" | grep "go.mod")
28 printf "%s\n" "Module files to adjust: ${GO_MOD_FILES//$'\n'/, }."
29
30 for f in ${GO_MOD_FILES}; do
31 MODULE_PATH="$(dirname "$f")"
32 printf "%s\n" "Upgrading \"$DEPENDENCY\" in \"$MODULE_PATH\"."
33
34 set -x
35 cd "$MODULE_PATH"
36 go get -u "$DEPENDENCY"
37 go mod tidy
38 cd "$ROOT"
39 set +x
40 done