actions / heroku

GitHub Action for interacting with Heroku
MIT License
177 stars 62 forks source link

Git push to heroku #10

Open rickyhopkins opened 4 years ago

rickyhopkins commented 4 years ago

I am trying to deploy to heroku with github actions using actions/heroku@master. I am not using docker so the standard directions for the heroku action does not really apply to me.

My current flow is:

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: login
      uses: actions/heroku@master
      env:
        HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
      with:
        args: container:login
    - name: set remote
      uses: actions/heroku@master
      env:
        HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
      with:
        args: git:remote -a my-app
    - name: push
      run: git subtree push --prefix server heroku master

It seems to login just fine and it adds the remote but then it fails when I try to push to heroku with the following message:

fatal: could not read Username for 'https://git.heroku.com': No such device or address

Which seems strange because the heroku login command should be adding my credentials to the .netrc file.

deniscostadsc commented 4 years ago

Hi,

@rickyhopkins, I'm having same problem here. Did you work around this in a clever way?

rickyhopkins commented 4 years ago

Hey @deniscostadsc,

Nope, my project does not change too often so I have resorted to a manual deploy until I can get this working.

The only workaround that I found was here which suggests adding the Heroku remote manually with the API key injected in like so:

    - name: Add remote origin
      run: |
        git remote add heroku https://heroku:${{ secrets.HEROKU_API_KEY }}@git.heroku.com/${{ secrets.HEROKU_APP_NAME }}.git
    - name: Deploy to Heroku
      run: |
        git push heroku HEAD:master -f

I did not test this myself but I can't see why it wouldn't work it just feels like a bit of a hack to me.

Hope that helps.

karimsa commented 4 years ago

You don’t need the remote step so for my project, this is the solution I’m using:

  - name: Deploy to production
     run: |
       git push https://heroku:$HEROKU_API_KEY@git.heroku.com/<heroku-project>.git master
deniscostadsc commented 4 years ago

@karimsa,

I tried an approach similar to yours, but I keep getting errors. I even tried to put hardcode URL with secret API key (don't worry I already invalidated it :sunglasses:) and got same error bellow:

Run git push ***git.heroku.com/<heroku-project>.git master
  git push ***git.heroku.com/<heroku-project>.git master
  shell: /bin/bash -e {0}
error: src refspec master does not match any
error: failed to push some refs to '***git.heroku.com/<heroku-project>.git'
karimsa commented 4 years ago

Is the branch that ran the workflow master? If not, you can try changing master to HEAD:master in the above command.

deniscostadsc commented 4 years ago

After changing my code to this:

STAGING_GIT_URL=$(git remote get-url staging | sed 's/\/git/\/heroku:${{ secrets.HEROKU_API_KEY }}@git/')
git remote set-url staging $STAGING_GIT_URL
git push staging HEAD:master

I start to get this error:

Run STAGING_GIT_URL=$(git remote get-url staging | sed 's/\/git/\/heroku:***@git/')
  STAGING_GIT_URL=$(git remote get-url staging | sed 's/\/git/\/heroku:***@git/')
  git remote set-url staging $STAGING_GIT_URL
  git push staging HEAD:master
  shell: /bin/bash -e {0}
error: The destination you provided is not a full refname (i.e.,
starting with "refs/"). We tried to guess what you meant by:

- Looking for a ref that matches 'master' on the remote side.
- Checking if the <src> being pushed ('HEAD')
  is a ref in "refs/{heads,tags}/". If so we add a corresponding
  refs/{heads,tags}/ prefix on the remote side.

Neither worked, so we gave up. You must fully qualify the ref.
hint: The <src> part of the refspec is a commit object.
hint: Did you mean to create a new branch by pushing to
hint: 'HEAD:refs/heads/master'?
error: failed to push some refs to '***git.heroku.com/<heroku-project>.git'

I think my error is more related to git that Heroku actually.

Thanx for the help so far.

deniscostadsc commented 4 years ago

Just for the sake of history, my problem seems to be caused by the state of detached of the repo on build. I'm confused why you didn't have this problem.

deniscostadsc commented 4 years ago

Yes, it was the detached state. I used a semi-hacky solution of creating a branch before pushing to github.

spk commented 4 years ago

o/ for other people looking for an example with Heroku git push deploy on pull request with a comment /deploy https://gist.github.com/spk/7be27d8f0f9fa0264fa24417ec40c742 secrets needs to be provided and also the HEROKU_APP_NAME changed

rohitkrishna094 commented 4 years ago

@deniscostadsc do you have a sample yaml file for that hacky solution that you mentioned?