Forked from drilonrecica/android-version-and-tag-automation.sh
Created
December 31, 2021 06:22
-
-
Save zinwalin/ae376867c29f1756767cc6b25aeb1eb7 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 hidden or 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment