Deploying to Firebase with GitHub Actions
Tags: githubactions, github, firebase
Published: 2020-10-29 19:43:38

---
title: Deploying to Firebase with GitHub Actions
published: true
date: 2020-10-29 19:42:35 UTC
tags: githubactions,github,firebase
canonical_url: 
---

This is a quick guide on how to get an un-hosted project, onto [Firebase](https://console.firebase.google.com/) hosting using [GitHub Actions](https://docs.github.com/en/free-pro-team@latest/actions) which is updated on every merge. We’ll just be using the Firebase CLI, no fancy coding required!

![](https://cdn-images-1.medium.com/max/1024/0*9ixlX2uq9cVQif4Y.jpeg)

A few assumptions before we begin:

- A repository on GitHub with a website ready to host (In my case, a fresh Angular App “ng new”)
- A Firebase account
- The latest [Firebase cli](https://www.npmjs.com/package/firebase-tools) installed and ready to go

### So let’s get started

First up, head over to [Firebase](https://console.firebase.google.com/) and create your new Project. Just follow the basic steps, add your project name, enable analytics if you want to.

![](https://cdn-images-1.medium.com/max/1024/1*gnXqWAkLMXMYULQl0I0M6Q.png)

Now let’s hop into our command window and setup the Firebase and GitHub stuff.

1. Get a command window open in your project directory.
2. Type the following command.

```
firebase init hosting:github
```

This will walk you through the process from start to finish

3. Follow the steps in the console, use the existing Firebase project you made earlier.

4. When prompted for the GitHub repository, type in the following “Username/Repository”, or in my case

```
OliBlade/MyFirebaseApp
```

5. You’ll also be asked to input the build directory of your site, and your build command, in my case “npm run build”

### Once that’s all done

You’ll have seen in the output that this has created a service account in your Firebase project with permission to deploy Firebase Hosting. Also that service account’s JSON key has been uploaded to the GitHub repository as a [GitHub Secret](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets).

In your files you’ll notice a folder called “.github” with a couple of YAML files in the workflows folder. If you take a look at these you will see how they reference the newly created secret and configure the [GitHub Action](https://github.com/marketplace/actions/deploy-to-firebase-hosting) to deploy Firebase Hosting.

![](https://cdn-images-1.medium.com/max/687/1*688WrTCulz4CvkCTvV5kcg.png)

### Commit and Push

It doesn’t really matter if you do this on a new branch or not, but you probably should. Navigate to your repository and click the Actions tab. You will see your action executing and building the project.

![](https://cdn-images-1.medium.com/max/740/1*-arD2VC9Q5xc9zxkPDB7Og.png)

Notice step 4 deploys to FireBase, if you check out your new project in [Firebase Console](https://console.firebase.google.com/) you will see a freshly deployed and hosted app.

This now updates your live FireBase hosted website with every merge into your main branch, and every PR in this GitHub repo will get its own preview URL!

### Some extra reading

- This post was heavily based on [this Firebase documentation](https://firebase.google.com/docs/hosting/github-integration), but I thought I’d do a little walkthrough
- [GitHub Secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets)
- [GitHub Action](https://docs.github.com/en/free-pro-team@latest/actions)
- [GitHub Action to deploy to Firebase hosting](https://github.com/marketplace/actions/deploy-to-firebase-hosting)