如何通过 github actions 部署 firebase 函数?

Har*_*tte 5 npm firebase google-cloud-functions firebase-cli github-actions

在我的项目中,其文件夹结构如下所示:

dev-internal-web
-.firebase
-.github
-e2e
-functions
-node_modules
-src
(misc files)
Run Code Online (Sandbox Code Playgroud)

我有一个函数文件夹,其中包含 firebase 函数。我希望通过我的操作脚本自动部署它,如下所示:

name: CI

on:
  push:
    branches:
    - master

jobs:
  hosting-deploy:
    name: Deploy Hosting
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master
    - uses: actions/setup-node@master
      with:
        node-version: '10.x'
    - run: npm install
    - run: npm run build
    - uses: w9jds/firebase-action@master
      with:
        args: deploy --only hosting --project=tombstone-roleplay
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

  functions-deploy:
      name: Deploy Functions
      runs-on: ubuntu-latest

      steps:
      - uses: actions/checkout@master
      - uses: chrissank/deploy-firebase-functions@1.0.0
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
          TARGET: default
Run Code Online (Sandbox Code Playgroud)

文件夹内 Angular 项目上托管的 firebase 操作工作正常,但第二个脚本失败并出现以下错误:

=== Deploying to 'tombstone-roleplay'...

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

> functions@ lint /github/workspace/functions
> tslint --project tsconfig.json

sh: 1: tslint: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! functions@ lint: `tslint --project tsconfig.json`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2020-10-04T14_06_06_215Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code1
Run Code Online (Sandbox Code Playgroud)

按照评论中的说明删除 tslint 并将我的脚本更新为本文中可以找到的内容后:https://medium.com/mainlycoding-com/automate-firebase-functions-deployment-with-github-actions-ci -a0eb10fa308d,我收到以下错误:

=== Deploying to 'project-name'...

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

> functions@ lint /github/workspace/functions
> tslint --project tsconfig.json

sh: 1: tslint: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! functions@ lint: `tslint --project tsconfig.json`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2020-10-04T14_06_06_215Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code1
Run Code Online (Sandbox Code Playgroud)

我在“功能部署”部分做错了什么?

Nig*_*ith 0

deploy步骤与步骤不同build(不同的文件夹),因此您需要再次运行或使用构建工件npm install引入部署依赖项。node_module

这是我的firebase.json

{
  "functions": {
    "predeploy": [
      "npm --prefix ./functions/ install",
      "npm --prefix ./functions/ run lint",
      "npm --prefix ./functions/ run build"
    ],
    "source": "functions"
  }
}
Run Code Online (Sandbox Code Playgroud)

这里有一些讨论: https ://github.com/w9jds/firebase-action/issues/30

另外,请确保tslinteslint、 和tsc位于您的文件devDependenciespackage.json