-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update update_dep.sh #18609
base: main
Are you sure you want to change the base?
Update update_dep.sh #18609
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,21 +13,51 @@ set -euo pipefail | |
|
||
source ./scripts/test_lib.sh | ||
|
||
if [ "$#" -ne 2 ]; then | ||
echo "Illegal number of parameters" | ||
exit 1 | ||
fi | ||
|
||
mod="$1" | ||
ver="$2" | ||
|
||
function maybe_update_module { | ||
function print_current_dep_version { | ||
echo "${mod} version in all go mod files" | ||
grep --exclude-dir=.git --include=\*.mod -Ri "^.*${mod} v.*$" | grep -v sum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By passing I think your regular expression can be simplified to |
||
printf "\n\n" | ||
} | ||
|
||
function is_fully_indirect { | ||
# check if all lines end with "// indirect" | ||
# if grep found nothing, the error code will be non-zero | ||
ALL=$(grep --exclude-dir=.git --include=\*.mod -Ri "^.*${mod} v.*$" | grep -v sum | wc -l) | ||
ONLY_INDIRECT=$(grep --exclude-dir=.git --include=\*.mod -Ri "^.*${mod} v.*// indirect$" | grep -v sum | wc -l) | ||
if [[ "$ALL" == "$ONLY_INDIRECT" ]]; then | ||
echo "Fully indirect, we will terminate the script" | ||
exit 1 | ||
else | ||
echo "Not fully indirect, we will perform dependency bump" | ||
fi | ||
Comment on lines
+31
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another approach would be to use local result
result=$(find . -name go.mod | xargs -I{} /bin/sh -c 'cd $(dirname {}); go list -f "{{if eq .Path \"'"${mod}"'\"}}{{.Indirect}}{{end}}" -m all' | sort | uniq)
if [ "$result" = "true" ] ; then
read -p "Module ${mod} is an indirect dependency. Are you sure you want to update it? [y/N] " -r confirm
[[ "${confirm,,}" == "y" ]] || exit
else
echo "Not fully..."
fi |
||
} | ||
|
||
function update_module { | ||
run go mod tidy | ||
|
||
deps=$(go list -f '{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}}{{end}}{{end}}' -m all) | ||
deps=$(go list -f '{{if .Version}}{{.Path}},{{.Version}}{{end}}' -m all) | ||
if [[ "$deps" == *"${mod}"* ]]; then | ||
if [ -z "${ver}" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the changes from the top of the file if [ "$#" -ne 2 ]; then
echo "Illegal number of parameters"
exit 1
fi We will never reach this conditional, as |
||
run go get "${mod}" | ||
run go get -u "${mod}" | ||
else | ||
run go get "${mod}@${ver}" | ||
fi | ||
fi | ||
} | ||
} | ||
|
||
print_current_dep_version | ||
is_fully_indirect | ||
run_for_modules update_module | ||
|
||
./scripts/fix.sh | ||
PASSES="dep" ./scripts/test.sh | ||
|
||
go mod tidy | ||
run_for_modules maybe_update_module | ||
print_current_dep_version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also outdates the documentation at the top of the file 😅