Skip to content

Instantly share code, notes, and snippets.

@loama
Last active February 18, 2021 17:39
Show Gist options
  • Save loama/0a3972d86c0f5732a599bad7de9c6829 to your computer and use it in GitHub Desktop.
Save loama/0a3972d86c0f5732a599bad7de9c6829 to your computer and use it in GitHub Desktop.
A script usable as a git pre-commit hook that sets the CFBundleVersion of a specified plist to the current timestamp. This is useful for iOS Capacitor apps that require updating the bundle version before uploading to iTunes connect.
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)
# Redirect output to stderr.
exec 1>&2
git=`sh /etc/profile; which git`
# Since this a pre-commit script we don't want the *current* commit count, we want the commit count we're about to make
d=`date +%Y%m%d.%T`
plistFilename="/Users/jaime/GitHub/postall/app/ios/App/App/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${d//:}" "$plistFilename"
$git add "$plistFilename"
echo "Bumped version in $plistFilename to $nextCommit and staged the file."
@loama
Copy link
Author

loama commented Feb 10, 2021

Inspired from https://gist.github.com/HiddenJester/711365db5fc5981bd87a, this might have extra unnecessary code. I have zero experience in bash, but this is working.

You just need to change the plist path in line 29

@loama
Copy link
Author

loama commented Feb 10, 2021

Especially useful if you are using appflow to have your app deployed automatically after commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment