1

I am using the code below in YML file to commit and push "data.xlsx" file within scheduled github actions. There are sometimes this file ("data.xlsx") doesn't get created so commit returns errors - "Your branch is up to date with 'origin/main'. nothing to commit, working tree clean. Error: Process completed with exit code 1" Is there any way to not to run this section when file does not exist

- name: Commit files
  run: |
    git config --local user.name actions-user
    git config --local user.email "[email protected]"
    git add *
    git commit -am "GH ACTION Headlines $(date)"
    git push origin main -f
  env:
    REPO_KEY: ${{secrets.GITHUB_TOKEN}}
    username: github-actions

1 Answer 1

2

You could use this file-existence action that returns a boolean output if the file exists or not.

Then add an if condition to your Commit files step depending on this boolean output.

It would look like this:

 - name: "Check file existence"
   id: check_files
   uses: andstor/file-existence-action@v2
   with:
     files: "data.xlsx"
- name: Commit files
  if: steps.check_files.outputs.files_exists == 'true'
  run: |
    git config --local user.name actions-user
    git config --local user.email "[email protected]"
    git add *
    git commit -am "GH ACTION Headlines $(date)"
    git push origin main -f
  env:
    REPO_KEY: ${{secrets.GITHUB_TOKEN}}
    username: github-actions

Note: But sure to give the job the permissions: write-all otherwise you would need to use a PAT instead of the GITHUB_TOKEN to push the code.

Sign up to request clarification or add additional context in comments.

1 Comment

id: check_files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.