AkhileshNS / heroku-deploy

A simple github action that dynamically deploys an app to heroku
MIT License
972 stars 253 forks source link

Error: Command failed: git push heroku HEAD:refs/heads/main --force #84

Open IshaanOhri opened 3 years ago

IshaanOhri commented 3 years ago

Error I received

image image

My file:

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install packages
        run: npm install
      - name: Build project
        run: npm run-script build
      - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: ${{secrets.HEROKU_APP_NAME}} #Must be unique in Heroku
          heroku_email: ${{secrets.HEROKU_EMAIL}}
          procfile: 'web: npm start'
rn4n commented 3 years ago

Same.

Run akhileshns/heroku-deploy@v3.12.12
  with:
    heroku_api_key: ***
    heroku_app_name: ***
    heroku_email: ***
    branch: main
    dontuseforce: true
    dontautocreate: false
    usedocker: false
    docker_heroku_process_type: web
    delay: 0
    rollbackonhealthcheckfailed: false
    justlogin: false
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.2/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.2/x64/lib
From https://github.com/cationhq/***
 * [new branch]      development -> origin/development
 * [new tag]         v1.0.0      -> v1.0.0
Created and wrote to ~/.netrc
Successfully logged into heroku
 ›   Warning: Our terms of service have changed: 
 ›   https://dashboard.heroku.com/terms-of-service
Added git remote heroku
To https://git.heroku.com/***.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.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.

            Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch. 
            (If you want to avoid this, set dontuseforce to 1 in with: of .github/workflows/action.yml. 
            Specifically, the error was: Error: Command failed: git push heroku main:refs/heads/main 
To https://git.heroku.com/***.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.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.

To https://git.heroku.com/***.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.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
Error: Error: Command failed: git push heroku main:refs/heads/main 
To https://git.heroku.com/***.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.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.

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.

My action:

- name: deploy to heroku
        uses: akhileshns/heroku-deploy@v3.12.12
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
          heroku_email: ${{secrets.HEROKU_EMAIL}}
          branch: main
          dontuseforce: true
mustafaergul commented 3 years ago

+1

Error I received

image image

My file:

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install packages
        run: npm install
      - name: Build project
        run: npm run-script build
      - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: ${{secrets.HEROKU_APP_NAME}} #Must be unique in Heroku
          heroku_email: ${{secrets.HEROKU_EMAIL}}
          procfile: 'web: npm start'
IshaanOhri commented 3 years ago

@AkhileshNS could you please help us resolve this issue?

This has been a very common issue I have faced. It occurs sometimes and sometimes it doesn't.

rn4n commented 3 years ago

@IshaanOhri I couldn't wait for a fix or a response from the developers, so I started using Heroku's automatic deploy. 😄 I removed the deployment part from my workflow and left only the steps that executes before (running tests, lint, etc). And then, on Heroku, I enabled the option to run deploy only on a specific branch (in this case, the main) and only after the CI has successfully run.

image

Maybe you should try, cheers.

madhums commented 3 years ago

@AkhileshNS This action does not work anymore because of this error, could you have a look at the issue? Indeed what @rn4n proposes is a workaround for CD.

madhums commented 3 years ago

Seems to be failing here and it's not picking up the heroku_app_name key https://github.com/AkhileshNS/heroku-deploy/blob/master/index.js#L20-L22

Screenshot 2021-04-19 at 14 46 26
IshaanOhri commented 3 years ago

@IshaanOhri I couldn't wait for a fix or a response from the developers, so I started using Heroku's automatic deploy. 😄 I removed the deployment part from my workflow and left only the steps that executes before (running tests, lint, etc). And then, on Heroku, I enabled the option to run deploy only on a specific branch (in this case, the main) and only after the CI has successfully run.

image

Maybe you should try, cheers.

I find this to be a great walkaround. Thanks!

DrPep commented 3 years ago

TL;DR: Ensure your secrets are defined and accessible.

For those of you discovering this issue today, I had the same problem. I determined it was being caused by the HEROKU_API_KEY not being defined in secrets for the repository. The error message is something of a misnomer as it shows successfully logged into heroku in the output, despite that clearly not being the case (in our instance).

HTH

Rahul-D78 commented 3 years ago

github_heroku

I think the problem is heroku app is using master branch as a default branch .

iampava commented 2 years ago

Any status updates on this?

AkhileshNS commented 2 years ago

Hey everyone, sorry about the extremely delayed response (COVID-19 + College is making it hard to stay on track with this). But I have been working on a fix on this for a while, I haven't been able to resolve it yet. My suspicion is that these could likely be multiple issues layered behind a common logging message (so there's obviously a need to improve the logging on these things). I am working on this, I'm not quite near a fix yet but I am working. I'll try and keep updated from now on and hopefully resolve this in a new release soon

iteesoft commented 2 years ago

@AkhileshNS please I'll appreciate it if we can get an update on this when resolved, thanks.

AkhileshNS commented 2 years ago

I'll have an update by tomorrow

krishna-ms-git commented 2 years ago

@AkhileshNS Any further updates please?

ianmartorell commented 2 years ago

My deployments started failing sometimes with the following error:

 ! [rejected]          HEAD -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/XXX.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.

It's weird because retrying the job usually makes it work 🤔 so definitely not an issue with secrets not being set.

muntiMedia commented 2 years ago

"git push heroku main " is not uploading. It is showing error: src refspec main does not match any error: failed to push some refs to 'https://git.heroku.com/arcane-lowlands-81668.git' was anybody able to resolve the issue?

geoffrey1330 commented 2 years ago

Guys previously I ran through the same issue only to find out that the problem is from the way I started my secret. I created my secret in the dependentbot section instead of the Action section

mohit000001 commented 2 years ago

@AkhileshNS , now it has been a year. any update ?

kuldeepsinghsekhon commented 2 years ago

when i run on local i need to add heroku remote, so same is required in action heroku git:remote -a app-name
then we can run command git push heroku main:refs/heads/main or your brach eg stage git push heroku stage:refs/heads/main

mdrahiem commented 2 years ago

In my case updating secret API_KEY and EMAIL_ID again, worked for me!

rbclark commented 2 years ago

In my case when trying to add the Heroku Remote I am getting an error, it seems the assumption the @AkhileshNS made that this is happening for multiple reasons is correct.

 Created and wrote to ~/.netrc
Successfully logged into heroku
 ›   Warning: Our terms of service have changed: 
 ›   https://dashboard.heroku.com/terms-of-service
Added git remote heroku
heroku: Press any key to open up the browser to login or q to exit: fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

            Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch. 
            (If you want to avoid this, set dontuseforce to 1 in with: of .github/workflows/action.yml. 
            Specifically, the error was: Error: Command failed: git push heroku HEAD:refs/heads/main 
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: 'heroku' does not appear to be a git repository
Error: Error: Command failed: git push heroku HEAD:refs/heads/main --force
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
cansin commented 2 years ago

We were having a similar issue (if not the same). Turns out we forgot to add our bot account to the Heroku application (with Deploy access) (Instead only added it to the pipeline 🤦‍♂️). Doing that, plus the below deploy.yml works for us currently:

name: Deploy

concurrency:
  group: deploy
  cancel-in-progress: false

on:
  push:
    branches:
      - master

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Deploy code
        uses: akhileshns/heroku-deploy@v3.12.12
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "sample-app-name"
          heroku_email: "bot@sample.com"
          team: "sample-team"
          dontuseforce: true
          dontautocreate: true

Hope this helps someone.

rbclark commented 2 years ago

Interestingly for me just regenerating the deploy token fixed the problem.

javi-aranda commented 2 years ago

Interestingly for me just regenerating the deploy token fixed the problem.

This worked for me, thank you!

SaD-Pr0gEr commented 2 years ago

Interestingly for me just regenerating the deploy token fixed the problem.

This worked for me too, thank you!

GrantBirki commented 2 years ago

I got this issue after resetting my heroku login/password. I had to regenerate new tokens and it fixed the issue

Eddievin commented 2 years ago

Interestingly for me just regenerating the deploy token fixed the problem.

Freaking Genius! Thanks 😁

oemekaogala commented 2 years ago

Regenerating the API key helped!!! Thanks.

HenryCodeT commented 2 years ago

Error I received

image image

My file:

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install packages
        run: npm install
      - name: Build project
        run: npm run-script build
      - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: ${{secrets.HEROKU_APP_NAME}} #Must be unique in Heroku
          heroku_email: ${{secrets.HEROKU_EMAIL}}
          procfile: 'web: npm start'

You just need to configure the secrets on GitHub image You can get HEROKU_API_KEY from account settings on Heroku Account image

brunomcr commented 2 years ago

My solution:

Generate a new HEROKU_API_KEY

heroku auth:token

My file:

name: Push Container to Heroku

on:
  push:
    branches:
      - 'main'

jobs:
  heroku-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v3
      - name: Deploy to Heroku
        uses: akhileshns/heroku-deploy@v3.12.12
        with:
          heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
          heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
          heroku_email: ${{ secrets.HEROKU_EMAIL }}

  custom-deploy:
    needs: heroku-deploy
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Heroku login credentials
        run: |
          cat > ~/.netrc <<EOF
            machine api.heroku.com
              login $HEROKU_EMAIL
              password $HEROKU_API_KEY
            machine git.heroku.com
              login $HEROKU_EMAIL
              password $HEROKU_API_KEY
          EOF
        env:
          HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
          HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
      - name: Add Heroku remote
        run: heroku git:remote --app $HEROKU_APP_NAME
        env:
          HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
      - name: Push to Heroku
        run: git push heroku main:main
franciskinyuru commented 2 years ago

Error i am getting image

my file `name: Deploy-to-heruko

on: push: branches:

Have regenerated the api key severally.

olivierlacan commented 1 year ago

Updated HEROKU_API_KEY with the new value shown in https://dashboard.heroku.com/account in https://github.com/INSERT_USERNAME/INSERT_REPO_NAME/settings/secrets/actions solved this for me.

Heroku invalidated API keys in April 2022: https://blog.heroku.com/april-2022-incident-review

Your once valid API keys are now invalid and this error message is hiding that this is the actual problem.

Domodan commented 1 year ago

In my case, I had created my secrets under dependentbot, so I had to create the secrets under action and it worked successfully.