Skip to content

Instantly share code, notes, and snippets.

@oradkovsky
Created July 9, 2021 08:09
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 oradkovsky/0bbfe2cac861b921c0164c9020aa3d82 to your computer and use it in GitHub Desktop.
Save oradkovsky/0bbfe2cac861b921c0164c9020aa3d82 to your computer and use it in GitHub Desktop.
Automated versioning based on tags
#!/bin/bash
# The greatest value Google Play allows for versionCode is 2100000000 and is not checked here for simplicity :)
RES=$(git show-ref --tags)
if [ -z "$RES" ]; then
NEW_TAG="1.0.0-1"
else
LATEST_TAG=$(git describe --tags --abbrev=0 --match *.*.*-*)
echo "Latest detected tag is $LATEST_TAG"
IFS='.' read -r -a array <<<${LATEST_TAG}
major=${array[0]}
minor=${array[1]}
remainder=${array[2]}
IFS='-' read -r -a array <<<${remainder}
point=${array[0]}
code=${array[1]}
echo "Parsed major $major"
echo "Parsed minor $minor"
echo "Parsed point $point"
echo "Parsed code $code"
if [ "$point" == "999" ]; then
if [ "$minor" == "999" ]; then
point=0
minor=0
((major++))
else
((minor++))
point=0
fi
elif [ "$minor" == "999" ] && [ "$point" == "999" ]; then
((major++))
minor=0
else
((point++))
fi
((code++))
NEW_TAG="${major}.${minor}.${point}-${code}"
fi
echo "New tag should be $NEW_TAG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment