diff --git a/.github/workflows/shell.yml b/.github/workflows/shell.yml index 5b3576a..eb1a63a 100644 --- a/.github/workflows/shell.yml +++ b/.github/workflows/shell.yml @@ -49,21 +49,21 @@ jobs: git config user.email "you@example.com" git config user.name "Your Name" - - name: Test help flags + - name: Zero exit code when use help flags working-directory: tornado run: | ../go-mod-bump.sh -h ../go-mod-bump.sh -help - - name: Default exit code must be zero + - name: Zero exit code when module name is not set working-directory: tornado run: | ../go-mod-bump.sh - - name: Test bump '${{ matrix.pkg }}' + - name: Update dependencies when there is something to update working-directory: tornado run: | - git checkout --quiet 029fe5d254ab71c1e72444adcda808f5a494084d + git checkout --force --quiet 029fe5d254ab71c1e72444adcda808f5a494084d ../go-mod-bump.sh ${{ matrix.pkg }} commit_count=$(git rev-list --count HEAD ^029fe5d254ab71c1e72444adcda808f5a494084d) if [[ "$commit_count" == 0 ]]; then @@ -71,3 +71,17 @@ jobs: exit 1 fi git diff 029fe5d254ab71c1e72444adcda808f5a494084d + + - name: Zero exit code when nothing to update + working-directory: tornado + run: | + git checkout --force --quiet 029fe5d254ab71c1e72444adcda808f5a494084d + ../go-mod-bump.sh ${{ matrix.pkg }} # update + ../go-mod-bump.sh ${{ matrix.pkg }} # nothing to update + + - name: Zero exit code when no have direct modules + run: | + mkdir testo + cd testo + go mod init testo + ../go-mod-bump.sh all diff --git a/go-mod-bump.sh b/go-mod-bump.sh index a8aee8e..4b5c441 100755 --- a/go-mod-bump.sh +++ b/go-mod-bump.sh @@ -91,18 +91,32 @@ fi GO_LIST_FORMAT_DIRECT='{{.Path}}{{if .Indirect}}{{end}}{{if .Main}}{{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 '') +DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@ | grep -v '' || true) 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}}{{end}}' # skip modules without updates. 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 '') +MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES | grep -v '' || true) readonly MODULES_FOR_UPDATE +if [ -z "$MODULES_FOR_UPDATE" ]; then + echoerr "go-mod-bump: nothing to update (no new versions found)" + exit 0 +fi + function update_module() { go get "$1"