Last active
January 29, 2024 13:15
-
-
Save kibotu/d24d6dcc08ffddfcaec02219c674bea7 to your computer and use it in GitHub Desktop.
extract_app_version.sh
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
#!/bin/bash | |
export LANG=en_US.UTF-8 | |
export LANGUAGE=en_US.UTF-8 | |
export LC_ALL=en_US.UTF-8 | |
# Check if -man option is passed | |
if [ -f "version-properties.gradle" ]; then | |
APP_VERSION_RAW=$(grep "appVersion *=" version-properties.gradle) | |
else | |
echo " | |
# Man Page for Version Properties Script | |
NAME | |
extract_app_version.sh - A script to fetch and format app version details from a Gradle file. | |
SYNOPSIS | |
extract_app_version.sh | |
DESCRIPTION | |
This bash script is used to fetch the application version details from a Gradle properties file named "version-properties.gradle". | |
It looks for the line with "appVersion" and extracts the version information, including major, minor, hotfix versions and build number. | |
The script then exports an environment variable that represents the release branch name in a specific format. | |
OPTIONS | |
This script does not accept any command line options. | |
EXAMPLES | |
Running the script without any options: | |
./extract_app_version.sh | |
NOTES | |
This scripts makes use of several Unix/Linux commands such as grep, sed, awk. Make sure these utilities are installed on your system. | |
The script expects that a file named "version-properties.gradle" is present in the same directory where this script is run." | |
exit 1 # Exit after displaying man page. | |
fi | |
APP_VERSION=$(echo "$APP_VERSION_RAW" | sed 's/[ \"]//g' | awk -F '[=]' '{print $2}') | |
APP_MAJOR=$(echo "$APP_VERSION_RAW" | sed 's/[ \"]//g' | awk -F '[.=/#]' '{print $2}') | |
APP_MINOR=$(echo "$APP_VERSION_RAW" | sed 's/[ \"]//g' | awk -F '[.=/#]' '{print $3}') | |
APP_HOTFIX_VERSION=$(echo "$APP_VERSION_RAW" | sed 's/[ \"]//g' | awk -F '[.=/#]' '{print $4}') | |
APP_BUILD_NUMBER=$(echo "$APP_VERSION_RAW" | sed 's/[ \"]//g' | awk -F '[.=/#]' '{print $5}') | |
if [[ -z $BUILD_NUMBER ]]; then | |
APP_BUILD_NUMBER=0 | |
fi | |
if [[ $APP_HOTFIX_VERSION -ne "" ]]; then | |
APP_HOTFIX_VERSION=".$APP_HOTFIX_VERSION" | |
fi | |
export BUILD_BRANCH="release/$APP_MAJOR.$APP_MINOR$APP_HOTFIX_VERSION" | |
echo ${BUILD_BRANCH} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment