DEV Community

Cover image for Steps to auto Firebase deployment using GITHUB Actions (CI/CD)
Muthu
Muthu

Posted on

14 4

Steps to auto Firebase deployment using GITHUB Actions (CI/CD)

Step #1

Create a GITHUB repository

Step #2

Create a Firebase Project on the Firebase console

Step #3

$ firebase init
Enter fullscreen mode Exit fullscreen mode

And choose your project and select Hosting from the CLI tool

Step #4

Create package.json using

$ npm init
Enter fullscreen mode Exit fullscreen mode

Once the package.json created add the following component on the JSON under scripts

"build:production": "node --version",
"build:prod": "node --version",
Enter fullscreen mode Exit fullscreen mode

The final package.json will look like this

package.json

{
  "name": "cicd",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build:production": "node --version",
    "build:prod": "node --version",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/muthugit/cicd.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/muthugit/cicd/issues"
  },
  "homepage": "https://github.com/muthugit/cicd#readme"
}
Enter fullscreen mode Exit fullscreen mode

Step #5

Create the workflow file (main.yml) on the following directory

$ <root directory>/.github/workflows
Enter fullscreen mode Exit fullscreen mode

main.yml

name: FIREBASE-DEPLOY

on:
  push:
    branches:
    - master
    - release/*


jobs:
  firebase-deploy:


    runs-on: ubuntu-latest


    steps:
    - uses: actions/checkout@master
    - uses: actions/setup-node@master
      with:
        node-version: '10.x'
    - run: npm install
    - run: npm run build:prod
    - uses: w9jds/firebase-action@master
      with:
        args: deploy --only hosting
      env:

        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Enter fullscreen mode Exit fullscreen mode

Step #6

Get the Firebase token by running this

$ firebase login:ci
Enter fullscreen mode Exit fullscreen mode

Step #7

  1. Goto GITHUB.com and navigate to your repository
  2. Goto Settings -> Secrets
  3. Create new secret
  4. Copy the secret generated on the previous step and name the secret as FIREBASE_TOKEN

Step #8

Thats it! Just push your code. This will deploy the PUBLIC folder to firebase hosting

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay