.set_version.sh 3.2 KB

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