Skip to content
Shreyas Patil's Blog

๐Ÿ”ฅ Quickly distribute your app with Firebase App Distribution using GitHub Actions + Fastlane ๐Ÿš€

Cover image for ๐Ÿ”ฅ Quickly distribute your app with Firebase App Distribution using GitHub Actions + Fastlane ๐Ÿš€

Hi Firebasers, in this article, weโ€™ll explore a way to automate workflows for distributing your Android application with Firebase App Distribution using GitHub Actions CI and Fastlane.

Once youโ€™ve set this up, youโ€™ll just need to write code, push to GitHub and your app will be automatically distributed to your trusted testers or QA team.

Before starting the implementation details, letโ€™s understand a few things.


What is Firebase App Distribution? ๐Ÿคทโ€โ™‚๏ธ

Firebase App Distribution lets you distribute pre-release versions of your app to your trusted testers painless. It gives us a holistic view of your beta testing program across iOS and Android, providing us with valuable feedback before a new release is in production. You can send pre-release versions of your app using the console or your CI servers, and installing your app is easy for testers.

If you use Crashlytics in your apps, youโ€™ll automatically get stability metrics for all your builds, so you know when youโ€™re ready to ship. Itโ€™s a time saver for the whole application development lifecycle process.


What is Fastlane? ๐Ÿƒ

Fastlane is a toolkit that does a lot of things, like generating screenshots, dealing with code signing, and releasing your application and much more. Itโ€™s the easiest way to automate beta deployments and releases for your iOS and Android apps. ๐Ÿš€

It has a plugin system that makes it easy to extend its functionality. There are plugins for all sorts of workflows, such as for publishing app on to the Google Play Store โ€” and even one for Firebase App Distribution! This tool is easy to use locally as well as CI workflows ๐Ÿ˜ƒ.

With this short introduction to the tools, weโ€™re going to use under our belt. letโ€™s dive into the implementation.


Setup Fastlane in app ๐Ÿƒ

You can refer to this repository as a reference. Everything in this article is already implemented there.

Setting up Fastlane is quite easy. Ruby should be preinstalled on your system. (Alternatively, you can follow the process as described here).

source "https://rubygems.org"
gem "fastlane"

Now you can see the newly created fastlane directory in your project with the following files:


Add the Firebase plugin ๐Ÿ”ฅ

You can refer to the steps described here for adding plugin using a variety of available authentication options. Run the following command to add the Firebase App Distribution plugin using Fastlane:

fastlane add_plugin firebase_app_distribution

Your working directory will be updated with some files.


Setting up Firebase Service Credentials ๐Ÿ”’

Firebase Service Credentials is required for Fastlane for authentication purposes. Take a look at this section for more information.

Firebase App Distribution Admin Role


Getting the Firebase App ID ๐Ÿ†”

Now your Firebase projectโ€™s App ID is required.

Firebase App ID

export FIREBASE_APP_ID=YOUR_APP_ID

Okay ๐Ÿ‘. Now letโ€™s configure Firebase App Distribution for Fastlane.


Configure Firebase App Distribution ๐Ÿ› ๏ธ

Firebase App Distribution supports testers or groups for distribution as well as release notes for distribution of the app. You can see this for more available options for configuration.

In this project, we will set up groups and release notes configuration for Firebase App Distribution.

In this file, we will mention groups whom we want to distribute our application for testing. So file would look like as below:

qa-team, trusted-testers

This means your application will be distributed to the qa-team and trusted-testers groups (these groups are created or managed in the App Distribution dashboard within the Firebase console).

App Distribution Groups

In this file, we will add release notes for the current version of the application. These release notes will be visible for testers of application. This file will be a simple plain text file as below:

In this version, we improved the user experience and fixed some bugs.

Hang tight โ€” weโ€™re almost done. Letโ€™s now set up the lane for app distribution.


Letโ€™s create a lane ๐Ÿ›ฃ๏ธ

You can declare various lanes in Fastfile which can have different behaviours or simply we can call them tasks. Now just open that file and define a lane called distribute.

default_platform(:android)

platform :android do

  desc "Lane for distributing app using Firebase App Distributions"
  lane :distribute do
    gradle(task: "clean assembleRelease")
    firebase_app_distribution(
        service_credentials_file: "firebase_credentials.json",
        app: ENV['FIREBASE_APP_ID'],
        release_notes_file: "FirebaseAppDistributionConfig/release_notes.txt",
        groups_file: "FirebaseAppDistributionConfig/groups.txt"
    )
  end

end

Using firebase_app_distribution we will distribute the app which is available in Fastlane via the plugin we just added. You can configure it as per your need as discussed earlier.

As you can see, we have provided file firebase_credentials.json as service_credentials_file which was recently downloaded from GCP.

Now we are ready to test it locally ๐Ÿ˜ƒ.


Testing it locally ๐Ÿ‘จโ€๐Ÿ’ป

Run the following command: fastlane <LANE_NAME>

So if you want to distribute an app then run fastlane distribute. Make sure everything works fine ๐Ÿท.

If everything is working fine then we are ready to go for automation โšก.


Setup GitHub Actions ๐Ÿค–

This is the most interesting part ๐Ÿ˜. As you might know that we always require the Firebase Credentials file and variable and FIREBASE_APP_ID. If your repository is private then you can directly include credentials file in VCS. But what if your project is public and you want to keep it safe?

Here GitHub Actions Secret comes to rescue ๐Ÿ˜ƒ. It allows us to store the actionโ€™s secrets. But we canโ€™t directly store the exact content because it may contain whitespace. To work around this requirement, weโ€™ll encode these files using Base64:

For example, run this command ๐Ÿ‘‡:

base64 -i firebase_credentials.json > firebase_credentials.json.b64

This will encode the Firebase credentials file and see the generated .b64 file. Now copy the content of the file and add a secret in GitHub Actions ๐Ÿ‘‡.

GitHub Actions Secret

Now our action has access to this secret, allowing us to decode this string and create a file in the working directory. Weโ€™ll see this in the next section.

Go ahead and also add as the secret for FIREBASE_APP_ID. Your secrets should now look like ๐Ÿ‘‡:

GitHub Actions Secrets List

Once all required secrets are added, we are ready to create an automation workflow ๐Ÿ”ฅ.


Letโ€™s create GitHub Actionโ€™s Workflow ๐Ÿ‘จโ€๐Ÿ’ป

Create a workflow file distribute.yml in the .github/workflows directory. Add initial contents to the file as ๐Ÿ‘‡:

name: Distribute

on:
  push:
    branches: [test]

jobs:
  distribute:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-ruby@v1
        with:
          ruby-version: "2.6"

Whenever you or someone else pushes to the test branch, the distribution workflow will be triggered. Donโ€™t forget to set up Ruby for the workflow.

- name: Install bundle
  run: |
    bundle config path vendor/bundle
    bundle install --jobs 4 --retry 3

As you know, we need Firebase Service credentials for authentication and we had added Base64 content in GitHub Secrets. So just decode it and create a file ๐Ÿ‘‡:

- name: Create Firebase Service Credentials file
  run: |
    echo "$FIREBASE_CREDENTIALS" > firebase_credentials.json.b64
    base64 -d -i firebase_credentials.json.b64 > firebase_credentials.json
  env:
    FIREBASE_CREDENTIALS: ${{ secrets.FIREBASE_CREDENTIALS }}
- name: Distribute app with ๐Ÿ”ฅ App Distribution ๐Ÿš€
  run: bundle exec fastlane distribute
  env:
    FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID }}

Thatโ€™s it. You can do the same for the production deployment as per your choice.

Now just push some commits to the test branch and see the magic โœจ.

GitHub Action Success

Lovely! ๐ŸŽ‰

Your app is now successfully distributed to the trusted testers and QA team you set up for the application. Just wait for their feedback then fix issues ๐Ÿ˜.

Write some code ๐Ÿ‘จโ€๐Ÿ’ป, push ๐Ÿš€ and chill! ๐Ÿ˜Ž

Here is a look at the Firebase App Distribution dashboard for my sample app ๐Ÿ˜:

Firebase App Distribution Dashboard

I hope this article will be helpful to everyone.

Thanks for reading! ๐Ÿ˜„


๐Ÿ“š References



Previous Post
๐Ÿ‘จโ€๐Ÿณ Cooking Tasty code in Kotlin ๐Ÿด โ€” Part 1
Next Post
Automate publishing app to the Google Play Store with GitHub Actionsโšก+ Fastlane๐Ÿƒ