From ca3dea190d7267527d0b4afc366830144c7f7730 Mon Sep 17 00:00:00 2001 From: DarthBenro008 Date: Sat, 5 Sep 2020 22:43:30 +0530 Subject: [PATCH] feat: firebase support --- action.yml | 16 ++++++++++++- entrypoint.sh | 66 ++++++++++++++++++++++++++++++++++++++------------- flutter.sh | 5 ++++ 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index d566b7d..5689e5d 100644 --- a/action.yml +++ b/action.yml @@ -16,7 +16,21 @@ inputs: abi: description: "Target ABI for flutter builds" requried: false - + firebase: + description: "Contents of your google-services.json file" + requried: false + keystore: + description: "The text dump you generated of your keystore" + requried: false + keystorePassword: + description: "Password of your keystore file" + requried: false + keyAlias: + description: "Key alias of your key that needs to be signed" + requried: false + keyPassword: + description: "Password of the key in your keystore file" + requried: false outputs: result: description: "Result of automated send" diff --git a/entrypoint.sh b/entrypoint.sh index b4702a9..92cd979 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,28 +10,63 @@ GREEN='\033[0;32m' NC='\033[0m' # Functions + +errorHandler(){ + echo -e "${RED}Error Due to : $1 ${NC}" + exit 1 +} + sendpackage(){ echo -e "${GREEN}Package Name is set to $packageName${NC}" output=$(curl --location --request POST 'http://appbrickie.herokuapp.com/api/sendPackage' \ --form 'file=@app/build/outputs/apk/debug/'$packageName'' \ --form 'id='$INPUT_CHATID'' \ --form 'msg=Build Successful https://www.github.com/'$GITHUB_REPOSITORY'/commit/'$GITHUB_SHA'') - echo "::set-output name=result::$output" -} + echo "::set-output name=result::$output" + } -renamePackage(){ - { - mv app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/debug/"$packageName" - }||{ - echo -e "${RED}File Renaming Error, reverting to app-debug.apk name${NC}" - packageName="app.apk" - } + renamePackage(){ + { + mv app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/debug/"$packageName" + }||{ + echo -e "${RED}File Renaming Error, reverting to app-debug.apk name${NC}" + packageName="app.apk" + } -} + } + + apkSigner(){ + echo -e "${GREEN} This app is being signed with a custom key ${NC}" + ksPassword=$INPUT_KEYSTOREPASSWORD + kAlias=$INPUT_KEYALIAS + echo "$INPUT_KEYSTORE" | base64 --decode > key.jks + { + zipalign -v -p 4 app/build/outputs/apk/debug/$packageName app/build/outputs/apk/debug/$packageName + apksigner sign --ks key.jks --ks-key-alias kAlias --ks-pass env:INPUT_KEYPASSWORD --out app/build/outputs/apk/debug/$packageName app/build/outputs/apk/debug/$packageName + }||{ + errorHandler "Failed to sign apk!" + } + echo -e "${GREEN} Apk signed successfully ! ${NC}" + } nativeBuild(){ - bash ./gradlew test --stacktrace - bash ./gradlew assembleDebug --stacktrace + if [ -z "$INPUT_FIREBASE" ] + then + : + else + echo -e "${GREEN} This app uses firebase, extracting info ${NC}" + echo "$INPUT_FIREBASE" > app/google-services.json + fi + { + bash ./gradlew test --stacktrace + bash ./gradlew assembleDebug --stacktrace + }||{ + errorHandler "Failed to compile android app!" + } +if [ -z "$INPUT_KEYSTORE" ] +then + apkSigner +else if [ -z "$INPUT_PACKAGENAME" ] then sendpackage @@ -40,7 +75,8 @@ nativeBuild(){ packageName="$rectifiedName.apk" renamePackage sendpackage - fi + fi +fi } flutterBuild(){ @@ -48,10 +84,6 @@ flutterBuild(){ bash /flutter.sh } -errorHandler(){ - echo -e "${RED}Error Due to : $1 ${NC}" - exit 1 -} # Main case $INPUT_TYPE in diff --git a/flutter.sh b/flutter.sh index 25ddd83..131140c 100755 --- a/flutter.sh +++ b/flutter.sh @@ -39,6 +39,11 @@ flutter precache yes "y" | flutter doctor --android-licenses flutter doctor -v flutter upgrade +if [ -z "$INPUT_FIREBASE" ] +then + continue +else + echo "$INPUT_FIREBASE" > android/app/google-services.json if [ -z "$INPUT_ABI" ] then flutter build apk