github.com/gogf/gf/v2@v2.7.4/.set_version.sh (about)

     1  #!/usr/bin/env bash
     2  if [ $# -ne 2 ]; then
     3      echo "Parameter exception, please execute in the format of $0 [directory] [version number]"
     4      echo "PS:$0 ./ v2.4.0"
     5      exit 1
     6  fi
     7  
     8  if [ ! -d "$1" ]; then
     9      echo "Error: Directory does not exist"
    10      exit 1
    11  fi
    12  
    13  if [[ "$2" != v* ]]; then
    14      echo "Error: Version number must start with v"
    15      exit 1
    16  fi
    17  
    18  workdir=.
    19  newVersion=$2
    20  echo "Prepare to replace the GF library version numbers in all go.mod files in the ${workdir} directory with ${newVersion}"
    21  
    22  # check find command support or not
    23  output=$(find "${workdir}" -name go.mod 2>&1)
    24  if [[ $? -ne 0 ]]; then
    25      echo "Error: please use bash or zsh to run!"
    26      exit 1
    27  fi
    28  
    29  if [[ true ]]; then
    30      echo "package gf" > version.go
    31      echo "" >> version.go
    32      echo "const (" >> version.go
    33      echo -e "\t// VERSION is the current GoFrame version." >> version.go
    34      echo -e "\tVERSION = \"${newVersion}\"" >> version.go
    35      echo ")" >> version.go
    36  fi
    37  
    38  if [ -f "go.work" ]; then
    39      mv go.work go.work.version.bak
    40      echo "Back up the go.work file to avoid affecting the upgrade"
    41  fi
    42  
    43  for file in `find ${workdir} -name go.mod`; do
    44      goModPath=$(dirname $file)
    45      echo ""
    46      echo "processing dir: $goModPath"
    47      cd $goModPath
    48      if [ $goModPath = "./cmd/gf" ]; then
    49          mv go.work go.work.version.bak
    50          go mod edit -replace github.com/gogf/gf/v2=../../
    51          go mod edit -replace github.com/gogf/gf/contrib/drivers/clickhouse/v2=../../contrib/drivers/clickhouse
    52          go mod edit -replace github.com/gogf/gf/contrib/drivers/mssql/v2=../../contrib/drivers/mssql
    53          go mod edit -replace github.com/gogf/gf/contrib/drivers/mysql/v2=../../contrib/drivers/mysql
    54          go mod edit -replace github.com/gogf/gf/contrib/drivers/oracle/v2=../../contrib/drivers/oracle
    55          go mod edit -replace github.com/gogf/gf/contrib/drivers/pgsql/v2=../../contrib/drivers/pgsql
    56          go mod edit -replace github.com/gogf/gf/contrib/drivers/sqlite/v2=../../contrib/drivers/sqlite
    57      # else
    58      #     cd -
    59      #     continue 1
    60      fi
    61      go mod tidy
    62      # Upgrading only GF related libraries, sometimes even if a version number is specified, it may not be possible to successfully upgrade. Please confirm before submitting the code
    63      go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf"
    64      go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf" | xargs -L1 go get -v 
    65      go mod tidy
    66      if [ $goModPath = "./cmd/gf" ]; then
    67          go mod edit -dropreplace github.com/gogf/gf/v2
    68          go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/clickhouse/v2
    69          go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/mssql/v2
    70          go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/mysql/v2
    71          go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/oracle/v2
    72          go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/pgsql/v2
    73          go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/sqlite/v2
    74          mv go.work.version.bak go.work
    75      fi
    76      cd -
    77  done
    78  
    79  if [ -f "go.work.version.bak" ]; then
    80      mv go.work.version.bak go.work
    81      echo "Restore the go.work file"
    82  fi