Deploy Apps And Functions To Firebase From A Mono Repo With GitHub Actions

How to deploy applications and functions from a mono repo with GitHub Actions to Firebase Hosting and Functions

Image for post
Image for post
Photo by 张 嘴 on Unsplash

Mono Repo

Our open source project DeckDeckGo contains many Progressive Web Apps and Cloud Functions, for which, obviously, I did set up GitHub actions as Julien displayed.

To Firebase Hosting

Let’s say that one of your application is available in a sub-folder of our repo called docs . Basically, everything you have to do in addition to the original post is to prefix all steps of the Action with your sub-directory, respectively with docs .

on:
push:
branches:
- master
on:
push:
branches:
- master
paths:
- 'docs/**'
- name: Install Dependencies
run: npm ci
- name: Install Dependencies
run: npm ci
working-directory: ./docs
- name: Archive Artifact
uses: actions/upload-artifact@master
with:
name: www
path: www
- name: Archive Artifact
uses: actions/upload-artifact@master
with:
name: docs
path: docs/www
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: "default"
PROJECT_PATH: "./docs"
name: CI - Docs

on:
push:
branches:
- master
paths:
- 'docs/**'

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci
working-directory: ./docs
- name: Build
run: npm run build
working-directory: ./docs
- name: Archive Artifact
uses: actions/upload-artifact@master
with:
name: docs
path: docs/www
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Download Artifact
uses: actions/download-artifact@master
with:
name: docs
path: docs/www
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: "default"
PROJECT_PATH: "./docs"

To Firebase Cloud

In DeckDeckGo we are also taking advantages of the amazing Cloud Functions features of Firebase.

name: CI - Cloud

on:
push:
branches:
- master
paths:
- 'cloud/**'

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci
working-directory: ./cloud/functions
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only functions
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: "default"
PROJECT_PATH: "./cloud"

Summary

GitHub actions are awesome! Seriously, few lines, few configuration, supports mono repo, really a perfect solution for a project like ours.

Freelancer by day | Creator of DeckDeckGo by night | Organizer of the Ionic and IndieHackers Zürich Meetup

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store