github.com/KEINOS/go-countline@v1.1.0/.github/run_go_mod_tidy.sh (about) 1 #!/bin/sh 2 # ============================================================================= 3 # This script updates Go modules to the latest version. 4 # ============================================================================= 5 # It will remove the go.mod file and run `go mod tidy` to get the latest moule 6 # versions. 7 # Then it will run the tests to make sure the code is still working, and fails 8 # if any errors are found during the process. 9 # 10 # NOTE: This script is aimed to run in the container via docker-compose. 11 # See "tidy" service: ./docker-compose.yml 12 # ============================================================================= 13 14 set -eu 15 16 echo '* Backup modules ...' 17 mv go.mod go.mod.bak 18 mv go.sum go.sum.bak 19 20 echo '* Create new blank go.mod ...' 21 # Copy the first 4 lines of the go.mod.bak file to the new go.mod file. 22 < go.mod.bak head -n 4 > go.mod 23 24 echo '* Get latest modules ...' 25 go get "github.com/pkg/errors" 26 go get "github.com/stretchr/testify" 27 go get "github.com/zenizh/go-capturer" 28 go get "golang.org/x/text" 29 30 31 echo '* Run go tidy ...' 32 go mod tidy 33 34 echo '* Run tests ...' 35 go test ./... && { 36 echo '* Testing passed. Removing old go.mod file ...' 37 rm -f go.mod.bak 38 rm -f go.sum.bak 39 echo 'Successfully updated modules!' 40 }