Automate Firebase cloud functions deployment with Github actions.
Tags: automation, deployment, firebase, firebasecloudfunctions
Published: 2021-07-04 08:31:38

---
title: Automate Firebase cloud functions deployment with Github actions.
published: true
description: Github actions provide a workflow that can help carry out various actions such as build the code in your repository, deploy to your production or staging environment, run tests on your code before carrying out some crucial operations, and so on.
tags: Automation, Deployment, Firebase, FirebaseCloudFunctions
cover_image: https://pixabay.com/get/g53f4c1d080daf388f5f3dd69f8aa22c2291fc8d455ab21466dc39fec20620fc8966863a7cecff30c8e1f679a4dfd610b_1920.jpg---

Deployment automation refers to the process that enables you to deploy your code to various environments at the occurrence of an event without human intervention. Deployment automation enables you to give little to no focus on the deployment process, hence saving you time that could be spent on other activities. 

Firebase cloud functions is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. You can read more about that [here](https://firebase.google.com/docs/functions). 

Github actions provide a workflow that can help carry out various actions such as build the code in your repository, deploy to your production or staging environment, run tests on your code before carrying out some crucial operations, and so on. You can read more about Github actions [here](https://docs.github.com/en/actions/guides/about-continuous-integration)

>This article assumes that you as a reader have some experience with firebase cloud functions, npm installed on your terminal, a firebase project created, and your cloud functions defined in your firebase project. 

To deploy any firebase cloud functions project, you need to be authenticated via Firebase CLI but since GitHub actions will solely be responsible for the deployment process, you need to generate an authentication token from Firebase CLI and save it as a secret in your repository settings. 

To install Firebase CLI, open your terminal and run 
  
  > npm install -g firebase-tools

To generate the authentication token, run 

  > firebase ci:login

The  command above opens your browser and asks you to log in to the Google account connected to your firebase project. Upon login, a new token will be generated on your terminal. Open your Github repository and go to the Settings tab, click on the Secrets pane, copy and save the token generated on your terminal as a new secret. Once that's done, click on the Action tab, and click on **_setup a workflow yourself_**.
Read and copy the following gist content to the new workflow file created.

{%gist https://gist.github.com/calebdeji/b40763b136def956eaa16f76241525cb.js %}

If you have custom environment variables used in your project, you need to store the environment data. You can use the below workflow code 

{%gist https://gist.github.com/calebdeji/d3558267f5df7e90f05a3decdffcc6db %}

Thanks for reading! Feel free to drop suggestions and questions in the comment box 😊.