在iOS世界中,您希望保持内部版本号唯一(CFBundleVersion)。 将应用程序提交到appStore时,Apple将检查您之前是否尚未提交具有相同编号的版本。 内部版本号也必须大于您以前的内部版本号。 否则,苹果将拒绝它。
那么,当使用git分支模型时,如何保持该数字不变?
您显然可以手动跟踪内部版本号并自己增加,但是我觉得这很麻烦。 您可以编写一个脚本,该脚本每次在xCode中构建时都会破坏您的内部版本号,但是根据我的经验,当您有多个开发人员在各自的分支上构建不同的发行版时,这些脚本就开始崩溃。
因此,今天我将带您完成一个将内部版本号保存在中央位置的过程,以便在创建新内部版本时始终可以确保内部版本号是唯一的。
首先,您需要选择哪个分支将保留事实。 在这个例子中,我将使用develop。
创建新版本时,第一个任务是检查最新版本号并增加它。
# the truth for the current bundle version is on develop, switch branch and get the number # but first save the branch we are currently on to be able to come back BUILD_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# switch branch git checkout develop
# get the current build number from the plist BUNDLE_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "app/Info.plist")
# bump and save the bundle version BUNDLE_VERSION=$(($BUNDLE_VERSION + 1))
现在知道了新的内部版本号,我们可以返回到发布分支并将更改保存在那里。
# switch back to the branch we're building git checkout $BUILD_GIT_BRANCH
# save the new bundle version in info.plist /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUNDLE_VERSION" "app/Info.plist"
echo "Build number set to: $BUNDLE_VERSION"
但是等等我们还没有完成。 您可以在此处构建应用程序。 但是,如果我们不提交这些更改并将其推送到git,那就像我们什么也没做。 另外,由于我们希望developer分支保留有关内部版本号的真相,因此我们也必须将内部版本号保存在那里。
如果构建成功,我只想保存该新的构建号。 在这种情况下,我运行以下脚本。
### add the change to the git index git add app/Info.plist
# give a nice commit message git commit -m "Bumping version"
### push changes to server for the release branch # get the current branch git rev-parse --abbrev-ref HEAD
# push all changes git push --set-upstream origin $GIT_BRANCH
### cherry pick the last commit from the release branch to develop (commit with the version bump) # first change to the develop branch git checkout develop
#cherry pick (--strategy-option theirs forces to accept the change coming in over what is already here) git cherry-pick $GIT_BRANCH --strategy-option theirs
# push change to develop git push origin develop
#go back to original branch so we can keep the build process going git checkout $GIT_BRANCH
添加一些错误处理,您就可以正常进行。