cronet.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. #分支Stable Dev Beta
  3. branch=$1
  4. #api 最大偏移
  5. max_offset=$2
  6. [ -z $1 ] && branch=Stable
  7. [ -z $2 ] && max_offset=3
  8. [ -z $GITHUB_ENV ] && echo "Error: Unexpected github workflow environment" && exit
  9. offset=0
  10. function fetch_version() {
  11. # 获取最新cronet版本
  12. lastest_cronet_version=`curl -s "https://chromiumdash.appspot.com/fetch_releases?channel=$branch&platform=Android&num=1&offset=$offset" | jq .[0].version -r`
  13. echo "lastest_cronet_version: $lastest_cronet_version"
  14. #lastest_cronet_version=100.0.4845.0
  15. lastest_cronet_main_version=${lastest_cronet_version%%\.*}.0.0.0
  16. check_version_exit
  17. }
  18. function check_version_exit() {
  19. # 检查版本是否存在
  20. local jar_url="https://storage.googleapis.com/chromium-cronet/android/$lastest_cronet_version/Release/cronet/cronet_api.jar"
  21. statusCode=$(curl -s -I -w %{http_code} "$jar_url" -o /dev/null)
  22. if [ $statusCode == "404" ]; then
  23. echo "storage.googleapis.com return 404 for cronet $lastest_cronet_version"
  24. if [[ $max_offset > $offset ]]; then
  25. offset=$(expr $offset + 1)
  26. echo "retry with offset $offset"
  27. fetch_version
  28. else
  29. exit
  30. fi
  31. fi
  32. }
  33. function version_compare() {
  34. # 版本号比较 本地版本小于远程版本时返回0
  35. local local_version=$1
  36. local remote_version=$2
  37. if [[ $local_version == $remote_version ]]; then
  38. return 1
  39. fi
  40. if [[ $(printf '%s\n' "$1" "$2" | sort -V | head -n1) == $remote_version ]]; then
  41. return 1
  42. else
  43. return 0
  44. fi
  45. }
  46. # 添加变量到github env
  47. function write_github_env_variable() {
  48. echo "$1=$2" >> $GITHUB_ENV
  49. }
  50. function sync_proguard_rules() {
  51. local raw_github_git="https://raw.githubusercontent.com/chromium/chromium/$lastest_cronet_version"
  52. local proguard_paths=(
  53. components/cronet/android/cronet_combined_impl_native_proguard_golden.cfg
  54. )
  55. local proguard_rules_path="$GITHUB_WORKSPACE/app/cronet_proguard_rules.pro"
  56. rm -f proguard_rules_path
  57. echo "fetch cronet proguard rules from upstream $raw_github_git"
  58. for path in ${proguard_paths[@]}
  59. do
  60. echo "fetching $path ..."
  61. curl "$raw_github_git/$path" >> proguard_rules_path
  62. done
  63. }
  64. ##########
  65. # 获取本地cronet版本
  66. path=$GITHUB_WORKSPACE/gradle.properties
  67. current_cronet_version=`cat $path | grep CronetVersion | sed s/CronetVersion=//`
  68. echo "current_cronet_version: $current_cronet_version"
  69. echo "fetch $branch release info from https://chromiumdash.appspot.com ..."
  70. fetch_version
  71. if version_compare $current_cronet_version $lastest_cronet_version; then
  72. # 更新gradle.properties
  73. sed -i s/CronetVersion=.*/CronetVersion=$lastest_cronet_version/ $path
  74. sed -i s/CronetMainVersion=.*/CronetMainVersion=$lastest_cronet_main_version/ $path
  75. # 更新cronet_proguard_rules.pro
  76. sync_proguard_rules
  77. # 添加更新日志
  78. sed "15a* 更新cronet: $lastest_cronet_version" -i $GITHUB_WORKSPACE/app/src/main/assets/updateLog.md
  79. # 生成pull request信息
  80. write_github_env_variable PR_TITLE "Bump cronet from $current_cronet_version to $lastest_cronet_version"
  81. write_github_env_variable PR_BODY "Changes in the [Git log](https://chromium.googlesource.com/chromium/src/+log/$current_cronet_version..$lastest_cronet_version)"
  82. # 生成cronet flag
  83. write_github_env_variable cronet ok
  84. fi