Search code examples
firebasegithub-actionsfirebase-cli

Firebase deploy in Github Actions gives Authorization failed error


I'm trying to automate the deployment of a react app to firebase with github actions but i'm getting the following error:

Error: Autorization failed. This account is missing the following required permissions on project ***
 firebase.projects.get
 firebasehosting.sites.update

I have multiple sites and when I try to deploy manually using firebase deploy --only hosting:MY_SITE_NAME it's working correctly. I have two jobs in my workflow. The build job passes but the deploy one fails. Here's my workflow file:

name: Build and Deploy to Firebase
on:
  push:
    branches:
      - master

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Install Dependencies
        run: yarn install
      - name: Build
        run: yarn build
      - name: Archive Production Artifact
        uses: actions/upload-artifact@master
        with:
          name: build
          path: build
  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: build
      - name: Deploy to Firebase
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only hosting:MY_SITE_NAME
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Does anyone have an idea of what is wrong?


Solution

  • If you want to use the Firebase CLI in a CI/CD environment such as GitHub Action, you'll have to provide a way for the CLI to know the account credentials it should use. When you run locally, it can get the credentials from your interaction with firebase login. But when you run elsewhere, there is no UI to prompt you.

    You will have to follow the instructions in the documentation on integrating with CI/CD system, and provide a token for the account that should be used to authorize the deployment.