In this tutorial, you will learn how to automate your Firebase Hosting deployments using Continuous Integration/Continuous Deployment (CI/CD) pipelines. The goal is to set up a pipeline that automatically builds and deploys your app to Firebase Hosting whenever you push to your repository.
By the end of this tutorial, you will be able to:
Prerequisites
- Basic understanding of Git and Github
- A Firebase project and familiarity with Firebase Hosting
- A Github account
- Basic knowledge of Node.js and npm
We'll be using Github Actions for this tutorial:
.github/workflows
directory. You can name it firebase-hosting.yml
.Here's an example of a workflow definition:
name: Deploy to Firebase Hosting
on:
push:
branches:
- master
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Install Dependencies
run: npm ci
- name: Build
run: npm run build
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
This file does the following:
npm ci
.npm run build
.The FIREBASE_TOKEN
is a secret stored in your repository settings. You can generate it by running firebase login:ci
in your terminal and copying the output token.
You've learned how to automate your Firebase Hosting deployments using CI/CD pipelines. You've set up a pipeline that automatically builds and deploys your app to Firebase Hosting whenever you push to your repository.
You can improve your workflow by adding testing and linting before the build step.
on.push.branches
value to your chosen branch name.run: npm test
to run tests.run: npm run lint
to lint your code.Try to automate other parts of your workflow, such as database migrations or cloud function deployments.