环境变量未通过 firebase Github CI 传递

时间:2021-04-06 22:22:36

标签: firebase github continuous-integration environment-variables github-actions

我使用 firebase init hosting:github 来设置 CI 和 react/webpack 应用程序,我正在推送到主应用程序进行部署。

我遇到的问题是我的环境变量被存储在一个 .env 文件中用于开发,我试图让它们与 github 的构建动作一起工作,并且部署到 firebase 托管的许多事情不是背着他们过去。

我知道这一点,因为当操作成功运行并且部署的站点将抛出与丢失或无效的 API 密钥相关的错误时,这些 API 密钥保存为环境变量。

这是我的 GitHub 工作流 (yml) 文件的样子

name: Deploy to Firebase Hosting on merge
'on':
  push:
    branches:
      - main
env:
  FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }} # I have tried using this at the top level and also with the other env scope below.
  
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: npm ci && npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_CLUBELO }}'
          channelId: live
          projectId: example
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels

然后在我的代码中,我只使用了 process.env.FIREBASE_API_KEY ,它适用于开发,当我手动运行构建和部署到 firebase 时,一切都按预期工作。

注意事项

  • 是的,密钥在 Github Secrets 中
  • 我先检查了明显的拼写错误

0 个答案:

没有答案
相关问题