Getting started with GitHub Actions - CI/CD Firebase deploy

Published: December 8, 2019

GitHub Actions are used to automatically run a pipeline on a repository. Uses cases can be to run tests on your code, build your application, and/or deploy your application.

Set Up a Workflow ​

In your repository, click the Actions tab in the middle.

GitHub Actions tab

Then click Set up a workflow yourself in the top right corner.

Yaml ​

This has created a .yml file for you that will contain all your triggers and steps.

First let's change it to trigger on a push, but only on the master branch.

yaml
on:
  push:
    branches:
      - master

Now let's create a step to build our code.

yaml
- name: Build
      run: |
        npm install
        npm run build

Firebase deploy ​

Now we will set up continuous deployment to Firebase. To deploy to Firebase on our behalf, we need to get our Firebase token through the CLI in your terminal. Run firebase login:ci. Now copy your token. Open a new tab for your GitHub repository and go to Settings, then Secrets. Add your secret and name it FIREBASE_TOKEN.

Now back to your .yml file, and add a deploy step. First install the firebase-tools (if your job run's on linux, remember to add sudo). Then deploy with the token.

yaml
- name: Firebase Deploy
      run: |
        sudo npm install -g firebase-tools
        firebase deploy --token ${{ secrets.FIREBASE_TOKEN }}

Finishing up ​

Click Start commit in the top right corner and commit your .yml file. Go to the Actions tab and see your pipeline running.

The complete .yml file:

yaml
name: CI/CD

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Build
        run: |
          npm install
          npm run build
      - name: Firebase Deploy
        run: |
          sudo npm install -g firebase-tools
          firebase deploy --token ${{ secrets.FIREBASE_TOKEN }}