You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions部署Firebase Cloud Functions无报错但未生效求助

Firebase Cloud Functions在GitHub Actions中部署无报错但未完成部署

我配置了GitHub Actions工作流,希望在代码推送到main分支时部署/functions目录下的Firebase Cloud Functions。工作流能正常触发且无报错输出,但函数并未完成部署。

工作流配置文件(deploy-cloud-functions-merge.yml)

name: Deploy Cloud Functions
on:
 workflow_dispatch:
 push:
   branches:
     - main
   paths:
     - 'functions/**'
jobs:
 build_and_deploy:
   runs-on: ubuntu-latest
   steps:
     - uses: actions/checkout@v3
     - uses: actions/setup-node@v3
       with:
         node-version: 16.x
     - name: Build Cloud Functions
       run: cd functions && npm ci
     - name: Create SA key
       run: echo '${{ secrets.CLOUD_FUNCTIONS_SERVICE_ACCOUNT }}' > $HOME/gcloud.json
     - name: Deploy Cloud Functions
       run: export GOOGLE_APPLICATION_CREDENTIALS=$HOME/gcloud.json && cd functions && npx firebase-tools deploy --only functions --project default --json && npx firebase-tools --version

GitHub Actions部署步骤输出

Run export GOOGLE_APPLICATION_CREDENTIALS=$HOME/gcloud.json && cd functions && npx firebase-tools deploy --only functions --project default --json && npx firebase-tools --version
npm WARN exec The following package was not found and will be installed: firebase-tools@11.23.0
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.3: this library is no longer supported
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)

> lint
> eslint

11.23.0

可以看到,执行完predeploy脚本(lint+eslint)后就没有后续输出,也无错误提示。但本地执行部署命令能正常完成。

本地正常部署输出

=== Deploying to '[projectname]'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> lint
> eslint

✔  functions: Finished running predeploy script.
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...
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing codebase default for deployment
⚠  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: preparing functions directory for uploading...
i  functions: packaged /home/stanley/[projectname]/functions (82.34 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 16 function getFileParts(europe-west1)...
i  functions: updating Node.js 16 function getCustomMeta(europe-west1)...
i  functions: updating Node.js 16 function getCSVParts(europe-west1)...
i  functions: updating Node.js 16 function getTemplates(europe-west1)...
i  functions: updating Node.js 16 function getCSVLink(europe-west1)...
✔  functions[getCustomMeta(europe-west1)] Successful update operation.
✔  functions[getTemplates(europe-west1)] Successful update operation.
✔  functions[getCSVParts(europe-west1)] Successful update operation.
✔  functions[getCSVLink(europe-west1)] Successful update operation.
✔  functions[getFileParts(europe-west1)] Successful update operation.
Function URL [functionurl]
Function URL [functionurl]
Function URL [functionurl]
Function URL [functionurl]
Function URL [functionurl]
i  functions: cleaning up build files...

✔  Deploy complete!

Project Console: [console-link]

相关背景与配置

我使用--project default参数是为了解决之前的错误:

{
  "status": "error",
  "error": "No project active, but project aliases are available.\n\nRun \u001b[1mfirebase use <alias>\u001b[22m with one of these options:\n\n  default ([projectname])\n  staging ([projectname])"
}

我的.firebaserc配置如下:

{
  "projects": {
    "default": "[projectname]",
    "staging": "[projectname]"
  },
  "targets": {
    "[projectname]": {
      "hosting": {
        "[projectname]": [
          "[otherprojectname]"
        ]
      }
    }
  },
  "etags": {}
}

排查与解决建议

  • 移除--json参数:当前部署命令启用了JSON输出模式,可能导致日志截断或工具行为异常,改为非JSON模式可以查看完整部署日志,排查是否有隐藏错误。
  • 固定firebase-tools版本:当前npx动态安装的是11.23.0版本,建议指定稳定版本(如npx firebase-tools@12.x deploy...),或在functions目录的package.json中添加firebase-tools作为开发依赖,工作流中直接调用本地版本避免版本兼容问题。
  • 验证服务账号权限:确认CLOUD_FUNCTIONS_SERVICE_ACCOUNT对应的服务账号拥有Cloud Functions Developer、Cloud Build Editor、Artifact Registry Administrator等必要权限,避免因权限不足导致静默部署失败。
  • 直接使用项目ID:替换--project default为实际项目ID,避免CI环境中.firebaserc别名识别异常。
  • 添加调试步骤:在部署命令前后增加调试操作,比如检查GOOGLE_APPLICATION_CREDENTIALS文件是否生成正常,执行firebase projects:list确认项目可访问,或提前运行firebase use default切换项目。
  • 排查predeploy脚本:临时注释掉package.json中的predeploy脚本,验证部署流程是否能继续执行,排除eslint在CI环境中卡住的可能。

内容的提问来源于stack exchange,提问作者S. Kosorin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 19:35:45