GitHub Actions makes it easy to automate all your software workflows with GitHub’s own CI/CD.
Now you can build, test, and deploy your code right from GitHub.
GitHub Actions offer free minutes of usage and storage per month so if you want to use GitHub Actions beyond the minutes or storage included in your account, you will be billed for additional usage.
In this article, we are going to Github Actions Firebase deployment example and how to build and deploy to firebase using Github Actions.
Creating the .yml file
Under the .github/workflows folder in your project, create a file named build.yml
Choose the branch to run the workflow
name: react native app deployment
on:
push:
branches:
- main
Here, I have chosen the main branch to run the workflow. You can change it to whichever branch or branches you want the workflow to run.
Installing dependencies and specifying the jobs
Now we install the dependencies and specify the VM to run our jobs.
jobs:
install-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install npm dependencies
run: |
npm install
Setting up Gradle cache
Gradle cache helps to keep the builds faster by caching the Gradle dependencies and Gradle wrapper.
- name: Cache Gradle Wrapper
uses: actions/cache@v2
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Cache Gradle Dependencies
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-caches-
Generate the Android release build
build-android:
needs: install-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install npm dependencies
run: |
npm install
- name: Build Android Release
run: |
cd android && ./gradlew assembleRelease
⚠️ The build will be different if you want to publish to Google Playstore.
Upload the artifact
GitHub Actions allow us to save the output of its jobs. This file can be downloaded and saved as a backup file or can be used for testing.
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: artifact
path: android/app/build/outputs/apk/release/app-release.apk
Deploying the app to Firebase App Distribution
Before you push the changes after configuring the upload-android job, there are a few things you have to do.
To deploy to Firebase App Distribution, you need two tokens. These tokens will be saved under GitHub Secrets and will help you connect the workflow to Firebase.
${{secrets.FIREBASE_APP_ID_ANDROID}}
This is the app ID which you can find from the firebase console under project settings. Go to the Firebase console>
Click on the project settings from the top left navigation bar>
Scroll to the bottom to find the app ID.
${{secrets.FIREBASE_TOKEN}}
This is a token which you can get after configuring firebase on your local machine and then running firebase login:ci to generate the token.
Once you get these two tokens, save them under Secrets in GitHub Secrets.
Click on New repository secret and enter the secret name and its respective value which you just found.
As a final step before adding the code, make a group in App Distribution under Testers & Groups so that you can release the app to your testers.
Finally, you can finish the workflow by adding the following code:
upload-android:
needs: build-android
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: artifact
- name: upload artifact to Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{secrets.FIREBASE_APP_ID_ANDROID}}
token: ${{secrets.FIREBASE_TOKEN}}
groups: android_testers
file: app-release.apk
Voila !. The workflow will now run and deploy the app via Firebase App distribution whenever a change is made to your repository.
Find the entire code on my GitHub here
If you have any product and Cloud / DevOps requirements, Please do contact us for free consulting [email protected]
Cheers
Vishnu
Follow me on Linkedin My Profile Follow DevopsJunction onFacebook orTwitter For more practical videos and tutorials. Subscribe to our channel
Signup for Exclusive "Subscriber-only" Content