通过shell脚本创建代码分支,及本地打包

最近的有个项目是做硬件定制App开发,根据设计方案,不同功能拆分了多个App,每次新版本在代码仓库建分支时,还有本地打包时,有几个App就得重复操作几遍。后来写了两个脚本,简化操作。

操作系统为macOS。

建分支

#!/bin/bash
#该脚本需要慎重修改变量,newBranch小心不要和已存在分支同名
#创建新分支,执行此脚本需要保证主摄本地没有任何修改未提交的代码,否则会一并提交上去
oldBranch=release/15
newBranch=release/15_1
#转移字符串,为了修改本地内容
s_oldBrach="release\/15"
s_newBranch="release\/15_1"
oldVersionCode=250
newVersionCode=251
oldVersionName=2.5.0
newVersionName=2.5.1
fileFetch=fetch
fileGradleProperties=gradle.properties
fileReadme=README.md
gitMessage=升级版本号到1.5.1

#主摄
git checkout $oldBranch
git pull --rebase origin $oldBranch
#切换分支
git checkout -b $newBranch
git push origin $newBranch
#修改本地配置文件
sed -i "" "s/$s_oldBrach/$s_newBranch/g" $fileFetch
sed -i "" "s/$oldVersionCode/$newVersionCode/g" $fileGradleProperties
sed -i "" "s/$oldVersionName/$newVersionName/g" $fileGradleProperties
sed -i "" "s/$oldVersionName/$newVersionName/g" $fileReadme
#提交git,添加文件
git add $fileFetch
git add $fileGradleProperties
git add $fileReadme
git commit -am $gitMessage
#提交评审,这步需要手动输入Reviewer
mk ak

#CommonAbility
commonAbilityPath="CommonAbility"
if [ ! -x "$commonAbilityPath" ];
then
  mkdir "$commonAbilityPath"
  git clone -b $oldBranch 【代码仓库git地址】
fi
cd $commonAbilityPath
git pull --rebase origin $oldBranch
#切换分支
git checkout -b $newBranch
git push origin $newBranch
cd ..

#TenMtkCommon
tenMtkCommonPath="TenMtkCommon"
if [ ! -x "$tenMtkCommonPath" ];
then
  mkdir "$tenMtkCommonPath"
  git clone -b $oldBranch 【代码仓库git地址】
fi
cd $tenMtkCommonPath
git pull --rebase origin $oldBranch
#切换分支
git checkout -b $newBranch
git push origin $newBranch
cd ..

#前向
roadCollectorPath="RoadCollector"
if [ ! -x "$roadCollectorPath" ];
then
  mkdir "$roadCollectorPath"
  git clone -b $oldBranch 【代码仓库git地址】
fi
cd $roadCollectorPath
git checkout $oldBranch
git pull --rebase origin $oldBranch
#切换分支
git checkout -b $newBranch
git push origin $newBranch
#修改本地配置文件
sed -i "" "s/$s_oldBrach/$s_newBranch/g" $fileFetch
sed -i "" "s/$oldVersionCode/$newVersionCode/g" $fileGradleProperties
sed -i "" "s/$oldVersionName/$newVersionName/g" $fileGradleProperties
#提交git,添加文件
git add $fileFetch
git add $fileGradleProperties
git commit -am $gitMessage
#提交评审,这步需要手动输入Reviewer
mk ak
cd ..
rm -rf $roadCollectorPath

#自检
inspectionPath="InspectionService"
if [ ! -x "$inspectionPath" ];
then
  mkdir "$inspectionPath"
  git clone -b $oldBranch 【代码仓库git地址】
fi
cd $inspectionPath
git checkout $oldBranch
git pull --rebase origin $oldBranch
#切换分支
git checkout -b $newBranch
git push origin $newBranch
#修改本地配置文件
sed -i "" "s/$s_oldBrach/$s_newBranch/g" $fileFetch
sed -i "" "s/$oldVersionCode/$newVersionCode/g" $fileGradleProperties
sed -i "" "s/$oldVersionName/$newVersionName/g" $fileGradleProperties
#提交git,添加文件
git add $fileFetch
git add $fileGradleProperties
git commit -am $gitMessage
git push origin $newBranch
cd ..
rm -rf $inspectionPath

#安装
installerPath="InstallerService"
if [ ! -x "$installerPath" ];
then
  mkdir "$installerPath"
  git clone -b $oldBranch 【代码仓库git地址】
fi
cd $installerPath
git checkout $oldBranch
git pull --rebase origin $oldBranch
#切换分支
git checkout -b $newBranch
git push origin $newBranch
#修改本地配置文件
sed -i "" "s/$s_oldBrach/$s_newBranch/g" $fileFetch
sed -i "" "s/$oldVersionCode/$newVersionCode/g" $fileGradleProperties
sed -i "" "s/$oldVersionName/$newVersionName/g" $fileGradleProperties
#提交git,添加文件
git add $fileFetch
git add $fileGradleProperties
git commit -am $gitMessage
git push origin $newBranch
cd ..
rm -rf $installerPath

本地打多个App包

#!/bin/bash
#在当前应用下构建其他app
currentBranchVersion=release/15
type=assembleDebug

#前向
roadCollectorPath="RoadCollector"
if [ ! -x "$roadCollectorPath" ];
then
  mkdir "$roadCollectorPath"
  git clone -b $currentBranchVersion 【代码仓库git地址】
fi
cd $roadCollectorPath
#切换分支
git checkout $currentBranchVersion
git pull --rebase origin $currentBranchVersion
#构建
./fetch
./gradlew clean $type --stacktrace --no-daemon -PIS_TEST_PHOTO=true
cd ..

#自检
inspectionPath="InspectionService"
if [ ! -x "$inspectionPath" ];
then
  mkdir "$inspectionPath"
  git clone -b $currentBranchVersion 【代码仓库git地址】
fi
cd $inspectionPath
#切换分支
git checkout $currentBranchVersion
git pull --rebase origin $currentBranchVersion
#构建
./fetch
./gradlew clean $type --stacktrace --no-daemon
cd ..

#安装
installerPath="InstallerService"
if [ ! -x "$installerPath" ];
then
  mkdir "$installerPath"
  git clone -b $currentBranchVersion 【代码仓库git地址】
fi
cd $installerPath
#切换分支
git checkout $currentBranchVersion
git pull --rebase origin $currentBranchVersion
#构建
./fetch
./gradlew clean $type --stacktrace --no-daemon
cd ..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值