【问题标题】:How to save build files (React) using Github Actions如何使用 Github Actions 保存构建文件 (React)
【发布时间】:2020-02-09 16:45:07
【问题描述】:

我正在尝试使用 github 操作构建反应代码。 但是在成功构建文件后,我想将其保存在特定位置,例如 repo 中的“build”文件夹。 我目前能够构建文件但不能将它们保存在 repo 中

【问题讨论】:

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


    【解决方案1】:

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

    Push to origin from GitHub action

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

    例如:

    on: release
    name: Update Version
    jobs:
      createPullRequest:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          ...
          (your build steps)
          ...
          - name: Create Pull Request
            uses: peter-evans/create-pull-request@v2
            with:
              token: ${{ secrets.GITHUB_TOKEN }}
              commit-message: Add build artifact
              title: Add build artifact
    

    【讨论】:

    • 感谢该链接的帮助。现在在 github 分支中构建 create-react-app 直接在 github 中构建文件。
    【解决方案2】:

    我刚刚使用了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

    【讨论】:

    • 请不要只发布一些工具或库作为答案。至少在答案本身中展示how it solves the problem
    • 感谢您指出@double-beep 我已添加工作流文件以进行澄清。
    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 2020-11-26
    • 2020-05-31
    • 1970-01-01
    • 2021-04-29
    • 2020-04-26
    • 2019-06-16
    • 1970-01-01
    相关资源
    最近更新 更多