w9jds / firebase-action

GitHub Action for interacting with Firebase
MIT License
926 stars 199 forks source link

Build fails with unspecified error when using GCP_SA_KEY for authentication #220

Closed maylorsan closed 8 months ago

maylorsan commented 8 months ago

Environment

Issue Description

I am encountering a build failure with an unspecified error when I try to use GCP_SA_KEY for authentication in my GitHub Actions workflow, specifically when deploying to Firebase Functions and Firestore indexes. The workflow succeeds without any issues when I use FIREBASE_TOKEN for authentication, indicating the problem is specifically related to using a service account key (GCP_SA_KEY).

Workflow Snippet

- name: Deploy Functions to Firebase
  uses: w9jds/firebase-action@master
  with:
    args: deploy --only firestore:indexes,functions
  env:
    PROJECT_ID: PROJECT_NAME
    GCP_SA_KEY: ${{ secrets.GCP_SA_KEY_ENV_NAME }}

Expected Behavior

The deployment should proceed without errors, similar to when using FIREBASE_TOKEN for authentication.

Actual Behavior

The build process fails during the functions deployment phase with the following output:

✔  functions: Finished running predeploy script.
i  firestore: reading indexes from firestore.indexes.json...
i  cloud.firestore: checking firestore.rules for compilation errors...
✔  cloud.firestore: rules file firestore.rules compiled successfully
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
⚠  functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8855
shutdown requested via /__/quitquitquit
**Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error**

Troubleshooting Attempts

maylorsan commented 8 months ago

I managed to resolve the build failure issue by assigning the Firebase Admin role to the service account associated with the GCP_SA_KEY. This change ensured that the service account had the necessary permissions for deploying functions and Firestore indexes through the GitHub Actions workflow.

@w9jds maybe need to add into README, something like this:

"When using .runtimeconfig.json for environment variables, ensure the service account has the Firebase Admin role assigned for proper access."