ad-m / github-push-action

GitHub actions to push back to repository eg. updated code
MIT License
1.21k stars 230 forks source link

Push issue #44

Open sabuto opened 4 years ago

sabuto commented 4 years ago

Ok, I may be being really dumb here but

image

I get permission denied

my workflow file:

name: CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

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

    - uses: actions/checkout@v2
      name: Secondary Checkout
      with:
        repository: sabuto/bot-test2
        path: bot-test2

    - name: move file to other repo
      run: \cp -Rv .github/sabubot.yml bot-test2/.github/sabubot.yml

    - name: commit to local
      run: |
        cd bot-test2
        git config --local user.email "robe_dunne@hotmail.com"
        git config --local user.name "sabuto"
        git add .
        git commit -m "Add changes"

    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_PSA }}
        repository: sabuto/bot-test2

I have the psa key setup in the repo that is triggering the workflow image

which is a personal access token with all rights.

robot-o commented 4 years ago

i'm having the same issue

magodo commented 4 years ago

For anyone suffering this issue, this might be the actions/checkout@v2 to blame. The default setting for checkout cannot work with push. To make them work together, you need to specify following parameters for checkout:

persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
sabuto commented 4 years ago

@magodo Thanks for this, I am now getting

Started: bash /home/runner/work/_actions/ad-m/github-push-action/master/start.sh
 ! [rejected]        HEAD -> master (fetch first)
Push to branch master
error: failed to push some refs to '***github.com/sabuto/bot-test2.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.

This makes no sense as i have pulled the latest version when i run the workflow, any ideas?

ad-m commented 4 years ago

@Sabuto , add force: true, but you should understand what that message mean in Git due risk of data loss.

magodo commented 4 years ago

Are you sure you set the fetch-depth to 0? I have this issue because of that.

sabuto commented 4 years ago

Thanks for this guys! and thanks for the fast responses :) i am happy for this to be closed as it works for me but will let you decide as the other haven't commented.

organizejs commented 4 years ago

@magodo I am unable to set persist-credentials and fetch-depth as parameters under checkout.

I'm setting it like so:

    - uses: actions/checkout@master
      persist-credentials: false
      fetch-depth: 0

i get this error:

- Your workflow file was invalid: The pipeline is not valid. .github/workflows/update.yml (Line: 17, Col: 7): Unexpected value 'persist-credentials',.github/workflows/update.yml (Line: 18, Col: 7): Unexpected value 'fetch-depth'
ad-m commented 4 years ago

@organizejs , missing with. Let's try:

    - uses: actions/checkout@master
      with:
         persist-credentials: false
         fetch-depth: 0
StefMa commented 4 years ago

Thanks guys, that worked for me. But I get (together with my own commit) a second commit which is something like

Merge abc1743 into cde9725

Again, it seems that checkout/v2 does this. Another solution is to simple declare the branch you want to checkout:

    - uses: actions/checkout@master
      with:
         ref: ${{ github.event.pull_request.head.ref }}
kenorb commented 4 years ago

But I get (together with my own commit) a second commit which is something like

Merge abc1743 into cde9725

Again, it seems that checkout/v2 does this.

I've got the same issue with merge commit. Related: #20.

kenorb commented 4 years ago

Related: