|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 | # Usage:
|
4 |
| -# ./scripts/update_dep.sh module version |
5 |
| -# or ./scripts/update_dep.sh module |
| 4 | +# ./scripts/update_dep.sh should_force_upgrade module version |
| 5 | +# or ./scripts/update_dep.sh should_force_upgrade module |
6 | 6 | # e.g.
|
7 |
| -# ./scripts/update_dep.sh github.com/golang/groupcache |
8 |
| -# ./scripts/update_dep.sh github.com/soheilhy/cmux v0.1.5 |
| 7 | +# ./scripts/update_dep.sh false github.com/golang/groupcache |
| 8 | +# ./scripts/update_dep.sh false github.com/soheilhy/cmux v0.1.5 |
9 | 9 | #
|
10 | 10 | # Updates version of given dependency in all the modules that depend on the mod.
|
11 | 11 |
|
12 | 12 | set -euo pipefail
|
13 | 13 |
|
14 | 14 | source ./scripts/test_lib.sh
|
15 | 15 |
|
16 |
| -mod="$1" |
17 |
| -ver="$2" |
| 16 | +if [ "$#" -ne 3 ]; then |
| 17 | + echo "Illegal number of parameters" |
| 18 | + exit 1 |
| 19 | +fi |
18 | 20 |
|
19 |
| -function maybe_update_module { |
| 21 | +should_force_upgrade="$1" |
| 22 | +mod="$2" |
| 23 | +ver="$3" |
| 24 | + |
| 25 | +function print_current_dep_version { |
| 26 | + echo "${mod} version in all go mod files" |
| 27 | + grep --exclude-dir=.git --include=\*.mod -Ri "${mod}" | grep -v sum |
| 28 | + printf "\n\n" |
| 29 | +} |
| 30 | + |
| 31 | +function is_fully_indirect { |
| 32 | + print_current_dep_version |
| 33 | + |
| 34 | + # check if all lines end with "// indirect" |
| 35 | + # if grep found nothing, the error code will be non-zero |
| 36 | + if grep --exclude-dir=.git --include=\*.mod -Ri -q "^.*${mod} v.*// indirect$"; then |
| 37 | + echo "Fully indirect, we will terminate the script" |
| 38 | + exit 1 |
| 39 | + else |
| 40 | + echo "Not fully indirect, we will perform dependency bump" |
| 41 | + fi |
| 42 | +} |
| 43 | + |
| 44 | +function update_module { |
20 | 45 | run go mod tidy
|
21 | 46 |
|
22 |
| - deps=$(go list -f '{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}}{{end}}{{end}}' -m all) |
| 47 | + deps=$(go list -f '{{if .Version}}{{.Path}},{{.Version}}{{end}}' -m all) |
23 | 48 | if [[ "$deps" == *"${mod}"* ]]; then
|
24 | 49 | if [ -z "${ver}" ]; then
|
25 | 50 | run go get "${mod}"
|
26 | 51 | else
|
27 | 52 | run go get "${mod}@${ver}"
|
28 | 53 | fi
|
29 | 54 | fi
|
30 |
| - } |
| 55 | +} |
| 56 | + |
| 57 | +print_current_dep_version |
| 58 | +if [ "$should_force_upgrade" = false ] ; then |
| 59 | + is_fully_indirect |
| 60 | +fi |
| 61 | +run_for_modules update_module |
| 62 | +print_current_dep_version |
| 63 | + |
| 64 | +# check all dependencies across all go mod files have the same pinned version respectively |
| 65 | +PASSES="dep" ./scripts/test.sh |
31 | 66 |
|
32 |
| -go mod tidy |
33 |
| -run_for_modules maybe_update_module |
| 67 | +./scripts/fix.sh |
0 commit comments