Site logo

Not Playing – Spotify

Building a Portfolio/Resume Site with Gatsby, Part 4 - Automating deploys to Firebase with GitHub Actions

Published on
5 mins read
Written by

This post is the fourth in a series and was originally published on

Quick recap. My personal website sucks. I'm updating it using Gatsby and the Novela theme by narative, because it's popular, and I'm basic.

FYI, I'm using a Mac, so there may be some Mac-specific commands.

Alright, part 4, automating deploys with GitHub Actions. GitHub Actions seems to be all the rage right now. I've used a couple of different enterprise-grade CI/CD tools, primarily Jenkins. So I'm familiar with the benefits and may have implemented it once or twice years ago. I haven't used GitHub Actions though. So this was a learning process. There was a lot of experimentation and testing (and failing) while doing this. At the end though, this is really good, easy to implement, CI that is free for most GitHub non-enterprise users. GitHub Actions are awesome.

Post-Publish Update: I ended up commenting out the Gatsby ‘clean’ and ‘build’ steps of my action. The Gatsby CLI action that I used worked fine, but it looks like Ubuntu is the only free choice for the containers the actions run in. While Ubuntu is great, some of the components of my Gatsby site look to be incompatible on Ubuntu and the site builds incorrectly vs. Mac. So I am building on my Mac, PR-ing my repo, and automating the deploy only with GitHub Actions.

Automate deployments with GitHub Actions

Add your Firebase token to your GitHub repo

  • In Terminal, firebase login:ci
  • Alt Text
  • Select your Google account that you use for Firebase
  • Alt Text
  • Alt Text
  • In Terminal, the output should be something like...
✔  Success! Use this token to login on a CI server:


Example: firebase deploy --token "$FIREBASE_TOKEN"
  • Copy your token and/or don't close your terminal so you can copy it later
  • Alt Text
  • Alt Text
  • Alt Text
  • For Name, enter 'FIREBASE_TOKEN'
  • For Value, enter the Firebase token you copied earlier from Terminal
  • Alt Text
Alt Text

Add GitHub Actions to automate deployment

  • Alt Text
  • Alt Text
  • Alt Text
  • Add a commit subject and message and click the Commit New File button
  • In Terminal, cd to site's root directory
  • git checkout main
  • git pull (your build-deploy.yml file should pull down to your local machine)
  • Open './.github/workflows/build-deploy.yml'
  • Alt Text
  • Alt Text
  • Alt Text
  • Alt Text
  • In your build-deploy.yml file, add your build and deploy and save. Here's mine.
# This is a basic workflow to help you get started with Actions

name: Build and Deploy
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
  # Gavin, 20200802: Removing on-push, because I only want PRs to trigger this job
    branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
  # This workflow contains a two jobs, "build" and "deploy"
    name: Build and Deploy
    runs-on: ubuntu-latest
    - name: Checkout Repo
      uses: actions/checkout@master
    - name: Clean Gatsby Site
      uses: jzweifel/gatsby-cli-github-action@master
        gatsby-arg: clean
    - name: Build Gatsby Site
      uses: jzweifel/gatsby-cli-github-action@master
        gatsby-arg: build
    # Gavin, 202008014: Moved this up from its own Deploy job into this job ()
    - name: Deploy to Firebase
      uses: w9jds/firebase-action@master
        args: deploy --only hosting
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Loosen your .gitignore restrictions and push your changes

  • Open './.gitignore'
  • In your .gitignore file, unignore node_modules and public (for building and deploying) and save. Here's mine.
# Logs

# Runtime data

# Directory for instrumented libs generated by jscoverage/JSCover

# Coverage directory used by tools like istanbul

# nyc test coverage

# Grunt intermediate storage (

# Bower dependency directory (

# node-waf configuration

# Compiled binary addons (

# Dependency directories
# Gavin, 20200719: Including the Novela theme directory under node_modules
# Gavin, 20200802: Including all under directory under node_modules

# Typescript v1 declaration files

# Optional npm cache directory

# Optional eslint cache

# Optional REPL history

# Output of 'npm pack'

# dotenv environment variables file

# gatsby files

# Gavin, 20200802: Including public

# Mac files

# Yarn
# Yarn Integrity file

  • In Terminal, gatsby clean
  • git add --all
  • git commit -a -m "Added GitHub actions to automate build and deploy. Also added the 'node_modules' folder and the 'public' folder"
  • git push -u origin main

So... Great. How can you tell if this works? When you pushed you your main repo to origin (GitHub), the action should have automatically run. Your Action will run when you push to your main branch, merge a PR into your main branch, or manually re-run your Action. I'll describe how to re-run an Action manually because everything for it will apply to the other automated runs.

  • Alt Text
  • Alt Text
  • Alt Text
  • Alt Text
  • Alt Text
  • Alt Text

Boom! Now your Gatsby site is automatically building and deploying when you merge a pull request to your main branch. Professional level CI on a personal site, easy, and free. Is it overkill? Maybe. Am I going to continue overkilling my personal site and doing write-ups like this? Probably.