Last active
October 17, 2023 17:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
!/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
!/usr/bin/env bash
-->!#/usr/bin/env bash