cpina/github-action-push-to-another-repository

remote: fatal: did not receive expected object on Pull request

adnanmayo opened this issue · 7 comments

The documentation might have information on what you could do to fix the problem.

nothing to commit, working tree clean
[+] git diff-index:
HEAD is now at f3c871d Merge pull request #137 from codeupscale/adnanmayo-patch-1
[+] Pushing git commit
error: Could not read a324db98bb4b38eec087243ba042fdfd87cc0fde
remote: fatal: did not receive expected object 624df496fd4e79b58305f0fb444526231a74353b
error: remote unpack failed: index-pack failed
To github.com:adnanmayo/autoupscale-frontend-nextjs.git
! [remote rejected] develop -> develop (failed)

Full output might contain useful information including the git command, git output and settings used. It also helps to search for the problem later on.

URL to the execution

This action works fine when we push directly to a certain branch but I am receiving the above error when there is a pull request.

cpina commented

Is it a public repo? Do you have a link to the action output? (it's easier to see some more variables and information on the origin and destination checking the commits). Thanks!

[+] Git version
git version 2.40.1
[+] Enable git lfs
Git LFS initialized.
[+] Cloning destination git repository autoupscale-frontend-nextjs
Cloning into '/tmp/tmp.DOGdNn'...
total 108
drwx------   18 root     root          4096 Aug 16 09:18 .
drwxrwxrwt    1 root     root          4096 Aug 16 09:18 ..
-rw-r--r--    1 root     root            98 Aug 16 09:18 .env.example
-rw-r--r--    1 root     root            40 Aug 16 09:18 .eslintrc.json
drwxr-xr-x    8 root     root          4096 Aug 16 09:18 .git
drwxr-xr-x    3 root     root          4096 Aug 16 09:18 .github
-rw-r--r--    1 root     root           4[42](https://github.com/codeupscale/autoupscale-frontend-nextjs/actions/runs/5876971178/job/15936159342#step:5:43) Aug 16 09:18 .gitignore
-rw-r--r--    1 root     root          1804 Aug 16 09:18 README.md
drwxr-xr-x   31 root     root          4096 Aug 16 09:18 components
drwxr-xr-x    2 root     root          4096 Aug 16 09:18 config
drwxr-xr-x    2 root     root          4096 Aug 16 09:18 context
drwxr-xr-x    5 root     root          4096 Aug 16 09:18 enums
drwxr-xr-x    2 root     root          4096 Aug 16 09:18 hooks
drwxr-xr-x    2 root     root          4096 Aug 16 09:18 lang
drwxr-xr-x    7 root     root          4096 Aug 16 09:18 models
-rw-r--r--    1 root     root           370 Aug 16 09:18 next.config.js
-rw-r--r--    1 root     root          2054 Aug 16 09:18 package.json
drwxr-xr-x   11 root     root          4096 Aug 16 09:18 pages
drwxr-xr-x    2 root     root          4096 Aug 16 09:18 permissions
-rw-r--r--    1 root     root            82 Aug 16 09:18 postcss.config.js
drwxr-xr-x    4 root     root          4096 Aug 16 09:18 public
drwxr-xr-x    2 root     root          4096 Aug 16 09:18 routes
drwxr-xr-x    2 root     root          4096 Aug 16 09:18 styles
-rw-r--r--    1 root     root           750 Aug 16 09:18 tailwind.config.js
-rw-r--r--    1 root     root           779 Aug 16 09:18 tsconfig.json
drwxr-xr-x   11 root     root          4096 Aug 16 09:18 types
drwxr-xr-x    4 root     root          4096 Aug 16 09:18 utils
[+] Deleting /tmp/tmp.DOGdNn//
[+] Creating (now empty) /tmp/tmp.DOGdNn//
[+] Listing Current Directory Location
total 108
drwxr-xr-x   18 1001     ntp           4096 Aug 16 09:18 .
drwxr-xr-x    6 root     root          4096 Aug 16 09:18 ..
-rw-r--r--    1 1001     ntp             98 Aug 16 09:18 .env.example
-rw-r--r--    1 1001     ntp             40 Aug 16 09:18 .eslintrc.json
drwxr-xr-x    8 1001     ntp           4096 Aug 16 09:18 .git
drwxr-xr-x    3 1001     ntp           4096 Aug 16 09:18 .github
-rw-r--r--    1 1001     ntp            [44](https://github.com/codeupscale/autoupscale-frontend-nextjs/actions/runs/5876971178/job/15936159342#step:5:45)2 Aug 16 09:18 .gitignore
-rw-r--r--    1 1001     ntp           1804 Aug 16 09:18 README.md
drwxr-xr-x   32 1001     ntp           4096 Aug 16 09:18 components
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 config
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 context
drwxr-xr-x    5 1001     ntp           4096 Aug 16 09:18 enums
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 hooks
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 lang
drwxr-xr-x    7 1001     ntp           4096 Aug 16 09:18 models
-rw-r--r--    1 1001     ntp            370 Aug 16 09:18 next.config.js
-rw-r--r--    1 1001     ntp           2054 Aug 16 09:18 package.json
drwxr-xr-x   11 1001     ntp           4096 Aug 16 09:18 pages
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 permissions
-rw-r--r--    1 1001     ntp             82 Aug 16 09:18 postcss.config.js
drwxr-xr-x    4 1001     ntp           4096 Aug 16 09:18 public
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 routes
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 styles
-rw-r--r--    1 1001     ntp            750 Aug 16 09:18 tailwind.config.js
-rw-r--r--    1 1001     ntp            779 Aug 16 09:18 tsconfig.json
drwxr-xr-x   11 1001     ntp           4096 Aug 16 09:18 types
drwxr-xr-x    4 1001     ntp           4096 Aug 16 09:18 utils
[+] Listing root Location
total 84
drwxr-xr-x    1 root     root          4096 Aug 16 09:18 .
drwxr-xr-x    1 root     root          4096 Aug 16 09:18 ..
-rwxr-xr-x    1 root     root             0 Aug 16 09:18 .dockerenv
drwxr-xr-x    2 root     root          4096 Aug  7 13:09 bin
drwxr-xr-x    5 root     root           340 Aug 16 09:18 dev
-rwxr-xr-x    1 root     root          6116 Aug 10 11:25 entrypoint.sh
drwxr-xr-x    1 root     root          4096 Aug 16 09:18 etc
drwxr-xr-x    6 root     root          4096 Aug 16 09:18 github
drwxr-xr-x    2 root     root          4096 Aug  7 13:09 home
drwxr-xr-x    1 root     root          4096 Aug  7 13:09 lib
drwxr-xr-x    5 root     root          4096 Aug  7 13:09 media
drwxr-xr-x    2 root     root          4096 Aug  7 13:09 mnt
drwxr-xr-x    2 root     root          4096 Aug  7 13:09 opt
dr-xr-xr-x  206 root     root             0 Aug 16 09:18 proc
drwx------    2 root     root          4096 Aug  7 13:09 root
drwxr-xr-x    1 root     root          4096 Aug 16 09:18 run
drwxr-xr-x    2 root     root          4096 Aug  7 13:09 sbin
drwxr-xr-x    2 root     root          4096 Aug  7 13:09 srv
dr-xr-xr-x   12 root     root             0 Aug 16 09:18 sys
drwxrwxrwt    1 root     root          4096 Aug 16 09:18 tmp
drwxr-xr-x    1 root     root          4096 Aug 16 09:18 usr
drwxr-xr-x    1 root     root          4096 Aug 16 09:18 var
[+] List contents of ./
README.md
components
config
context
enums
hooks
lang
models
next.config.js
package.json
pages
permissions
postcss.config.js
public
routes
styles
tailwind.config.js
tsconfig.json
types
utils
[+] Checking if local ./ exist
[+] Copying contents of source repository folder ./ to folder  in git repo autoupscale-frontend-nextjs
[+] Files that will be pushed
total 108
drwxr-xr-x   18 1001     ntp           4096 Aug 16 09:18 .
drwxrwxrwt    1 root     root          4096 Aug 16 09:18 ..
-rw-r--r--    1 1001     ntp             98 Aug 16 09:18 .env.example
-rw-r--r--    1 1001     ntp             40 Aug 16 09:18 .eslintrc.json
drwxr-xr-x    8 1001     ntp           4096 Aug 16 09:18 .git
drwxr-xr-x    3 1001     ntp           4096 Aug 16 09:18 .github
-rw-r--r--    1 1001     ntp            442 Aug 16 09:18 .gitignore
-rw-r--r--    1 1001     ntp           1804 Aug 16 09:18 README.md
drwxr-xr-x   32 1001     ntp           4096 Aug 16 09:18 components
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 config
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 context
drwxr-xr-x    5 1001     ntp           4096 Aug 16 09:18 enums
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 hooks
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 lang
drwxr-xr-x    7 1001     ntp           4096 Aug 16 09:18 models
-rw-r--r--    1 1001     ntp            370 Aug 16 09:18 next.config.js
-rw-r--r--    1 1001     ntp           2054 Aug 16 09:18 package.json
drwxr-xr-x   11 1001     ntp           4096 Aug 16 09:18 pages
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 permissions
-rw-r--r--    1 1001     ntp             82 Aug 16 09:18 postcss.config.js
drwxr-xr-x    4 1001     ntp           4096 Aug 16 09:18 public
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 routes
drwxr-xr-x    2 1001     ntp           4096 Aug 16 09:18 styles
-rw-r--r--    1 1001     ntp            750 Aug 16 09:18 tailwind.config.js
-rw-r--r--    1 1001     ntp            779 Aug 16 09:18 tsconfig.json
drwxr-xr-x   11 1001     ntp           4096 Aug 16 09:18 types
drwxr-xr-x    4 1001     ntp           4096 Aug 16 09:18 utils
[+] Set directory is safe (/tmp/tmp.DOGdNn)
[+] Switch to the TARGET_BRANCH
fatal: a branch named 'develop' already exists
[+] Adding git commit
[+] git status:
On branch develop
Your branch is up to date with 'origin/develop'.

nothing to commit, working tree clean
[+] git diff-index:
HEAD is now at bcbe689 Added mac m1 platform in docker yamk
[+] Pushing git commit
error: Could not read 50fd0b005[48](https://github.com/codeupscale/autoupscale-frontend-nextjs/actions/runs/5876971178/job/15936159342#step:5:49)0b669d020dd2783389d[51](https://github.com/codeupscale/autoupscale-frontend-nextjs/actions/runs/5876971178/job/15936159342#step:5:52)1a4f7231
remote: fatal: did not receive expected object 7eafb3[57](https://github.com/codeupscale/autoupscale-frontend-nextjs/actions/runs/5876971178/job/15936159342#step:5:58)68626e8ddbf3b3be0f2972d57b1bf[60](https://github.com/codeupscale/autoupscale-frontend-nextjs/actions/runs/5876971178/job/15936159342#step:5:61)c        
error: remote unpack failed: index-pack failed
To github.com:adnanmayo/autoupscale-frontend-nextjs.git
 ! [remote rejected] develop -> develop (failed)
error: failed to push some refs to 'github.com:adnanmayo/xxxx-frontend-nextjs.git'

This is a private repository

cpina commented

I've found at least one place (https://github.com/orgs/Homebrew/discussions/666#discussioncomment-1228144) that mentions that it happened when using https protocol instead of using ssh.

In the docs:
https://cpina.github.io/push-to-another-repository-docs/setup.html#setup-using-ssh-deploy-keys

Would you be able to try setting it up with the SSH deploy keys? (https://cpina.github.io/push-to-another-repository-docs/setup-using-ssh-deploy-keys.html#setup-ssh-deploy-keys)

It would be good to know if it still fails...

@cpina

I have set it up using ssh keys and it is working fine when we push the code directly to a develop branch. it only happens when we merge a PR on github.

cpina commented

I have set it up using ssh keys and it is working fine when we push the code directly to a develop branch. it only happens when we merge a PR on github.

Before I give too many non-relevant details, do you mean that the action works fine when you push into develop in the source repository and then the action pushes it into the target repository? but does not work fine if a PR is involved?

Or that it works fine if you push from your computer to the target repository?

What I want to suggest... could you try reproducing locally the error reading the action and following what it does (https://github.com/cpina/github-action-push-to-another-repository/blob/main/entrypoint.sh). I can give better directions if needed.

do you mean that the action works fine when you push into develop in the source repository and then the action pushes it into the target repository? but does not work fine if a PR is involved?

Yess, it always works fine when we push the code directly to any branch in the source repository. Actions runs successfully when we push to the branch but it does not work when PR is involved.

I am using https://github.com/nektos/act to run GitHub actions locally which runs fine.

I also tried to fork the repo and tried to push the code forcefully from the GitHub actions the error still persists.
This error could be a result of cloning only the last commit. When we copy the dir to the target dir git commit does not exist in the target repository which returns this error.

cpina commented

My only idea at the moment is that, since you already did:

I also tried to fork the repo and tried to push the code forcefully from the GitHub actions the error still persists.

Perhaps you can add "set -x" at the beginning of entrypoint.sh to see the exact commands executed. And then try to execute them by hand and see if it fails / debug it checking step by step / modifying?

Perhaps try removing the "--depth 1" and see if this is causing the problem? (there were some problems in the past in git but I thought that are all solved...)

entrypoint.sh is moving .git folder but I don't see how this would cause an issue only for you.

Is the remote repository changed remotely but another process at the same time as the action is running? Or, can you think what's happening when a PR is involved that is not happening when a PR is not involved?

Sorry for the general ideas and no concrete steps / fixes!