Skip to content

Instantly share code, notes, and snippets.

@bensig
Created January 17, 2022 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bensig/b136914edf7e95b8afb89f65553bca7f to your computer and use it in GitHub Desktop.
Save bensig/b136914edf7e95b8afb89f65553bca7f to your computer and use it in GitHub Desktop.
Script to update version in Info.plist and app/build.gradle
#!/bin/sh
# bash script to update build number
# variables
PLIST=`find ./ios -name "Info.plist"`
GRADLE=`find ./android/app -name "build.gradle"`
BRANCH=`git symbolic-ref --short -q HEAD`
# announcement
echo
echo "This script should be run after a release has been pushed live on the app stores."
# check git branch
echo
if [[ "$BRANCH" != "dev" ]]; then
read -p "You are on the branch $BRANCH instead of dev - continue? "
else
echo "You are on the dev branch"
fi
echo
# check if git is clean
if [[ -z $(git status -s) ]]; then
echo "Git status is clean"
else
echo "Found some uncommitted files on your branch."
git status -s
read -p "Git is not clean, do you want to continue? "
fi
echo
# first update git
echo
echo "Pulling from git to ensure you are up to date."
git pull
echo
# get current versions
echo "Getting current version numbers..."
androidVersion=`cat $GRADLE |grep -m1 "versionName" | cut -d'"' -f2 | tr -d ';' | tr -d ' '`
iosVersion=`plutil -p $PLIST|grep CFBundleShortVersionString | cut -d ">" -f2|cut -d'"' -f2`
# show current versions
echo "Current iOS Version: $iosVersion"
echo "Current Android Version: $androidVersion"
echo
if [[ "$iosVersion" != "$androidVersion" ]]; then
read -p "Different versions detected, continue? "
else
echo "Versions are synchronized on iOS and Android"
fi
# tag state for release
echo
if [[ "$iosVersion" = "$androidVersion" ]]; then
read -p "Would you like to add a tag for the current release ($iosVersion) before updating? (y/n)? " answer
# if echo "$answer" | grep -iq "^y" ;then
if [[ "$answer" != "${answer#[Yy]}" ]] ;then # this grammar (the #[] operator) means that the variable $answer where any Y or y in 1st position will be dropped if they exist.
echo "Adding git tag for release-$iosVersion"
git tag release-$iosVersion
fi
else
echo "Since version numbers not synchronized, not adding a tag to Github for the current release."
fi
echo
# get new version from user input
echo
echo "Great, let's set a new version number."
read -p "Please enter the version number to set: " version
echo
# confirm new version change
read -p "Changing iOS and Android versions to $version - continue? "
echo
# change to new version
echo "Changing version numbers..."
sed -i '' -e 's/'"$iosVersion"'/'"$version"'/g' $PLIST
sed -i '' -e 's/'"$androidVersion"'/'"$version"'/g' $GRADLE
echo
# get new versions
echo "Getting new version numbers..."
androidVersion=`cat $GRADLE |grep -m1 "versionName" | cut -d'"' -f2 | tr -d ';' | tr -d ' '`
iosVersion=`plutil -p $PLIST|grep CFBundleShortVersionString | cut -d ">" -f2|cut -d'"' -f2`
# display new versions
echo "New iOS Version: $iosVersion"
echo "New Android Version: $androidVersion"
echo
# push new version to github
read -p "Would you like to push this new version to Github on the current branch? (y/n)? " answer
# if echo "$answer" | grep -iq "^y" ;then
if [[ "$answer" != "${answer#[Yy]}" ]] ;then # this grammar (the #[] operator) means that the variable $answer where any Y or y in 1st position will be dropped if they exist.
git add $GRADLE
git add $PLIST
git commit -m "Update ios plist and android gradle to $iosVersion"
git push --tags && git push
fi
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment