Skip to content

Commit

Permalink
Add additional info messages for users
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xorcare committed Sep 22, 2024
1 parent 1742d54 commit 4e63ce5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,39 @@ 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
echo "ERROR: No changes have been detected, but they must be exist"
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
18 changes: 16 additions & 2 deletions go-mod-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,32 @@ fi
GO_LIST_FORMAT_DIRECT='{{.Path}}{{if .Indirect}}<SKIP>{{end}}{{if .Main}}<SKIP>{{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>')
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@ | grep -v '<SKIP>' || 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}}<SKIP>{{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 '<SKIP>')
MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES | grep -v '<SKIP>' || 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"

Expand Down

0 comments on commit 4e63ce5

Please sign in to comment.