Set Xcode bundle version to git hash

前端 未结 4 1004
野的像风
野的像风 2021-02-01 19:01

In Xcode, I want to set the project bundle version to the git hash, to create a unique link between a revision and a build.

(I have seen several postings about this that

相关标签:
4条回答
  • 2021-02-01 19:26

    https://gist.github.com/966838 is a short bash script that meets Apple's requirement that CFBundleVersion should be a monotonically increased string.

    0 讨论(0)
  • 2021-02-01 19:27

    You will need to install PlistBuddy to use this method.

    The method that I use is to set the script as the last build phase, and make the changes on the target build directory. In other words:

    BUILD_NUMBER=`git rev-parse --short HEAD`
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${TARGET_BUILD_DIR}"/"${INFOPLIST_PATH}"
    

    So in the repo the value should be a dummy value like 0, and it will get overwritten everytime. This does mean that the current build number will only be available after you build.

    0 讨论(0)
  • 2021-02-01 19:30

    There have been quite a few ways to do this.

    I used to run a post build script to inject the sha into the bundle:

    https://gist.github.com/208825

    But a more modern method is on the Cocoa is my Girlfriend blog http://www.cimgf.com/2011/02/20/revisiting-git-tags-and-building/

    0 讨论(0)
  • 2021-02-01 19:34

    I wrote a much shorter script for this. Bash can accomplish the task; no need for other interpreters.

    0 讨论(0)
提交回复
热议问题