I’m trying to have GitHub perform an action on some files in my repo every time one of them gets edited within the GH web interface.
The action performs but the files that are generated afterwards are lost when the workflow finishes.
I’d like them to go into an ‘output/‘ directory inside the root of my repo. How can I go about this?
Hi @chris-c-thomas ,
Github hosted runner will be released after workflow completed, thus it will not store the generated files, you need to push the files to repo.
Step1: put the generated files into dir ‘output’.
Step2: push the output folder to your repo.
You can check my sample code below, my repo here.
name: commitfiles
on: [push]
jobs:
job1:
runs-on: [ubuntu-latest]
steps:
- name: checkout
uses: actions/checkout@v2
- name: Modify value # Tried to modify the files based on existing testfile.txt
run: |
echo 'Add value2' >> testfile.txt
- name: move to dir # Move the generated files into output folder
run: |
mkdir -p output
yes| cp -rf testfile.txt ./output/
- name: Commit files # commit the output folder
run: |
git config --local user.email "test@github.com"
git config --local user.name "GitHub Action test"
git add ./output
git commit -m "Add changes"
- name: Push changes # push the output folder to your repo
uses: ad-m/github-push-action@master
with:
branch: B77 #ignore if your branch is master
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true
Hope it helps.
4 Likes
@weide-zhouthis is exactly what I was looking for! Thank you for providinng an example, it’s clear and concise!