Skip to content

Instantly share code, notes, and snippets.

@nhancv
Last active May 15, 2023 16:51
Show Gist options
  • Save nhancv/2711d460c5069560c7eeebde6002aae2 to your computer and use it in GitHub Desktop.
Save nhancv/2711d460c5069560c7eeebde6002aae2 to your computer and use it in GitHub Desktop.
React native: Bash script to update Info.plist version
#!/usr/bin/env bash -e
_PROJECT_NAME=$(cat package.json | grep name | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
_INFOPLIST_DIR="ios/${_PROJECT_NAME}/Info.plist"
_PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
# Set BUILD_NUMBER to the value 1 only if it is unset.
: ${BUILD_NUMBER=$(expr $(git log -1 --pretty=format:%ct) / 3600)}
# Update plist with new values
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${_PACKAGE_VERSION#*v}" "${_INFOPLIST_DIR}"
BUNDLE_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${_INFOPLIST_DIR}")
if [ "$BUNDLE_VERSION" != "$BUILD_NUMBER" ]
then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${_INFOPLIST_DIR}"
fi
echo "-----------------------------"
echo "PROJECT_NAME: " $_PROJECT_NAME
echo "PACKAGE_VERSION: " $_PACKAGE_VERSION
echo "BUILD_NUMBER: " $BUILD_NUMBER
echo "-----------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment