Created
          July 9, 2021 08:09 
        
      - 
      
- 
        Save oradkovsky/0bbfe2cac861b921c0164c9020aa3d82 to your computer and use it in GitHub Desktop. 
    Automated versioning based on tags
  
        
  
    
      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
    
  
  
    
  | #!/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