最近的有个项目是做硬件定制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 ..