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 increase the build number for each build, but to me this seems excessive, and I would like to have a build number that testers can refer to when sender feedback).
I added the following as a Run Script in Build Phases:
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion `git rev-parse --short HEAD`" *.plist
And then I read out the bundle version in the code with:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
However, then the new revision number does not appear in the code until the next build. I assume this is because the plist file is already read by the compiler when my script is run.
Also, since the plist is changed with the revision string after committing to git, this causes an annoying diff in the project, so maybe I am not so smart after all.
An alternative would be to write the revision number to a text file (build.txt) which is ignored by git. But I would still like the project build number to follow git as well.
Anyone know a brilliant way to do this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With