cronet.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 fetchExitVersion() {
  11. # 获取最新cronet版本
  12. echo "fetch $branch release info from https://chromiumdash.appspot.com ..."
  13. lastest_cronet_version=`curl -s "https://chromiumdash.appspot.com/fetch_releases?channel=$branch&platform=Android&num=1&offset=$offset" | jq .[0].version -r`
  14. echo "lastest_cronet_version: $lastest_cronet_version"
  15. #lastest_cronet_version=100.0.4845.0
  16. lastest_cronet_main_version=${lastest_cronet_version%%\.*}.0.0.0
  17. checkVersionExit
  18. }
  19. function checkVersionExit() {
  20. # 检查版本是否存在
  21. local jar_url="https://storage.googleapis.com/chromium-cronet/android/$lastest_cronet_version/Release/cronet/cronet_api.jar"
  22. statusCode=$(curl -s -I -w %{http_code} "$jar_url" -o /dev/null)
  23. if [ $statusCode == "404" ];then
  24. echo "storage.googleapis.com return 404 for cronet $lastest_cronet_version"
  25. if [[ $max_offset > $offset ]]; then
  26. offset=$(expr $offset + 1)
  27. echo "retry with offset $offset"
  28. fetchExitVersion
  29. else
  30. exit
  31. fi
  32. fi
  33. }
  34. # 添加变量到github env
  35. function writeVariableToGithubEnv() {
  36. echo "$1=$2" >> $GITHUB_ENV
  37. }
  38. ##########
  39. # 获取本地cronet版本
  40. path=$GITHUB_WORKSPACE/gradle.properties
  41. current_cronet_version=`cat $path | grep CronetVersion | sed s/CronetVersion=//`
  42. echo "current_cronet_version: $current_cronet_version"
  43. fetchExitVersion
  44. if [[ $current_cronet_version < $lastest_cronet_version ]];then
  45. # 更新gradle.properties
  46. sed -i s/CronetVersion=.*/CronetVersion=$lastest_cronet_version/ $path
  47. sed -i s/CronetMainVersion=.*/CronetMainVersion=$lastest_cronet_main_version/ $path
  48. # 添加更新日志
  49. sed "15a* 更新cronet: $lastest_cronet_version" -i $GITHUB_WORKSPACE/app/src/main/assets/updateLog.md
  50. # 生成pull request信息
  51. writeVariableToGithubEnv PR_TITLE "Bump cronet from $current_cronet_version to $lastest_cronet_version"
  52. writeVariableToGithubEnv PR_BODY "Changes in the [Git log](https://chromium.googlesource.com/chromium/src/+log/$current_cronet_version..$lastest_cronet_version)"
  53. # 生成cronet flag
  54. writeVariableToGithubEnv cronet ok
  55. fi