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

remote rejected: cannot lock ref #61

Open
kenorb opened this issue Jul 14, 2020 · 4 comments
Open

remote rejected: cannot lock ref #61

kenorb opened this issue Jul 14, 2020 · 4 comments

Comments

@kenorb
Copy link

kenorb commented Jul 14, 2020

The following error can happen at random especially for jobs in parallel (matrix). This could be related to race condition.

Run ad-m/github-push-action@master
  with:
    branch: refs/heads/optimize-strategy-ac
    github_token: ***
    directory: .
Started: bash /home/runner/work/_actions/ad-m/github-push-action/master/start.sh
Push to branch refs/heads/optimize-strategy-ac
To https://github.com/EA31337/EA31337-Lite-optimization-tests.git
 ! [remote rejected] HEAD -> optimize-strategy-ac (cannot lock ref 'refs/heads/optimize-strategy-ac': is at 98bf7e54a615d7e23cbcf8688d22c4099a1d2240 but expected 00da1b358846ae9a8ffa71b34eb1e330e3a37e3d)
error: failed to push some refs to 'https://github.com/EA31337/EA31337-Lite-optimization-tests.git'
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:9: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
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:9: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)

My config:

    steps:
      - uses: actions/checkout@v2
        with:
          persist-credentials: false
          # Otherwise, you will failed to push refs to dest repo.
          fetch-depth: 0
      - run: docker-compose run $DCA ${{ matrix.test }}
      - name: Commit files
        run: |
          git config --local core.autocrlf false
          git config --local user.email "${{ github.actor }}@users.noreply.github.com"
          git config --local user.name "${{ github.actor }}"
          git pull origin ${{ github.ref }} --autostash --rebase -Xours
          git add --renormalize .
          git status
          git commit -am "${{ github.workflow }}"
      - name: Git Diff
        run: NO_PAGER=1 git --no-pager diff HEAD^
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          branch: ${{ github.ref }}
          github_token: ${{ secrets.GITHUB_TOKEN }}

I don't want to force push (because obviously something changed upstream right after the pull), so maybe integrating pull feature as well right before push could be useful and do some customizable number of retries?

One workaround is to move push action outside of matrix jobs by uploading changed from from matrix job, then downloading artifacts (e.g. patches) and push the changes at the final stage.

@kenorb
Copy link
Author

kenorb commented Sep 9, 2020

Workaround

As for the workaround, I've re-pulled and pushed again after the job failure.

      - name: Commit files
        run: |
          git config --local core.autocrlf false
          git config --local user.email "${{ github.actor }}@users.noreply.github.com"
          git config --local user.name "${{ github.actor }}"
          git add . && git add --renormalize .
          git pull origin ${{ github.ref }} --autostash --rebase -X ours
          git commit --allow-empty -am "${{ github.workflow }}"
          NO_PAGER=1 git --no-pager diff HEAD^
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          branch: ${{ github.ref }}
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Re-pull on failure
        if: ${{ failure() }}
        run: git pull origin ${{ github.ref }} --autostash --rebase -X ours
      - name: Re-push on failure
        if: ${{ failure() }}
        uses: ad-m/github-push-action@master
        with:
          branch: ${{ github.ref }}
          force: true
          github_token: ${{ secrets.GITHUB_TOKEN }}

But would be great to add some pull feature and re-try system to this action to try again, in case the remote HEAD changed.

@lucharo
Copy link

lucharo commented Sep 30, 2020

Hey @kenorb this really helped, thank you!

@gergokee
Copy link

gergokee commented Apr 18, 2024

i have the same issue, is there any planned fix for this ?

@ZPascal
Copy link
Collaborator

ZPascal commented May 2, 2024

@gergokee I think, the issue is already solved by using the --atomic option by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants