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
2 Answers
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

- 34,297
- 7
- 84
- 83
-
Thanks that link helped. now building in github branch create-react-app Build files directly in github. – Adithya d Oct 31 '19 at 07:11
-
The answer seems not to answer the exact question asked! @Adithyad please share how you able to build directly in github. – TrevorDeTutor Oct 08 '22 at 10:18
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

- 11,864
- 10
- 72
- 89
-
1Please don't just post some tool or library as an answer. At least demonstrate [how it solves the problem](https://meta.stackoverflow.com/a/251605) in the answer itself. – double-beep Jun 04 '20 at 05:36
-
Thank you for calling that out @double-beep I've added the workflow file to clarify. – ubershmekel Jun 05 '20 at 07:55