我一直在尝试使用 Github 操作 CI/CD 工作流自动部署 Firebase 云功能。这些函数是使用 NodeJs、Express 和 Typescript 开发的。并且所有环境变量都保存在 .env 文件中,该文件不在 github 上跟踪(原因很明显)
main.yaml 文件(在 .github/workflows/ 中)
name: CI/CD
on:
push:
branches: [ deploy ]
pull_request:
branches: [ deploy ]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: create env file
run: |
cd functions
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env
- name: Install npm packages
run: |
cd functions
npm install
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
工作流首先创建一个 .env 文件,在其中写入 env 变量(保存在 github secrets 中),然后安装依赖项,最后部署云函数
这些步骤的执行没有任何问题,直到出现此错误的部署部分
Error: Service account object must contain a string "project_id" property.
at FirebaseAppError.FirebaseError [as constructor] (/github/workspace/functions/node_modules/firebase-admin/lib/utils/error.js:44:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/github/workspace/functions/node_modules/firebase-admin/lib/utils/error.js:90:28)
at new FirebaseAppError (/github/workspace/functions/node_modules/firebase-admin/lib/utils/error.js:125:28)
at new ServiceAccount (/github/workspace/functions/node_modules/firebase-admin/lib/credential/credential-internal.js:134:19)
at new ServiceAccountCredential (/github/workspace/functions/node_modules/firebase-admin/lib/credential/credential-internal.js:68:15)
at Object.exports.cert (/github/workspace/functions/node_modules/firebase-admin/lib/credential/credential.js:34:54)
at Object.<anonymous> (/github/workspace/functions/lib/config/firebase.js:10:34)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
先感谢您