I've managed to reproduce a build phase script from this SO question which increments the build number every time I build the app. Can anyone suggest how the script should look if I want the build number to be version.build
, i.e. if my app version is 0.2, I'd like my build number to be set to 0.2.001, 0.2.002, etc. Then, when I change my build number to 0.3, I want the builds to restart to 001, so I get 0.3.001, 0.3.002, etc.
Here's my current script:
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
UPDATE
What I'm trying to do is the following:
- Get the shortVersion from plist file (e.x. 0.2)
- Get the buildNumber from plist file (e.x. 0.2.007)
- Separate the buildNumber into 0.2 and 007
- If 0.2 equals shortVersion, just increment 007 -> 008 and join the two again so the new buildNumber is 0.2.008
- Else (e.x. shortVersion has been changed to 0.3), reset the build number to 001 and join the two together to get the new buildNumber as 0.3.001
Unfortunately, I know nothing about bash scripting, so I'd be grateful if someone can provide the script.