如何使用Github Actions保存构建文件(React)

时间:2019-10-12 10:54:41

标签: reactjs continuous-integration continuous-deployment github-actions

我正在尝试使用github动作来构建React代码。 但是在成功构建文件之后,我想将其保存在特定位置,在存储库中说“ build”文件夹。 我目前能够构建文件,但无法将其保存在仓库中

2 个答案:

答案 0 :(得分:0)

如果您想在工作流中尝试将构建工件自己提交回存储库,请参阅以下答案,了解如何准备存储库和git config。

Push to origin from GitHub action

或者,您可能会发现create-pull-request操作对此用例有用。它将对“动作”工作区的更改提交到新分支,并提出拉取请求。因此,如果在工作流期间创建工件后调用create-pull-request操作,则可以将该更改作为PR提出,以供您查看和合并。

例如:

on: release
name: Update Version
jobs:
  createPullRequest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      ...
      (your build steps)
      ...
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v1.5.2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          COMMIT_MESSAGE: Add build artifact
          PULL_REQUEST_TITLE: Add build artifact

答案 1 :(得分:0)

我刚刚使用过https://github.com/s0/git-publish-subdir-action,效果很好。它只是将文件从给定的文件夹转储到分支中。这是对我有用的示例工作流程文件:

name: Build Data

on:
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python 3.x
      uses: actions/setup-python@v2
      with:
        python-version: '3.x' 

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r tools/requirements.txt

    - name: Run python script
      run: python tools/data_builder.py

    # THIS IS WHERE THE DATA IS PUBLISHED TO A BRANCH
    - name: Deploy
      uses: s0/git-publish-subdir-action@master
      env:
        REPO: self
        BRANCH: data_build
        FOLDER: tools/data_build
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

这里正在起作用:https://github.com/2020PB/police-brutality/blob/4818ae367f2627c7a456bd3c6aa866054e618ac8/.github/workflows/build_data_ci.yml