Sitemap

Using Firebase with Github Actions!

3 min readDec 11, 2018

--

You have probably heard that Github is releasing a workflow system of their own that is obscenely powerful. They even include a huge amount of out of the box actions that will get a lot of things done for you like deploying to NPM, Azure, and Google Cloud Platform. However, they don’t offer anything for Firebase which has a whole sweet of offerings like hosting, functions, real-time database, and Firestore.

Since actions can basically be anything with a Dockerfile, I have created a repo that sets up the environment so you can use any firebase-tools commands you need in your workflow. I have been using it on my private repositories to deploy to dev and prod hosting sites as I push them to specific branches. The firebase action can be found here and it’s extremely simple to implement.

On your development machine, you need to get a CI token from Firebase, so in your terminal just enter:

firebase login:ci

This will NOT mess up your current login on your machine and generates a completely new token to use.

Go through the login process and copy the token that is spit out into your console, and navigate to the project you want to include a Firebase action in. Inside of your workflow create a new action and for uses you want to set it to w9jds/firebase-action@master (It is recommended to use a specific commit has over master as it won’t break as actions are updated!).

Secrets section in the Github workflow

In this action there is a secrets section. Click create new secret and create a token named FIREBASE_TOKEN using the token you just recieved. Once you finish, make sure that the secret is checked for this action.

Get Jeremy’s stories in your inbox

Join Medium for free to get updates from this writer.

Depending on what you want to do in this action, update the args for the action to what you want. Actions are recommended to default to any help commands, so you want to override it. Once set up, it should look something like this:

action "Pushed to develop" {
uses = "actions/bin/filter@95c1a3b"
args = "branch develop"
}
action "Install Dependencies" {
uses = "actions/npm@6309cd9"
needs = ["Pushed to develop"]
args = "install"
}
action "Build Development" {
uses = "actions/npm@6309cd9"
needs = ["Install Dependencies"]
secrets = ["FIREBASE_API_KEY"]
args = "run build"
}
action "Deploy to Development" {
uses = "w9jds/firebase-action@master"
needs = ["Build Development"]
args = "deploy --only hosting:dev"
env = {
PROJECT_ID = "new-eden-storage-a5c23"
}
secrets = ["FIREBASE_TOKEN"]
}

Notice that I have a workflow that first installs all of the dependencies needed for my project. It then moves on to run a build for the project, and finally deploys the project to the dev hosting target on my firebase project.

As this action isn’t designed to only work for deployment, if the command is supported by firebase-tools then you can use it as an argument.

Enjoy!

--

--