Skip to content

Instantly share code, notes, and snippets.

@crgarridos
Created November 5, 2018 20:37
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 crgarridos/2f34e6d20273e979b60aa066ef12ded6 to your computer and use it in GitHub Desktop.
Save crgarridos/2f34e6d20273e979b60aa066ef12ded6 to your computer and use it in GitHub Desktop.
Used to deliver apk
#!/bin/bash
while getopts dhv: option
do
case "${option}"
in
d) DEV_BUILD=true
echo "Running dev config..." ;;
v) TAG=${OPTARG};;
h) echo "Usage :"
echo -e "\t$0 [option...]"
echo
echo -e "\t-h \t: Show this message."
echo -e "\t-d \t: Compile only assembleTabletRelease task using -PdevBuild. Does not create the tag."
echo -e "\t-v <x.y.z>\t: Specify the number version and tag to use, where x,y and Z are integers."
echo
exit 0;;
esac
done
TAG=$1
echo 'Checking version...'
echo "Last used is $(git describe --tags --abbrev=0)"
## Git tag checkings
echo $'-----------------------------------------'
TAG_REGEX="^v?[0-9]+(\.[0-9]+)+[[:alnum:]|_-]*$"
while ! [[ "${TAG}" =~ ${TAG_REGEX} ]]; do
read -p "New git tag : " TAG
if ! [[ ${TAG} =~ ${TAG_REGEX} ]] && [[ ${TAG} != "" ]] ; then
echo "Invalid format, use x.y.z format"
fi
done
#Add v prefix it does not is present
if [[ ${TAG} != v* ]] ; then
TAG="v"${TAG}
fi
echo "Using version (tag) : $TAG"
## Build APKs
echo $'-----------------------------------------'
BUILD=$(date +%y%m%d%H%M)
echo $'Build APK: '${BUILD}
OPTIM="--configure-on-demand --daemon --parallel -x lint -x test"
COMMON_ARGS="-PbuildNum=$BUILD "${OPTIM}
if [[ ${DEV_BUILD} ]]; then
echo "Building APk with 'devBuild' property"
./gradlew assembleDebug -PdevBuild -Papi=DEV -PapkVersion=${TAG}dev ${COMMON_ARGS} || { echo "DEV APK Failed !"; exit 1; }
else
./gradlew :app:assembleRelease -Papi=PREPROD -PapkVersion=${TAG} ${COMMON_ARGS} || { echo "PREPROD APK Failed !"; exit 2; }
./gradlew :app:assembleRelease -Papi=PROD -PapkVersion=${TAG} ${COMMON_ARGS} || { echo "PROD APK Failed !"; exit 3; }
#log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
# Display tickets/commits²
echo $'-----------------------------------------'
COMMITS=$(git log `git describe --tags --abbrev=0`..HEAD --oneline --pretty=format:'- %h | %s\n')
TICKETS=$(echo -e ${COMMITS} | egrep -o '((TFS|TG)[ -]?[0-9]+)' | sort -u)
TAG_RESUME="\n**Tickets :**\n\n- "$(echo -e ${TICKETS} | sed -e 's/\s/\\n- /g')
TAG_RESUME=${TAG_RESUME}"\n\n**_Principal commits :_**\n\n "${COMMITS}
TAG_RESUME=${TAG_RESUME}"\n\n**_APKs :_**\n\n "
echo -e ${TAG_RESUME}
echo $'-----------------------------------------'
#Create the tag
echo "Creating tag $TAG..."
git tag -a ${TAG} -m "$TAG ("`date +%d/%m/%Y`")"
git push origin ${TAG}
echo "Git Tag created : $TAG"
fi
echo "DONE !"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment