Skip to content
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

Get rid of 'grep -v' #15

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions go-mod-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,27 @@ EOF
exit 0
fi

GO_LIST_FORMAT_DIRECT='{{.Path}}{{if .Indirect}}<SKIP>{{end}}{{if .Main}}<SKIP>{{end}}'
GO_LIST_FORMAT_DIRECT='{{if and (not .Main) (not .Indirect)}}{{.Path}}{{end}}'
readonly GO_LIST_FORMAT_DIRECT

echoerr "go-mod-bump: fetching direct modules"

# shellcheck disable=SC2068
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@ | grep -v '<SKIP>' || true)
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@)
readonly DIRECT_MODULES

if [ -z "$DIRECT_MODULES" ]; then
echoerr "go-mod-bump: nothing to update (no direct modules found)"
exit 0
fi

GO_LIST_FORMAT_FOR_UPDATE='{{.Path}}@{{.Version}}@{{if .Update}}{{.Update.Version}}{{end}}'
GO_LIST_FORMAT_FOR_UPDATE+='{{if not .Update}}<SKIP>{{end}}' # skip modules without updates.
GO_LIST_FORMAT_FOR_UPDATE='{{if .Update}}{{.Path}}@{{.Version}}@{{.Update.Version}}{{end}}'
readonly GO_LIST_FORMAT_FOR_UPDATE

echoerr "go-mod-bump: fetching latest versions of modules"

# shellcheck disable=SC2086
MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES | grep -v '<SKIP>' || true)
MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES)
readonly MODULES_FOR_UPDATE

if [ -z "$MODULES_FOR_UPDATE" ]; then
Expand Down