How to easily CI/CD a Flutter app on test environment?
Hello dev, have you ever had to distribute an app to your QA team? I guess every dev have been through this right? Thats why I decided to talk about CI/CD using Github Actions and Firebase App Distribution… Do you know those things are? No? Ok, don’t worry and stay with me because we are going to figure it out how to use those!
First let’s start talking about with Github, because it is not just a simple place to save your code and if you walked through the tabs on the top of it, maybe you read something like “actions” and that’s exactly it, Github Actions is an easy way to automate your build, test and deploy process.
Ok, no more talking and let’s start with this Github Actions setup, ho ahead and click on the “Actions” tab to see a screen like this one bellow.
Click on one of the options to set up the workflow, in my case I just clicked on the “set up a workflow yourself” because I’ll just past this script bellow and it will not make any difference.
Wow so many things going on here, but don’t worry you just have to replace wherever have this <> tags with the values you need, for example on the top of the script put the branch you want to be triggered when you have a push and a/or pull request and the magic will happen. Pay attention that we are only working with the Android build because we don’t need all the certificates from iOS.
Moving forward, let’s do the Firebase part… First make sure to create the Firebase project and integrate it on your Flutter Android project. After doing it, install on your machine the Firebase CLI because we are going to need the login token after login on it.
And talking about that, let’s do it right now… open you terminal and execute this command “firebase login:ci — no-localhost”, and your browser will pop up asking to do a login, now it’s time to login with your google account, and after doing that make sure to copy te given token. With this token copied, paste it on the terminal and copy the new given token to some where. Take a look on the images below if you have any doubts.
On your Github project, go to the “Settings” and select the “Secrets” option, as the image below, and now create the FIREBASE_TOKEN with the copied token, and create FIREBASE_ANDROID_APPID with the Firebase android app id. And still on the Firebase go to the App Distribution and activate it for the Android project and make sure to create the group, with the value that you put on the <FIREBASE-GROUP-NAME>, with at least one valid email, because everyone on this group will receive a notification about the app after the deploy process.
See it’s not that hard and you just need to do it once, however you need to pay attention on the details because if you forget or put something wrong it’s not going to work. Now every time you make a push to your chosen branch, your team will receive a notification to download the app and nobody will bug you to build an app manually to be tested.