Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry for non-fast-forward pushes #170

Closed
koppor opened this issue Aug 17, 2021 · 7 comments
Closed

Retry for non-fast-forward pushes #170

koppor opened this issue Aug 17, 2021 · 7 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@koppor
Copy link

koppor commented Aug 17, 2021

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 #142 (comment)). 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 #102, because it is not a shallow update.

@stefanzweifel stefanzweifel added bug Something isn't working enhancement New feature or request labels Aug 17, 2021
@stefanzweifel
Copy link
Owner

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
Copy link
Author

koppor commented Aug 19, 2021

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 koppor closed this as completed Aug 19, 2021
@stefanzweifel
Copy link
Owner

@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
Copy link
Author

koppor commented Aug 19, 2021

@stefanzweifel Thank you for adding the link.

The solution sketched above is written in length at EndBug/add-and-commit#262 (comment).

@fritx
Copy link

fritx commented Oct 21, 2022

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
Copy link
Owner

@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
Copy link

fritx commented Oct 21, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants