Skip to content

Commit 4e63ce5

Browse files
committed
Add additional info messages for users
Additional messages are needed to better understand the result of the script. Output codes have been changed to avoid generating interrupts in cases of normal termination.
1 parent 1742d54 commit 4e63ce5

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

.github/workflows/shell.yml

+18-4
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,39 @@ jobs:
4949
git config user.email "you@example.com"
5050
git config user.name "Your Name"
5151
52-
- name: Test help flags
52+
- name: Zero exit code when use help flags
5353
working-directory: tornado
5454
run: |
5555
../go-mod-bump.sh -h
5656
../go-mod-bump.sh -help
5757
58-
- name: Default exit code must be zero
58+
- name: Zero exit code when module name is not set
5959
working-directory: tornado
6060
run: |
6161
../go-mod-bump.sh
6262
63-
- name: Test bump '${{ matrix.pkg }}'
63+
- name: Update dependencies when there is something to update
6464
working-directory: tornado
6565
run: |
66-
git checkout --quiet 029fe5d254ab71c1e72444adcda808f5a494084d
66+
git checkout --force --quiet 029fe5d254ab71c1e72444adcda808f5a494084d
6767
../go-mod-bump.sh ${{ matrix.pkg }}
6868
commit_count=$(git rev-list --count HEAD ^029fe5d254ab71c1e72444adcda808f5a494084d)
6969
if [[ "$commit_count" == 0 ]]; then
7070
echo "ERROR: No changes have been detected, but they must be exist"
7171
exit 1
7272
fi
7373
git diff 029fe5d254ab71c1e72444adcda808f5a494084d
74+
75+
- name: Zero exit code when nothing to update
76+
working-directory: tornado
77+
run: |
78+
git checkout --force --quiet 029fe5d254ab71c1e72444adcda808f5a494084d
79+
../go-mod-bump.sh ${{ matrix.pkg }} # update
80+
../go-mod-bump.sh ${{ matrix.pkg }} # nothing to update
81+
82+
- name: Zero exit code when no have direct modules
83+
run: |
84+
mkdir testo
85+
cd testo
86+
go mod init testo
87+
../go-mod-bump.sh all

go-mod-bump.sh

+16-2
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,32 @@ fi
9191
GO_LIST_FORMAT_DIRECT='{{.Path}}{{if .Indirect}}<SKIP>{{end}}{{if .Main}}<SKIP>{{end}}'
9292
readonly GO_LIST_FORMAT_DIRECT
9393

94+
echoerr "go-mod-bump: fetching direct modules"
95+
9496
# shellcheck disable=SC2068
95-
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@ | grep -v '<SKIP>')
97+
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@ | grep -v '<SKIP>' || true)
9698
readonly DIRECT_MODULES
9799

100+
if [ -z "$DIRECT_MODULES" ]; then
101+
echoerr "go-mod-bump: nothing to update (no direct modules found)"
102+
exit 0
103+
fi
104+
98105
GO_LIST_FORMAT_FOR_UPDATE='{{.Path}}@{{.Version}}@{{if .Update}}{{.Update.Version}}{{end}}'
99106
GO_LIST_FORMAT_FOR_UPDATE+='{{if not .Update}}<SKIP>{{end}}' # skip modules without updates.
100107
readonly GO_LIST_FORMAT_FOR_UPDATE
101108

109+
echoerr "go-mod-bump: fetching latest versions of modules"
110+
102111
# shellcheck disable=SC2086
103-
MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES | grep -v '<SKIP>')
112+
MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES | grep -v '<SKIP>' || true)
104113
readonly MODULES_FOR_UPDATE
105114

115+
if [ -z "$MODULES_FOR_UPDATE" ]; then
116+
echoerr "go-mod-bump: nothing to update (no new versions found)"
117+
exit 0
118+
fi
119+
106120
function update_module() {
107121
go get "$1"
108122

0 commit comments

Comments
 (0)