【问题标题】:How can I deploy firebase functions through github actions?如何通过 github 操作部署 firebase 功能?
【发布时间】:2021-01-19 13:53:51
【问题描述】:

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

dev-internal-web
-.firebase
-.github
-e2e
-functions
-node_modules
-src
(misc files)

我有一个函数文件夹,其中包含 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

在文件夹内的 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

按照评论中的说明删除 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

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

【问题讨论】:

  • 我找到了一个链接:npmjs.com/package/tslint 那里有一条红色消息可以提供帮助:此包已被弃用 作者消息:TSLint 已被弃用,取而代之的是 ESLint。请参阅github.com/palantir/tslint/issues/4534 了解更多信息。
  • @MrTech 在尝试删除 tslint 之后(我刚刚重新初始化了 firebase 函数,因为我还没有在那里做任何工作)我现在收到这个错误:npm ERR! functions@ build: tsc
  • 为了继续前进,我找到了一个可以帮助您的详细教程。 medium.com/mainlycoding-com/…
  • @MrTech 我已经尝试过了,但它对我不起作用。我尝试将其添加到原始文件的末尾,但没有奏效,所以我尝试了一个新文件(也没有奏效)。托管没有问题,但我复制了那篇文章底部的脚本,它不起作用。
  • 为了进一步研究,当它不起作用时是否有任何错误消息?

标签: firebase npm google-cloud-functions github-actions firebase-cli


【解决方案1】:

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"
  }
}

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

另外,请确保 tslinteslinttsc 在您的 devDependencies 中的 package.json 文件中。

【讨论】:

    猜你喜欢
    • 2017-08-17
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 2020-09-25
    • 1970-01-01
    • 2020-07-13
    • 2022-12-15
    相关资源
    最近更新 更多