4

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?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Merha
  • 81
  • 1
  • 10
  • How exactly did you configure the account that you want to use for deployment with the Firebase CLI? – Doug Stevenson Feb 24 '20 at 16:43
  • You mean locally? I ran the commands from firebase-tools. firebase login, then firebase init. Then I selected the project. – Merha Feb 24 '20 at 16:49

1 Answers1

3

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.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Yes, I did that too. Sorry I forgot to mention it. I added the token in Github as a secret. i'm using it here `FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}` – Merha Feb 24 '20 at 17:01
  • The error message is telling you that the account represented by that token simply doesn't have the required permissions. What have you done to ensure that it has permission? – Doug Stevenson Feb 24 '20 at 17:33
  • 1
    You were right. I'm so silly. When I ran the `firebase login:ci` command, firebase was opening a chrome tab from the wrong account Chrome window (I had two different sessions opened) and I didn't even see it when I clicking to log in... Anyway thanks a lot for your help mate! – Merha Feb 24 '20 at 17:44
  • `firebase login:ci` is going to be deprecated soon. How to authenticate using other methods? – Aseem Jun 18 '23 at 21:26