仅用Firebase Hosting却被要求启用Cloud Functions API的问题
问题
通过Firebase CLI初始化了仅用于Hosting的项目,并让其自动生成GitHub CI脚本,相关配置如下:
.firebaserc 配置:
{ "projects": { "default": "project-name" } }
firebase.json 配置:
{ "hosting": { "public": "dist", "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], "rewrites": [ { "source": "**", "destination": "/index.html" } ] } }
GitHub CI 脚本:
name: deploy on push "on": push: branches: - main jobs: build_and_deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: yarn && yarn build - uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: "${{ secrets.GITHUB_TOKEN }}" firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROJECT_NAME }}" channelId: live projectId: project-name
但CI脚本运行时出现如下错误:
[2022-10-06T15:45:17.926Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v1/projects/project-name/locations/-/functions ***"error":***"code":403,"message":"Cloud Functions API has not been used in project 123123123 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","status":"PERMISSION_DENIED","details":[***"@type":"type.googleapis.com/google.rpc.Help","links":[***"description":"Google developers console API activation","url":"https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123"***]***,***"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"SERVICE_DISABLED","domain":"googleapis.com","metadata":***"service":"cloudfunctions.googleapis.com","consumer":"projects/123123123"***]*** [2022-10-06T15:45:17.930Z] [functions] failed to list functions for project-name [2022-10-06T15:45:17.930Z] [functions] HTTP Error: 403, Cloud Functions API has not been used in project 123123123 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. [2022-10-06T15:45:17.931Z] FirebaseError: HTTP Error: 403, Cloud Functions API has not been used in project 123123123 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. at responseToError (/home/runner/.npm/_npx/7750544ccf494d8b/node_modules/firebase-tools/lib/responseToError.js:49:12) at RetryOperation._fn (/home/runner/.npm/_npx/7750544ccf494d8b/node_modules/firebase-tools/lib/apiv2.js:288:77) at processTicksAndRejections (node:internal/process/task_queues:96:5) Error: Failed to list functions for project-name The process '/usr/local/bin/npx' failed with exit code 1 Error: The process '/usr/local/bin/npx' failed with exit code 1
仅需使用Firebase的Hosting功能,并无启用Cloud Functions的计划,为何CI脚本会要求启用该API?过往同类项目无此要求。
解决方案
原因
你使用的 FirebaseExtended/action-hosting-deploy@v0 版本较旧,该版本的Action默认会尝试检查项目中的Cloud Functions资源,即便你只用到Hosting服务。后续版本的Action修复了这个问题,或者提供了参数可以限定仅操作Hosting。
修复方法
有两种可行的解决方式:
升级Action版本
将CI脚本中的FirebaseExtended/action-hosting-deploy@v0替换为最新稳定版(比如v1或更高版本),新版本默认不会检查无关的服务资源:- uses: FirebaseExtended/action-hosting-deploy@v1 with: repoToken: "${{ secrets.GITHUB_TOKEN }}" firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROJECT_NAME }}" channelId: live projectId: project-name添加
only参数限定服务
如果你不想升级版本,可以在Action的with参数中添加only: hosting,明确告知Action仅操作Hosting资源,避免触发Cloud Functions的检查:- uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: "${{ secrets.GITHUB_TOKEN }}" firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROJECT_NAME }}" channelId: live projectId: project-name only: hosting
内容的提问来源于stack exchange,提问作者MauriceNino
相关产品推荐
相关产品推荐

