使用 github 个操作部署 firebase 云函数

Deploying firebase cloud functions using github actions

我正在尝试使用 github 操作部署我的 firebase 云函数应用程序:

name: Deploy

'on':
  push:
    branches:
      - main

jobs:
  deploy_to_production:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: install dependencies
        run: cd functions/ && npm install
      - name: deploy to production
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only functions
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
          

“部署到生产环境”步骤不成功。我激活了调试模式,但实际上并没有收到任何有用的信息:

##[debug]Evaluating: secrets.FIREBASE_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'FIREBASE_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'deploy to production'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: deploy to production
##[debug]Loading inputs
##[debug]Loading env
Run w9jds/firebase-action@master
  with:
    args: deploy --only functions
  env:
    FIREBASE_TOKEN: ***
/usr/bin/docker run --name w9jdsfirebaseactionv212_2c5197 --label 08450d --workdir /github/workspace --rm -e FIREBASE_TOKEN -e INPUT_ARGS -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_DEBUG -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/personalsite-backend/personalsite-backend":"/github/workspace" w9jds/firebase-action:v2.1.2 deploy --only functions
##[debug]Docker Action run completed with exit code 2
##[debug]Finishing: deploy to production

我是不是漏掉了什么?

注意:本地我可以毫无问题地部署。

通过使用 w9jds/firebase-action,存在一个已知问题,如果您使用 uses: w9jds/firebase-action@master,它会尝试存储 CLI 吐出的内容,如果出错并在回显之前结束操作这可能会阻止它打印出响应。来自存储库所有者的更多信息 here.

从版本 v2.1.2 开始,您必须替换此行:

uses: w9jds/firebase-action@master

对此:

uses: docker://w9jds/firebase-action:master

更多信息here


此外,还有一个替代解决方案,使用 actions/checkout 代替。请参阅下面的 yaml 配置:

name: Deploy to Firebase Functions via github action
"on":
  push:
    branches:
      - main
env:
  CI: false

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Download deps
        working-directory: functions
        run: npm install

      - name: Deploy
        run: npx firebase-tools deploy
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

注意:我在上面的示例 yaml 中使用了 actions/checkout@v2,但现在可以使用 v3

除了 Marc Anthony B , if you are having difficulties creating your .yml file to deploy your applications through GitHub actions, 不错的教程会帮助你。