Skip to content

Instantly share code, notes, and snippets.

@samermurad
Last active October 16, 2018 10:31
Show Gist options
  • Save samermurad/b0133d104e762293aa2cc65e3d82f70e to your computer and use it in GitHub Desktop.
Save samermurad/b0133d104e762293aa2cc65e3d82f70e to your computer and use it in GitHub Desktop.
Add Git Hash to iOS App plist: Put this code under a new "run script" in Project>Target>Run Phases> Create new run script
#!/bin/sh
gitHash=$(/usr/libexec/PlistBuddy -c "Print :GitHash" "${PROJECT_DIR}/${INFOPLIST_FILE}")
exitCode=$?
if [ $exitCode == 0 ]; then
gitHash=$(git rev-parse HEAD | cut -c1-10)
/usr/libexec/PlistBuddy -c "Set :GitHash $gitHash" "${PROJECT_DIR}/${INFOPLIST_FILE}"
else
gitHash=$(git rev-parse HEAD | cut -c1-10)
/usr/libexec/PlistBuddy -c "Add :GitHash string $gitHash" "${PROJECT_DIR}/${INFOPLIST_FILE}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment