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

通过GitHub Actions使用workload identity federation部署Flutter到Firebase遇认证错误

解决GitHub Actions部署Flutter到Firebase的认证错误

问题原因

  1. firebase init是交互式命令,在GitHub Actions这类无头CI环境中无法正常执行,会导致流程中断。
  2. 虽然完成了Google Cloud身份认证,但firebase-tools未自动复用该认证上下文,且缺少明确的项目指定逻辑。

修复步骤

1. 本地准备Firebase配置文件

在本地开发环境执行一次firebase init hosting,完成项目托管配置后,将生成的firebase.json和.firebaserc文件提交到GitHub仓库。这两个文件包含部署所需的项目信息和托管规则,CI环境无需重复初始化。

2. 调整GitHub Actions的部署步骤

修改yaml中的部署步骤(注意原步骤注释写错了,是部署到Firebase Hosting而非Firestore),移除firebase init,并让firebase-tools复用已有的Google Cloud认证:

- name: Deploy Flutter to Firebase Hosting
  run: |
    npm install -g firebase-tools
    # 用gcloud生成的访问令牌完成firebase认证,替代手动login
    firebase deploy --only hosting --token "$(gcloud auth print-access-token)"

如果你的.firebaserc未指定默认项目,可添加一行指定项目ID:

- name: Deploy Flutter to Firebase Hosting
  run: |
    npm install -g firebase-tools
    firebase use <你的Firebase项目ID> --token "$(gcloud auth print-access-token)"
    firebase deploy --only hosting --token "$(gcloud auth print-access-token)"

3. 确认服务账号权限

给服务账号firebase-deploy-flutter@project123.iam.gserviceaccount.com添加Firebase Hosting Admin角色(roles/firebasehosting.admin),或至少赋予以下权限:

  • firebasehosting.sites.update
  • firebasehosting.releases.create

内容的提问来源于stack exchange,提问作者Aseem

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 01:17:47