Github 每个新的提交操作-工作流反应 js 构建

Github every new commit actions-workflow react js build

我在 react js 中有一个 Github 项目,有一个 github-pages 页面。

每当我对项目进行更改时,在推送之前,我 运行 yarn build 命令为 github-pages 创建内容,然后推送。

我想做的是,每次在项目中进行新的提交时,随后都会执行构建。 无需我手动操作。

原因是如果我在github项目上直接在浏览器上修改,我无法构建项目,因为我没有下载的项目及其npm modules

我想知道是否可以做这样的事情?

package.json

"build": "npm run watch:css && react-scripts build && cp -R ./copy-build/. ./build && rm -rf docs && mv build docs"

解决方案:

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

name: Build

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

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

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      
      - name: Install Yarn
        run: yarn
          
      - name: Build
        run: yarn build