GitHub Actions 部署构建时出现错误

Posted

技术标签:

【中文标题】GitHub Actions 部署构建时出现错误【英文标题】:GitHub Actions Deployment building with errors 【发布时间】:2021-11-26 09:37:51 【问题描述】:

我的 GitHub Actions 成功完成,但是当我访问我的网站时,我看到的只是一个空白页面。从 chrome 开发工具中,我检查了控制台,我看到了这个错误:

react-dom.production.min.js:216 Error: accountId is required
    at Z (brightcove-react-player-loader.es.js:950)
    at Q (brightcove-react-player-loader.es.js:1061)
    at X (brightcove-react-player-loader.es.js:1126)
    at r.o.loadPlayer (brightcove-react-player-loader.es.js:1350)
    at r.o.componentDidMount (brightcove-react-player-loader.es.js:1519)
    at hu (react-dom.production.min.js:219)
    at As (react-dom.production.min.js:259)
    at t.unstable_runWithPriority (scheduler.production.min.js:18)
    at Ha (react-dom.production.min.js:122)
    at Ts (react-dom.production.min.js:252)
uu @ react-dom.production.min.js:216

以下是我的 yaml 文件,它创建了一个包含 BrightCove ID 的 .env 文件,但由于某种原因它没有从 .env 获取 ID...

# This is a basic workflow to help you get started with Actions

name: Deploy React Dev

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ development ]
  pull_request:
    branches: [ development ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

env:
  REACT_APP_BRIGHTCOVE_ID: $ secrets.REACT_APP_BRIGHTCOVE_ID 

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./app
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2.3.4
      # Create .env
      - name: Create env file
        run: |
          touch .env
          echo REACT_APP_AUTH0_DOMAIN=$ secrets.REACT_APP_AUTH0_DOMAIN  >> .env
          echo REACT_APP_AUTH0_CLIENT_ID=$ secrets.REACT_APP_AUTH0_CLIENT_ID  >> .env
          echo REACT_APP_AUTH0_AUDIENCE=$ secrets.REACT_APP_AUTH0_AUDIENCE  >> .env
          echo REACT_APP_VIDEO_URL=$ secrets.REACT_APP_VIDEO_URL  >> .env
          echo REACT_APP_STORE_NAME=$ secrets.REACT_APP_STORE_NAME  >> .env
          echo REACT_APP_PAYPAL_CLIENT_ID=$ secrets.REACT_APP_PAYPAL_CLIENT_ID  >> .env
          echo REACT_APP_HASURA_GRAPHQL_ENDPOINT=$ secrets.REACT_APP_HASURA_GRAPHQL_ENDPOINT  >> .env
          echo REACT_APP_BRIGHTCOVE_ID=$ secrets.REACT_APP_BRIGHTCOVE_ID  >> .env
          echo HASURA_GRAPHQL_ADMIN_SECRET=$ secrets.HASURA_GRAPHQL_ADMIN_SECRET  >> .env
      # Set up Node JS
      - uses: actions/setup-node@master
        with:
          node-version: '16.x'
          cache: 'yarn'
          cache-dependency-path: app/yarn.lock
      # Use cached node_modules directory
      - uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: $ runner.os -modules-$ hashFiles('**/yarn.lock') 
      # Install & build
      - run: yarn install
      - run: yarn build
      # Upload artifact
      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: webapp
          path: app/build
  deploy:
    runs-on: ubuntu-latest
    environment: Orange Develop
    needs: build
    steps: 
      - name: Download artifact
        uses: actions/download-artifact@v2
        with:
          name: webapp
      # Deploy webapp to Orange server
      - name: SCP deployment to Orange
        uses: appleboy/scp-action@master
        with:
          host: $ secrets.FTP_HOST 
          username: $ secrets.FTP_USER 
          key: $ secrets.FTP_KEY 
          source: '.'
          target: '/opt/media-exchange/app/build'
          rm: true`

【问题讨论】:

【参考方案1】:

在这个 *** 问题上找到答案:https://***.com/a/66929604/14502018

我需要设置存储我的秘密的环境。 在构建作业中,我添加了这一行:

build:
    runs-on: ubuntu-latest
    environment: Orange Develop #MISSING LINE

【讨论】:

很高兴您能够解决自己的问题。为了使您的答案对其他用户有用,1) 接受它,2) 链接对您有帮助的答案,而不是问题。使用相关答案底部的Share 链接来执行此操作,3)具体指出您为使代码正常工作所做的更改。您可以在代码中添加注释,或者只发布一个小的相关 sn-p 而不是整个文件。 @thisisrandy 感谢您的建议!答案已更新!

以上是关于GitHub Actions 部署构建时出现错误的主要内容,如果未能解决你的问题,请参考以下文章

记录在使用 GitHub Actions 时出现的 Permission Denied 问题及办法

使用 jest-puppeteer 在 GitHub Actions 中构建和启动 2 个应用程序会导致读取环境变量时出现问题

jest.config.ts:从 Github Actions 运行 jest 时出现“registerer.enabled 不是函数”错误

GitHub Actions 因从 JsonReader 错误读取 JToken 而失败

使用GitHub Actions自动构建DockerHub镜像

设置 QEMU 时出现 Github 操作错误 - 错误:无法找到可执行文件:docker