github.com/verrazzano/verrazzano@v1.7.1/tools/scripts/list_go_mod_versions.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2021, Oracle and/or its affiliates. 4 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 5 # 6 SCRIPT_DIR=$(cd $(dirname "$0"); pwd -P) 7 TMP_DIR=$(mktemp -d) 8 GO_MOD_FILE=$SCRIPT_DIR/../../go.mod 9 10 function table_row() { 11 local all_versions=$(go list -m -mod=mod -versions $1) 12 all_versions=${all_versions#"$1"} 13 local in_use=$(echo $2 | cut -d- -f1 |cut -d+ -f1 ) 14 local found_in_use=false 15 local newer_vers="" 16 local avail_vers="" 17 local latest="" 18 for ver in $all_versions; do 19 if [[ "$ver" == "$in_use" ]]; then 20 found_in_use=true 21 fi 22 if [[ "$ver" != *"rc"* ]] && [[ "$ver" != *"beta"* ]] && [[ "$ver" != *"alpha"* ]]; then 23 avail_vers="$avail_vers $ver" 24 if [[ "$ver" != *"incompatible"* ]]; then 25 latest=$ver # assuming the last one is the latest 26 fi 27 if [[ $found_in_use == true ]] ; then 28 newer_vers="$newer_vers $ver" 29 fi 30 fi 31 done 32 if [[ "$newer_vers" == "" ]]; then 33 local warnNotFound="in_use_version: $2 not found!!" 34 newer_vers=$avail_vers 35 fi 36 echo $1,$2,$latest,$newer_vers 37 } 38 39 function inspect_go_mod() { 40 local in_require=false 41 while IFS= read -r line; do 42 if [[ "$line" == *"require ("* ]]; then 43 in_require=true 44 else 45 if [[ $in_require == true ]] && [[ "$line" != *")"* ]]; then 46 table_row $line 47 else 48 in_require=false 49 fi 50 fi 51 done < $1 52 } 53 54 echo "Component,In Use,Latest,Available" 55 inspect_go_mod $GO_MOD_FILE