stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
1.98k stars 227 forks source link

Action sometimes fails when jobs are re-run #155

Closed jojo2357 closed 3 years ago

jojo2357 commented 3 years ago

Version of the Action v4.10.0 v4.9.2

The bug When using this action in a workflow, it fails when the workflow makes changes to the repo during a re-run of the job.

To Reproduce

  1. Create a workflow that makes changes and runs on push
  2. Make a commit to activate the workflow and ensure the workflow applies changes
  3. Change the source of an action in the workflow to ensure that the workflow will create new changes and the repo will be dirty
  4. Request re-run jobs (since you havent made a new commit, to apply the new action, you must re-run jobs)
  5. This job will fail

Expected behavior The action will complete without error and create a new commit

Used Workflow

name: create stats

on: push

jobs:
  generate-file:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Code_Stats
        uses: jojo2357/CodeStats@Dev
        with:
          root_dir: 'src/main/java/frc'

      - name: Git Auto Commit
        uses: stefanzweifel/git-auto-commit-action@v4.10.0
        with:
          branch: ${{ github.head_ref }}
          commit_message: Woooooooooo stats
          commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
          commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com

Additional context A log of a failed run can be found here

stefanzweifel commented 3 years ago

Re-running a workflow will use the exact same commit SHA and ref values (Docs).

So when a workflow is re-run, it won't checkout the latest commit of your project, but rather the exact same commit for which the run was originally created.

git-auto-commit won't/can't solve this problem for you. As the name suggest, it's about committing and pushing. If you regularly encounter this problem I would suggest two options:

(I won't add a git pull call to the Action, as I think the consumers of this Action should be in control of this step. A git pull could also lead to merge conflicts which can be solved in different ways. It's easier for us if consumers of the Action are in control of this step)

jojo2357 commented 3 years ago

Ah yes that makes sense. In my particular case, adding force should do the trick since the data overwrites anyway. I just didn't know if it was a me problem or an action problem or the fix so thanks for that.