Skip to content

Instantly share code, notes, and snippets.

@kibotu
Last active March 10, 2021 07:10
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 kibotu/ffbf2d0c329db525967614172bb5383b to your computer and use it in GitHub Desktop.
Save kibotu/ffbf2d0c329db525967614172bb5383b to your computer and use it in GitHub Desktop.
Extracting app version from version-properties.gradle
#!/usr/bin/env bash
echo ">> Step: Extracting app version from versions.properties. <<"
if [ -f "version-properties.gradle" ]; then
APP_VERSION_RAW=$(grep "appVersion *=" version-properties.gradle)
else
echo "Could not detect version-properties.grade file, aborting..."
exit 1
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 $HOTFIX_VERSION ]]; then
APP_HOTFIX_VERSION=0
fi
if [[ -z $BUILD_NUMBER ]]; then
APP_BUILD_NUMBER=0
fi
export BUILD_BRANCH="release/${APP_MAJOR}.${APP_MINOR}.${APP_HOTFIX_VERSION}"
ext {
/**
* This is the (external) app version.
* It will be used e.g. to: load the gradle script, load the app settings, etc.
*
* This parameter is mandatory.
*/
appVersion="3.13.0.0"
}
@kibotu
Copy link
Author

kibotu commented Mar 10, 2021

#!/usr/bin/env bash

curl https://gist.githubusercontent.com/kibotu/ffbf2d0c329db525967614172bb5383b/raw/8deeb167264fd0cdeb112d1942a821016df682dc/extract_app_version.sh --output extract_app_version.sh

. extract_app_version.sh

echo $BUILD_BRANCH 

prints release/1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment