2022-05-29 08:54:45 +08:00
#!/usr/bin/env bash
2023-03-13 21:34:18 +08:00
#分支Stable Dev Beta
2023-03-09 08:24:19 +08:00
branch = $1
2023-03-13 21:34:18 +08:00
#api 最大偏移
max_offset = $2
2023-03-09 08:24:19 +08:00
[ -z $1 ] && branch = Stable
2023-03-13 21:37:32 +08:00
[ -z $2 ] && max_offset = 3
2023-03-09 08:24:19 +08:00
[ -z $GITHUB_ENV ] && echo "Error: Unexpected github workflow environment" && exit
2022-03-05 15:38:40 +08:00
2023-03-13 21:21:37 +08:00
offset = 0
2023-03-24 22:00:34 +08:00
function fetch_version( ) {
2023-03-13 21:21:37 +08:00
# 获取最新cronet版本
lastest_cronet_version = ` curl -s " https://chromiumdash.appspot.com/fetch_releases?channel= $branch &platform=Android&num=1&offset= $offset " | jq .[ 0] .version -r`
echo " lastest_cronet_version: $lastest_cronet_version "
#lastest_cronet_version=100.0.4845.0
lastest_cronet_main_version = ${ lastest_cronet_version %% \. * } .0.0.0
2023-03-24 22:00:34 +08:00
check_version_exit
2023-03-13 21:21:37 +08:00
}
2023-03-24 22:00:34 +08:00
function check_version_exit( ) {
2023-03-13 21:21:37 +08:00
# 检查版本是否存在
2022-05-29 08:54:45 +08:00
local jar_url = " https://storage.googleapis.com/chromium-cronet/android/ $lastest_cronet_version /Release/cronet/cronet_api.jar "
statusCode = $( curl -s -I -w %{ http_code} " $jar_url " -o /dev/null)
2023-03-24 22:00:34 +08:00
if [ $statusCode = = "404" ] ; then
2022-05-29 08:54:45 +08:00
echo " storage.googleapis.com return 404 for cronet $lastest_cronet_version "
2023-03-13 21:21:37 +08:00
if [ [ $max_offset > $offset ] ] ; then
2023-03-13 21:34:18 +08:00
offset = $( expr $offset + 1)
2023-03-13 21:21:37 +08:00
echo " retry with offset $offset "
2023-03-24 22:00:34 +08:00
fetch_version
2023-03-13 21:21:37 +08:00
else
2023-03-13 21:36:08 +08:00
exit
2023-03-13 21:21:37 +08:00
fi
2022-05-29 08:54:45 +08:00
fi
}
2023-03-24 22:00:34 +08:00
function version_compare( ) {
# 版本号比较 本地版本小于远程版本时返回0
local local_version = $1
local remote_version = $2
if [ [ $local_version = = $remote_version ] ] ; then
return 1
fi
if [ [ $( printf '%s\n' " $1 " " $2 " | sort -V | head -n1) = = $remote_version ] ] ; then
return 1
else
return 0
fi
}
2023-03-09 08:24:19 +08:00
# 添加变量到github env
2023-03-24 22:00:34 +08:00
function write_github_env_variable( ) {
2023-03-09 08:24:19 +08:00
echo " $1 = $2 " >> $GITHUB_ENV
}
2023-03-13 21:21:37 +08:00
2024-03-17 11:21:30 +08:00
function sync_proguard_rules( ) {
local raw_github_git = " https://raw.githubusercontent.com/chromium/chromium/ $lastest_cronet_version "
local proguard_paths = (
2024-03-17 11:44:51 +08:00
components/cronet/android/cronet_combined_impl_native_proguard_golden.cfg
2024-03-17 11:21:30 +08:00
)
2024-03-17 12:11:46 +08:00
local proguard_rules_path = " $GITHUB_WORKSPACE /app/cronet-proguard-rules.pro "
2024-03-17 11:53:54 +08:00
rm -f $proguard_rules_path
2024-03-17 11:21:30 +08:00
echo " fetch cronet proguard rules from upstream $raw_github_git "
for path in ${ proguard_paths [@] }
do
echo " fetching $path ... "
2024-03-17 11:53:54 +08:00
curl " $raw_github_git / $path " >> $proguard_rules_path
2024-03-17 11:21:30 +08:00
done
}
2023-03-13 21:21:37 +08:00
##########
2023-03-09 08:24:19 +08:00
# 获取本地cronet版本
2022-03-05 15:38:40 +08:00
path = $GITHUB_WORKSPACE /gradle.properties
current_cronet_version = ` cat $path | grep CronetVersion | sed s/CronetVersion= //`
echo " current_cronet_version: $current_cronet_version "
2023-03-24 22:00:34 +08:00
echo " fetch $branch release info from https://chromiumdash.appspot.com ... "
fetch_version
2023-03-13 21:21:37 +08:00
2023-03-24 22:00:34 +08:00
if version_compare $current_cronet_version $lastest_cronet_version ; then
2023-03-09 08:24:19 +08:00
# 更新gradle.properties
2022-03-05 15:38:40 +08:00
sed -i s/CronetVersion= .*/CronetVersion= $lastest_cronet_version / $path
2022-11-09 23:23:04 +08:00
sed -i s/CronetMainVersion= .*/CronetMainVersion= $lastest_cronet_main_version / $path
2024-03-17 11:21:30 +08:00
# 更新cronet_proguard_rules.pro
sync_proguard_rules
2023-03-09 08:24:19 +08:00
# 添加更新日志
2022-03-05 21:45:56 +08:00
sed " 15a* 更新cronet: $lastest_cronet_version " -i $GITHUB_WORKSPACE /app/src/main/assets/updateLog.md
2023-03-09 08:24:19 +08:00
# 生成pull request信息
2023-03-24 22:00:34 +08:00
write_github_env_variable PR_TITLE " Bump cronet from $current_cronet_version to $lastest_cronet_version "
write_github_env_variable PR_BODY " Changes in the [Git log](https://chromium.googlesource.com/chromium/src/+log/ $current_cronet_version .. $lastest_cronet_version ) "
2023-03-09 08:24:19 +08:00
# 生成cronet flag
2023-03-24 22:00:34 +08:00
write_github_env_variable cronet ok
2023-03-09 08:24:19 +08:00
fi