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

Pushing changes fail #79

Open
Kraymer opened this issue Jan 25, 2021 · 5 comments
Open

Pushing changes fail #79

Kraymer opened this issue Jan 25, 2021 · 5 comments

Comments

@Kraymer
Copy link

Kraymer commented Jan 25, 2021

My action :

name: foobar

on: [pull_request]

jobs:
  hello_world_job:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Get changed files
        id: files
        uses: jitterbit/get-changed-files@v1
        with:
          format: 'space-delimited'

      - name: Action that add a new file in repo
            ...

      - name: Commit files
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git add .
          git commit -m "Add changes" -a
          
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: ${{ github.head_ref }}

Error log :

Run ad-m/github-push-action@master
  with:
    github_token: ***
    branch: gh-action-generate
    directory: .
Push to branch gh-action-generate
To https://github.com/Kraymer/Simple-Repertoire.git
 ! [rejected]        HEAD -> gh-action-generate (fetch first)
error: failed to push some refs to 'https://github.com/Kraymer/Simple-Repertoire.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Error: Invalid exit code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:29:21)
    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 exit code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:29:21)
    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)

Note: I did not commit in the remote branch after the commit that triggered the action

@navaneeth-spotnana
Copy link

Clue:

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

I had the same issue, but my case was a different clue, and so a different fix. 😝

@navaneeth-spotnana
Copy link

Yo. Now I got your same error. Add force: true to fix this:

      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: ${{ github.head_ref }}
          force: true

@navaneeth-spotnana
Copy link

Not sure if force pushing is going to be safe, I'm wondering if doing a git pull before you push would do the job.

@fs-c
Copy link

fs-c commented May 12, 2021

Quick note in response to the force push suggestion: Don't force push unless you know what you are doing. Many, many people have shot themselves in the foot with git push -f.

Also, as another data point, I get the same error as the OP on ad-m/github-push-action@master but ad-m/github-push-action@v0.5.0 works fine.

And on an unrelated note, it's a really bad practice to recommend people to use ad-m/github-push-action@master as is being done in the README. It might just introduce unexpected errors in people's workflows even though seemingly nothing changed...

@jg75
Copy link

jg75 commented May 4, 2023

It looks like you would get this error if you have no new commits to push. For example, let's say you have a workflow that triggers on a pull_request that does:

  • checkout
  • install dependencies
  • format code (e.g. prettier)
  • build & test
  • stage and commit changes, if any from the code format step
  • push

If there are no changes in the format code step, you'll get that error in the push step. So, question then. Should you commit with --allow-empty and just always create another commit or is it possible to fail gracefully if there is nothing to push?

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