Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Firebase App Distribution (locally)
#!/bin/bash
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
PROPERTY_FILE=local.properties
function getProperty() {
PROP_KEY=$1
# shellcheck disable=SC2002
PROP_VALUE=$(cat $PROPERTY_FILE | grep -w "$PROP_KEY" | cut -d'=' -f2-)
echo "$PROP_VALUE"
}
PRODUCT_FLAVOR="all"
BUILD_TYPE="?"
FIREBASE_REFRESH_TOKEN=""
RELEASE_NOTES=""
while getopts f:b:t:n: option; do
case "${option}" in
f) PRODUCT_FLAVOR=${OPTARG} ;;
b) BUILD_TYPE=${OPTARG} ;;
t) FIREBASE_REFRESH_TOKEN=${OPTARG} ;;
n) RELEASE_NOTES=${OPTARG} ;;
*)
printf "\nUsage: firebaseLocalDistribution [-f string] [-b string] [-t string] [-n string]
\t-f,\tproduct flavor to distribute [dev; qa; prd; all], if not specified \"all\" will be used
\t-b,\tbuild type to distribute [debug; release]
\t-t,\tfirebase refresh token, if not specified fallback will be used (local.properties, firebaseRefreshToken property)
\t-n,\trelease notes message\n\n"
exit 1
;;
esac
done
printf "\n%s\n" "${BOLD}> Checking for Firebase Token${NORMAL}"
if [ "$FIREBASE_REFRESH_TOKEN" == "" ]; then
printf "%s\n" "No ${BOLD}firebaseRefreshToken${NORMAL} value specified. Default location for fetching value will be used..."
FIREBASE_REFRESH_TOKEN=$(getProperty "firebaseRefreshToken")
if [ "$FIREBASE_REFRESH_TOKEN" == "" ]; then
printf "%s\n\n" "Bummer! No ${BOLD}firebaseRefreshToken${NORMAL} found in local.properties!"
exit 1
fi
fi
printf "\n%s\n" "${BOLD}> Distribution${NORMAL}"
export FIREBASE_TOKEN=$FIREBASE_REFRESH_TOKEN
echo "$RELEASE_NOTES" > releasenotes.txt
chmod +x ./gradlew
./gradlew --stop #Only needed for environment variable changes
if [ "$BUILD_TYPE" == "release" ]; then
if [ "$PRODUCT_FLAVOR" == "all" ]; then
echo "Starting all flavors Release distribution..."
./gradlew assembleDevRelease appDistributionUploadDevRelease --stacktrace
./gradlew assembleQaRelease appDistributionUploadQaRelease --stacktrace
./gradlew assembleProdRelease appDistributionUploadProdRelease --stacktrace
elif [ "$PRODUCT_FLAVOR" == "dev" ]; then
echo "Starting DEV flavor Release distribution..."
./gradlew assembleDevRelease appDistributionUploadDevRelease --stacktrace
elif [ "$PRODUCT_FLAVOR" == "qa" ]; then
echo "Starting QA flavor Release distribution..."
./gradlew assembleQaRelease appDistributionUploadQaRelease --stacktrace
elif [ "$PRODUCT_FLAVOR" == "prd" ]; then
echo "Starting PRD flavor Release distribution..."
./gradlew assembleProdRelease appDistributionUploadProdRelease --stacktrace
else
printf "%s\n\n" "Bummer! Project flavor ${BOLD}$PRODUCT_FLAVOR${NORMAL} unknown!"
fi
elif [ "$BUILD_TYPE" == "debug" ]; then
if [ "$PRODUCT_FLAVOR" == "all" ]; then
echo "Starting all flavors Debug distribution..."
./gradlew assembleDevDebug appDistributionUploadDevDebug --stacktrace
./gradlew assembleQaDebug appDistributionUploadQaDebug --stacktrace
./gradlew assembleProdDebug appDistributionUploadProdDebug --stacktrace
elif [ "$PRODUCT_FLAVOR" == "dev" ]; then
echo "Starting DEV flavor Debug distribution..."
./gradlew assembleDevDebug appDistributionUploadDevDebug --stacktrace
elif [ "$PRODUCT_FLAVOR" == "qa" ]; then
echo "Starting QA flavor Debug distribution..."
./gradlew assembleQaDebug appDistributionUploadQaDebug --stacktrace
elif [ "$PRODUCT_FLAVOR" == "prd" ]; then
echo "Starting PRD flavor Debug distribution..."
./gradlew assembleProdDebug appDistributionUploadProdDebug --stacktrace
else
printf "%s\n\n" "Bummer! Project flavor ${BOLD}$PRODUCT_FLAVOR${NORMAL} unknown!"
fi
else
printf "%s\n\n" "Bummer! Build type ${BOLD}$BUILD_TYPE${NORMAL} unknown!"
fi
@GuilhE

This comment has been minimized.

Copy link
Owner Author

@GuilhE GuilhE commented Feb 4, 2021

Firebase App Distribution (locally)

To distribute app-variants with one simple command by taking advantage of this helper bash script, you need to use com.google.firebase.appdistribution gradle plugin and:

  1. Add this firebaseLocalDistribution.sh to your project root;
  2. Have a google-services.json with the desired project configurations inside app module;
  3. Have a signing.properties file correctly filled (will be used here);
  4. Add firebaseRefreshToken property to local.properties with the token returned by ./gradlew appDistributionLogin (it will print in the console after successful authentication) or pass it as parameter;
  5. run chmod +x ./firebaseLocalDistribution.sh (needed first time only) and then ./firebaseLocalDistribution.sh
Usage: firebaseLocalDistribution [-f string] [-b string] [-t string]  
    	-f,	product flavor to distribute [dev; qa; prd; all], if not specified "all" will be used  
      	-b,	build type to distribute [debug; release]  
      	-t,	firebase refresh token, if not specified fallback will be used (local.properties, firebaseRefreshToken property)
      	-n,	release notes message

Grab some 🍿 and wait for the result.

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