Github Action and Firebase App Distribution — CI/CD Ways — Part 2

Stephen Oyebanji
5 min readFeb 13, 2023

--

Yep, you’re not lost.

Welcome to part two on CI/CD ways. If you’ve not yet read part 1, what are you waiting for? Go read it here.

I will wait for you to return here.

Great, In part one we learn how we could hook our flutter project(or any project actually) to GitHub action, here we will use GitHub action to build an apk and upload it to firebase app distribution, so we can easily share it with our group of testers.

Head over to firebase console and create a project if you've not done that yet. If this is your first project with firebase, you will need to install firebase on your local machine.

Head over here to get a more detailed guide to installing firebase CLI, but let's go over it here: Open up your terminal and run

npm install -g firebase-tools

After that has ran a successfully installation, login to your firebase account.

firebase login

Now, over to your flutter project, open up the terminal and install flutterfire_cli

dart pub global activate flutterfire_cli

ensure you add the installation to your machine env. Configure your project by running

flutterfire configure

If you get an error like command not found: flutterfire it means you’ve not added your installation to env and your machine doesn’t know you have flutterfire CLI installed. If you’ve installed everything right. The above command should display the list of projects you have on your console and an option to create a new project. If you have an existing project, simply select it. If not create a new project and follow the prompts and you should have a project up and running in no time on firebase.

So, flutterfire configure syncs your project to firebase and adds the required dependencies and file (firebase_options.dart) to your project.
Next, you are required to add the firebase_core package to your pubspec.yaml to clear the error in the firebase_options file.

flutter pub add firebase_core

and add the below code in the main.dart file in the main method


void main() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}

Next, modify your GitHub action workflow file to the below code. If you don’t know where the file is located. You need to read part one of this article in that case

Yep. Github action is set to build and publish our app apk to firebase, but we need to set up our APP_ID and CREDENTIAL_FILE_CONTENT secret for line 32 and 33.

Head over to the repo > settings > secret and variable > Actions > Click New Repository Secret

Add your app id from firebase > to get the APP_ID, we could get this in two methods:

Method 1: Go to your firebase_options.dart file, open it and scroll till you see a code like below. Copy the app id and paste it.

static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSy******************',
appId: '1:2********:android:8**********', //your app id
messagingSenderId: '23454676532',
projectId: 'cicd-guide-01',
storageBucket: '',
);

Method 2: Open the firebase project > settings > project settings > your app id should be at the bottom just scroll down.

Previously we could use firebase token to authorize out application to interact with firebase but that is now deprecated. Hence, we will be using serviceCredentialFileContents. To get this file you need to go to Google cloud https://console.cloud.google.com

By default, all your firebase projects should also be accessible in your cloud account.

Click on All > and select the project you’re currently integrating with.

Click on Service Account > Create Service Account > give the service account a name. and create.

grant service permission to firebase app distribution and click on DONE

A list of service should be displayed now. The one named with your project select the : by the right end. Click on Manage Keys and create a new key

Ensure the key type is JSON and create

A JSON file should automatically be downloaded. Open it up, and copy everything in it. Head back to GitHub and paste it in secret and you’re done.

You do not have to include the download file in your project structure. Just keep it somewhere safe 😉

On Firebase Console left pan. Click on Release and monitor > App Distribution and create.

App Distribution interface Firebase

You have can create Testing groups and add different testers to the group. I will let you explore that on your own. Create a group and add it to groups in the Github action file Line 34 in the code above.

You should be all set now. Push your code fixes to github and let github action build and push to firebase.

Everyone in your testing group should have mail in their inbox 😁

Hope this was helpful. Feel free to drop a comment if you’re facing any issues and let’s get it fixed.

Till we cross paths again, stay safe and happy coding. ChatGPT isn’t coming for you yet. 🤣🤣

--

--

Stephen Oyebanji

Mobile developer | UI/UX | Community lover | Tech lover | Cinematographer | Music | Gamer