Adithya d
Adithya d

Reputation: 43

How to save build files (React) using Github Actions

I am trying to build react code using github actions. But after successfully building the files i want to save it in a particular location say "build" folder in the repo. I am currently able to build the files but not save them in the repo

Upvotes: 0

Views: 2580

Answers (2)

ubershmekel
ubershmekel

Reputation: 12808

I just used https://github.com/s0/git-publish-subdir-action and it worked great. It just dumps files from a given folder into a branch. Here's an example workflow file that worked for me:

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 }}

And here is in action: https://github.com/2020PB/police-brutality/blob/4818ae367f2627c7a456bd3c6aa866054e618ac8/.github/workflows/build_data_ci.yml

Upvotes: 0

peterevans
peterevans

Reputation: 41970

If you would like to try and commit your build artifacts back to the repository yourself in a workflow see the following answer for how to prepare the repository and git config.

Push to origin from GitHub action

Alternatively, you might find create-pull-request action useful for this use case. It will commit changes to the Actions workspace to a new branch and raise a pull request. So if you call create-pull-request action after creating your artifacts during a workflow, you can have that change raised as a PR for you to review and merge.

For example:

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

Upvotes: 1

Related Questions