ad-m / github-push-action

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

Push another repo error #151

Closed totalo closed 1 year ago

totalo commented 1 year ago
image
totalo commented 1 year ago

I have my personal token configured.

totalo commented 1 year ago
image
ZPascal commented 1 year ago
image

You've set up the SSH mode with the param ssh: true. So you've also forwarded a deploy key or an ssh key?

ZPascal commented 1 year ago
image

if you want to use your personal token, it's necessary to owerwrite the default user. I've described it here.

totalo commented 1 year ago
image

if you want to use your personal token, it's necessary to owerwrite the default user. I've described it here.

I think it's still an implementation issue. I used another action component and it worked.

totalo commented 1 year ago
image
ZPascal commented 1 year ago

I think it's still an implementation issue. I used another action component and it worked.

I can implement a solution to overwrite the default user specified by GITHUB if needed. For me personally, it's not a bug it's an enhancement.

image

For my understanding the user action here overwrite this user.

@totalo Did overwriting the user helped you?

totalo commented 1 year ago

Thank you for your patience, but I understand it is not, I tried to configure my own account and use tokens, but also failed. Using another action component using my own account or github-action[bot] worked. Or based on our component, how should I configure if I want to push another repository?

The config:

image

The error:

image

Another point is that configuring users via git config doesn't seem to work for components.

ZPascal commented 1 year ago

Thank you for your patience, but I understand it is not, I tried to configure my own account and use tokens, but also failed.

No problem. Let's fix your case :+1:

Using another action component using my own account or github-action[bot] worked.

If you are using the github-action[bot] user, you used the default GITHUB_TOKEN, right?

Or based on our component, how should I configure if I want to push another repository? I think the corresponding configuration below should work for my understanding. I'll follow this case up and start to build a reproducible case on my side.

Another point is that configuring users via git config doesn't seem to work for components.

As I already mentioned, we're not using the corresponding specified git config user. We're using the GITHUB_ACTOR environment variable, specified by the action system, that user represents the corresponding user who initiated the GitHub Action.

I think it's maybe necessary to overwrite this environment variable. I've placed an untested example below.

 - name: Push changes
   uses: ad-m/github-push-action@master
   with:
     github_token: <token>
     branch: master
     repository: <repository>
     force: true
     github_url: <url>
     directory: .
   env:
      GITHUB_ACTOR: <user user>
totalo commented 1 year ago

Thank you for your patience, but I understand it is not, I tried to configure my own account and use tokens, but also failed.

No problem. Let's fix your case 👍

Using another action component using my own account or github-action[bot] worked.

If you are using the github-action[bot] user, you used the default GITHUB_TOKEN, right?

Yes, the token is the same. but failed.

Or based on our component, how should I configure if I want to push another repository? I think the corresponding configuration below should work for my understanding. I'll follow this case up and start to build a reproducible case on my side.

Another point is that configuring users via git config doesn't seem to work for components.

As I already mentioned, we're not using the corresponding specified git config user. We're using the GITHUB_ACTOR environment variable, specified by the action system, that user represents the corresponding user who initiated the GitHub Action.

I think it's maybe necessary to overwrite this environment variable. I've placed an untested example below.

 - name: Push changes
   uses: ad-m/github-push-action@master
   with:
     github_token: <token>
     branch: master
     repository: <repository>
     force: true
     github_url: <url>
     directory: .
   env:
      GITHUB_ACTOR: <user user>

Thank you, i has try it, but it does not work.

image
ZPascal commented 1 year ago

I've reproduced the issue on my side and added a few debug variables inside a special adapted version. To further analyze the issue, I've checked the functionality and at the end I've found an issue inside the documentation of the GitHub Action.

I think that could be also your case, it's necessary to use the same token as inside Push Action inside the checkout otherwise, the action use at the end the GitHub service user specified by the checkout functionality.

Could you please execute your case again and adapt beforehand the checkout action like the following example? Thank you.

      - uses: actions/checkout@v3
        with:
          ...
          token: ${{ secrets.TOKEN }}

As a follow-up, I'll adjust the existing PR, adapt the documentation and a bit the code.

totalo commented 1 year ago

I've reproduced the issue on my side and added a few debug variables inside a special adapted version. To further analyze the issue, I've checked the functionality and at the end I've found an issue inside the documentation of the GitHub Action.

I think that could be also your case, it's necessary to use the same token as inside Push Action inside the checkout otherwise, the action use at the end the GitHub service user specified by the checkout functionality.

Could you please execute your case again and adapt beforehand the checkout action like the following example? Thank you.

      - uses: actions/checkout@v3
        with:
          ...
          token: ${{ secrets.TOKEN }}

As a follow-up, I'll adjust the existing PR, adapt the documentation and a bit the code.

Thank you, and It seems that the permission verification has passed, but there seems to be something wrong with the steps in the execution of push. It may need to clone the local execution machine first, overwrite the local generated file, and then add it to git for push.

image
ZPascal commented 1 year ago

I've tested it with a force push and it worked as expected. If this, is not possible for your case, I recommend cloning the other repository beforehand and move the file to do not break the history. If you need for such a case an example, feel free to notify me.

totalo commented 1 year ago

I've tested it with a force push and it worked as expected. If this, is not possible for your case, I recommend cloning the other repository beforehand and move the file to do not break the history. If you need for such a case an example, feel free to notify me.

i has tested it.but aslo failed.

image
ZPascal commented 1 year ago

Can you please share the corresponding error message? I want to reproduce the case.

totalo commented 1 year ago

Can you please share the corresponding error message? I want to reproduce the case.

To https://github.com/totalo/totalo.github.io.git
 ! [remote rejected] HEAD -> master (shallow update not allowed)
error: failed to push some refs to 'https://github.com/totalo/totalo.github.io.git'
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 (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:[16](https://github.com/totalo/website/actions/runs/4160303292/jobs/7197167984#step:6:17))
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302: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 (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
ZPascal commented 1 year ago

The interesting fact is the following sentence: shallow update not allowed. Do you have used thefetch-depth: 0 parameter inside the checkout action, like the following example? I think that's necessary for your corresponding case.

- uses: actions/checkout@v3
  with:
    ref: ${{ github.head_ref }}
    fetch-depth: 0
    token: ${{ secrets.PAT_TOKEN }}
totalo commented 1 year ago

The interesting fact is the following sentence: shallow update not allowed. Do you have used thefetch-depth: 0 parameter inside the checkout action, like the following example? I think that's necessary for your corresponding case.

- uses: actions/checkout@v3
  with:
    ref: ${{ github.head_ref }}
    fetch-depth: 0
    token: ${{ secrets.PAT_TOKEN }}

Thank you.It worked, but it seemed like the directory configuration wasn't working. It was pushing my source code up instead of the generated files.

ZPascal commented 1 year ago

@totalo Okay, is the corresponding added configuration here still right and was it the expected result? At the end, the action only switches the directory and the git add is performed by yourselves.

totalo commented 1 year ago

@totalo Okay, is the corresponding added configuration here still right and was it the expected result? At the end, the action only switches the directory and the git add is performed by yourselves.

@ZPascal , Thank you. I'm sorry for the late reply. I didn't do git add on the new configuration. And finally just switch directories, right? There's no git add, did the component add it automatically for me.

ZPascal commented 1 year ago

@totalo That's right. The action only switches the directory and executes the push command inside this folder. It's necessary that you beforehand add your changes to git.

totalo commented 1 year ago

@totalo That's right. The action only switches the directory and executes the push command inside this folder. It's necessary that you beforehand add your changes to git.

Ok, I see. Thank you for your patience.