replaceVersion.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #
  3. # The MIT License (MIT)
  4. #
  5. # Copyright (c) 2019 Code Technology Studio
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. # this software and associated documentation files (the "Software"), to deal in
  9. # the Software without restriction, including without limitation the rights to
  10. # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. # the Software, and to permit persons to whom the Software is furnished to do so,
  12. # subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in all
  15. # copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. #
  24. #-----------------------------------------------------------
  25. # 此脚本用于每次升级时替换相应位置的版本号
  26. #-----------------------------------------------------------
  27. set -o errexit
  28. current_path=$(pwd)
  29. case "$(uname)" in
  30. Linux)
  31. bin_abs_path=$(readlink -f "$(dirname "$0")")
  32. ;;
  33. *)
  34. bin_abs_path=$(
  35. cd "$(dirname "$0")"
  36. pwd
  37. )
  38. ;;
  39. esac
  40. base=${bin_abs_path}/../
  41. echo "当前路径:${current_path} 脚本路径:${bin_abs_path}"
  42. tag="$2"
  43. if [ -n "$1" ]; then
  44. new_version="$1"
  45. old_version=$(cat "${base}/script/tag.$tag.txt")
  46. echo "$old_version 替换为新版本 $new_version"
  47. else
  48. # 参数错误,退出
  49. echo "ERROR: 请指定新版本!"
  50. exit
  51. fi
  52. if [ ! -n "$old_version" ]; then
  53. echo "ERROR: 旧版本不存在,请确认 /script/tag.$tag.txt 中信息正确"
  54. exit
  55. fi
  56. # 替换所有模块pom.xml中的版本
  57. cd ${base} && mvn versions:set -DnewVersion=$1
  58. echo "替换配置文件版本号 $new_version"
  59. if [ -f "$base/.env" ]; then
  60. # 替换 docker 中的版本
  61. sed -i.bak "s/${old_version}/${new_version}/g" $base/.env
  62. fi
  63. # 替换 Dockerfile 中的版本
  64. sed -i.bak "s/${old_version}/${new_version}/g" $base/modules/server/Dockerfile
  65. sed -i.bak "s/${old_version}/${new_version}/g" $base/modules/agent/Dockerfile
  66. sed -i.bak "s/${old_version}/${new_version}/g" $base/script/docker.sh
  67. sed -i.bak "s/${old_version}/${new_version}/g" $base/modules/server/DockerfileRelease
  68. # logo
  69. sed -i.bak "s/${old_version}/${new_version}/g" $base/modules/common/src/main/resources/banner.txt
  70. # vue version
  71. sed -i.bak "s/${old_version}/${new_version}/g" $base/web-vue/package.json
  72. # release-sha1sum.sh
  73. sed -i.bak "s/${old_version}/${new_version}/g" $base/script/release-sha1sum.sh
  74. # gitee go
  75. sed -i.bak "s/${old_version}/${new_version}/g" $base/.workflow/MasterPipeline.yml
  76. # 保留新版本号
  77. echo "$new_version" >"${base}/script/tag.$tag.txt"
  78. echo "版本号替换成功 $new_version"