github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/scripts/vendor (about) 1 #!/usr/bin/env bash 2 3 set -eu 4 5 TYP=$1 6 7 usage() { 8 echo "usage: ./scripts/vendor <init|update|validate|outdated>" 9 exit 1 10 } 11 12 if [ -z "$TYP" ]; then 13 usage 14 fi 15 16 init() { 17 # create dummy go.mod, see comment in vendor.mod 18 cat > go.mod <<EOL 19 module github.com/khulnasoft/cli 20 21 go 1.19 22 EOL 23 } 24 25 update() { 26 (set -x ; go mod tidy -modfile=vendor.mod; go mod vendor -modfile=vendor.mod) 27 } 28 29 validate() { 30 diff=$(git status --porcelain -- vendor.mod vendor.sum vendor) 31 if [ -n "$diff" ]; then 32 echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make -f docker.Makefile vendor"' 33 echo "$diff" 34 exit 1 35 fi 36 } 37 38 outdated() { 39 if [ ! -x "$(command -v go-mod-outdated)" ]; then 40 echo "go-mod-outdated not found. Install with 'go install github.com/psampaz/go-mod-outdated@v0.8.0'" 41 exit 1 42 fi 43 (set -x ; go list -mod=vendor -mod=readonly -modfile=vendor.mod -u -m -json all | go-mod-outdated -update -direct) 44 } 45 46 case $TYP in 47 "init") 48 init 49 ;; 50 "update") 51 init 52 update 53 ;; 54 "validate") 55 init 56 update 57 validate 58 ;; 59 "outdated") 60 init 61 outdated 62 ;; 63 *) 64 echo >&2 "Unknown type $TYP" 65 exit 1 66 ;; 67 esac