Hi,
I do set the build number based on a git pre-commit hook for every commit.
Using tools like autohook you should be quite fast in fitting this to your own processes.
As an example the script I use:
#!/usr/bin/env bash
git=$(which git)
PlistBuddy="/usr/libexec/PlistBuddy"
REPO_ROOT_PATH=$("$git" rev-parse --show-toplevel)
GIT_BRANCH_NAME=$("$git" -C "$REPO_ROOT_PATH" branch --show-current)
GIT_HASH=$("$git" -C "$REPO_ROOT_PATH" show -s --format=%H)
GIT_NUMBER_OF_COMMITS=$("$git" -C "$REPO_ROOT_PATH" rev-list HEAD --count)
GIT_RELEASE_VERSION=$("$git" -C "$REPO_ROOT_PATH" describe --tags --always --abbrev=0)
IOS_PLIST_PATH="$REPO_ROOT_PATH/iOS/Info.plist"
MACOS_PLIST_PATH="$REPO_ROOT_PATH/macOS/Info.plist"
TVOS_PLIST_PATH="$REPO_ROOT_PATH/tvOS/Info.plist"
echo "GIT: $git"
echo "NUMBER_OF_COMMITS: $GIT_NUMBER_OF_COMMITS"
echo "RELEASE_VERSION: $GIT_RELEASE_VERSION"
for plist in "$IOS_PLIST_PATH" "$MACOS_PLIST_PATH" "$TVOS_PLIST_PATH"; do
if [ -f "$plist" ]; then
echo "PATCH: $plist"
"$PlistBuddy" -c "Set :CFBundleVersion $GIT_NUMBER_OF_COMMITS" "$plist"
"$PlistBuddy" -c "Set :GitBranchName $GIT_BRANCH_NAME" "$plist"
"$PlistBuddy" -c "Set :GitHash $GIT_HASH" "$plist"
"$git" add "$plist"
fi
done
Kind regards,
Sascha