Skip to content

Instantly share code, notes, and snippets.

@drilonrecica
Last active October 17, 2023 17:31
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save drilonrecica/3ca7ca6cc5c347b1d5dad64755a29f7e to your computer and use it in GitHub Desktop.
Save drilonrecica/3ca7ca6cc5c347b1d5dad64755a29f7e to your computer and use it in GitHub Desktop.
Bash script for automating versioning (versionCode & versionName) and setting git Tag in an android project
# Proccess:
# 1. Go into app directory
# 2. Get current versionCode and print it
# 3. Increment versionCode by one and print it
# 4. Get current versionName and print it
# 5. Ask user for new versionName and set it then print it
# 6. Stage changes to build.gradle
# 7. Go back one directory to project root
# 8. Commit version update with message Bumped up version
# 9. Tag with versionName
# 10. Push changes
#author :Drilon Recica - dre
!/usr/bin/env bash
set -e
function sedi {
if [ "$(uname)" == "Linux" ]; then
sed -i "$@"
else
sed -i "" "$@"
fi
}
echo "Welcome to the automated Versioning and Tagging of the X Android Project"
cd "app"
newVersionCode=0
# If versionCode is set with = (ex. versionCode = X) change {print $2} to {print $3}
currentVersionCode=`awk '/versionCode/ {print $2}' ./build.gradle`
echo "Current versionCode is: $currentVersionCode"
echo "Incrementing versionCode by 1 ..."
# If versionCode is set with = (ex. versionCode = X) change {print $2} to {print $3}
for entry in `awk '/versionCode/ {print $2}' ./build.gradle`; do
index=`echo ${entry}`
sedi 's/versionCode [0-9a-zA-Z -_]*/versionCode '$(($index + 1))'/' ./build.gradle
done
# If versionCode is set with = (ex. versionCode = X) change {print $2} to {print $3}
newVersionCode=`awk '/versionCode/ {print $2}' ./build.gradle`
echo "New versionCode is: $newVersionCode"
# If versionName is set with = (ex. versionName = "X.X.X") change {print $2} to {print $3}
currentVersionName=`awk '/versionName/ {print $2}' ./build.gradle`
echo "Current versionName is: $currentVersionName"
echo "Please type in the new versionName: "
read newVersionName
echo "Setting new versionName..."
sedi 's/versionName [0-9a-zA-Z -_]*/versionName "'"$newVersionName"'"/' ./build.gradle
echo "New versionName is: $newVersionName"
cd ..
currentBranch=`git symbolic-ref --short -q HEAD`
echo "$currentBranch"
git add app/build.gradle
echo "Staged changes in build.gradle"
git commit -m 'Bumped up version'
echo "Commited build.gradle changes"
git tag $newVersionName
echo "Set new tag: $newVersionName"
git push origin
echo "Pushed changes and tag to $currentBranch"
cat << "EOF"
______________________
< Who you Gonna Call >
----------------------
\ __---__
_- /--______
__--( / \ )XXXXXXXXXXX\v.
.-XXX( O O )XXXXXXXXXXXXXXX-
/XXX( U ) XXXXXXX\
/XXXXX( )--_ XXXXXXXXXXX\
/XXXXX/ ( O ) XXXXXX \XXXXX\
XXXXX/ / XXXXXX \__ \XXXXX
XXXXXX__/ XXXXXX \__---->
---___ XXX__/ XXXXXX \__ /
\- --__/ ___/\ XXXXXX / ___--/=
\-\ ___/ XXXXXX '--- XXXXXX
\-\/XXX\ XXXXXX /XXXXX
\XXXXXXXXX \ /XXXXX/
\XXXXXX > _/XXXXX/
\XXXXX--__/ __-- XXXX/
-XXXXXXXX--------------- XXXXXX-
EOF
@swikars1
Copy link

!/usr/bin/env bash --> !#/usr/bin/env bash

@dragonmaster784
Copy link

dragonmaster784 commented Jun 16, 2022

@swikars1

!/usr/bin/env bash --> !#/usr/bin/env bash

Don't you mean !/usr/bin/env bash#!/usr/bin/env bash

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