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.97k stars 226 forks source link

Retry for non-fast-forward pushes #170

Closed koppor closed 3 years ago

koppor commented 3 years ago

Is your feature request related to a problem? Please describe.

I am running a build matrix, where each job updates another file. I want to have all updates committed. The second job outputs the following error:

  ! [rejected]        switch-to-github-actions -> switch-to-github-actions (non-fast-forward)
error: failed to push some refs to 'latextemplates/LNCS'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 1

Describe the solution you'd like

The action should do a pull if it encounters "non-fast-forward" as push result and then retry. In case it encounters that again, it should do another retry. It should do so until it succeeds (or maybe 100 tries are reached).

Describe alternatives you've considered

One could issue git fetch just before the action (similar to the proposal at https://github.com/stefanzweifel/git-auto-commit-action/issues/142#issuecomment-784444823). However, if first job 2 rebases, then job 3, then job 2 commits and then job 3 commits, job 3 still fails.

I also tried skip_fetch: false, but I still encounter this issue.

This is not https://github.com/stefanzweifel/git-auto-commit-action/issues/102, because it is not a shallow update.

stefanzweifel commented 3 years ago

Thanks for reporting! I can see the pain point here.

However, I'm really hesitant to solve this issue within git-auto-commit. The main goal of the Action is to "commit and push" and not necessarily to resolve issues when the push fails due to the local version to be out of date (but I can also see reasons why this Action should solve these problems).

Adding support for both git rebase and git merge strategies is just something I'm not keen on adding; I would like to keep this Action as basic as possible. Hence the "80% use case" in the README.


I keep a private note with ideas for v5. Added solving such problems to that note.

In the meantime, I'm sorry to say you have to solve this issue yourself in your Workflow. Feel free to share your solution here, so others can benefits from it.

I will also update the Limitations section in the README in the next days. Will add "running in a build matrix" to that list.

koppor commented 3 years ago

I finally found a working solution - unfortunately, by switching to another action: https://github.com/marketplace/actions/add-commit

      - name: Commit changes
        uses: EndBug/add-and-commit@v7
        with:
          message: 'Update files based on generated files by template generator'
          pull_strategy: 'NO-PULL'
          push: false
      - name: Push changes
        run: |
          git pull --rebase
          git push

Since I seem to be the only one asking here for such a thing and I found a workaround, I will close the issue.

stefanzweifel commented 3 years ago

@koppor I'm glad you could solve the problem. I've added a link to the add-commit Action to the README, so others can learn and use it if git-auto-commit doesn't help in their workflows.

koppor commented 3 years ago

@stefanzweifel Thank you for adding the link.

The solution sketched above is written in length at https://github.com/EndBug/add-and-commit/issues/262#issuecomment-901473894.

fritx commented 1 year ago

I finally found a working solution - unfortunately, by switching to another action: https://github.com/marketplace/actions/add-commit

      - name: Commit changes
        uses: EndBug/add-and-commit@v7
        with:
          message: 'Update files based on generated files by template generator'
          pull_strategy: 'NO-PULL'
          push: false
      - name: Push changes
        run: |
          git pull --rebase
          git push

Since I seem to be the only one asking here for such a thing and I found a workaround, I will close the issue.

@koppor if I want more assurance, how to add some retry loops to the run: commands?

@koppor I'm glad you could solve the problem. I've added a link to the add-commit Action to the README, so others can learn and use it if git-auto-commit doesn't help in their workflows.

@stefanzweifel would git-auto-commit consider adding some git pull --rebase retry support for this?

stefanzweifel commented 1 year ago

@fritx

would git-auto-commit consider adding some git pull --rebase retry support for this?

No, there are no current plans to add support for retries using git pull or git pull --rebase. (Maybe in a new major version, but I haven't started working on that.) This I a can of worms I just don't want to open. This Action showed me, that people are using git in so many different ways. See also https://github.com/stefanzweifel/git-auto-commit-action#limitations--gotchas.

fritx commented 1 year ago

@stefanzweifel OK. My case is that I have multiple jobs concurrently triggered that commit separately to the same branch. So it can have concurrent problem sometimes with git-auto-commit