Automate Firebase cloud functions deployment with Github actions.
calebdeji
Posted on July 4, 2021
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.
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
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.
If you have custom environment variables used in your project, you need to store the environment data. You can use the below workflow code
Thanks for reading! Feel free to drop suggestions and questions in the comment box 😊.
Posted on July 4, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.