stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
2.06k stars 230 forks source link

Invalid reference, error 128 #278

Closed lukepighetti closed 4 months ago

lukepighetti commented 1 year ago

git-auto-commit Version

v4

Machine Type

Ubuntu (eg. ubuntu-latest)

Bug description

A contributor has a fork branch called contributor:card and is trying to merge it in to lukepighetti:main

It appears that git-auto-commit is trying to commit to lukepighetti:card instead of contributor:card

jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: arduino/setup-task@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
      - uses: subosito/flutter-action@v2
        with:
          channel: stable
      - run: task gen
      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Update generated files
          file_pattern: "*.g.dart"

When new generated files are found and this action is triggered to commit the new files, I get the following error

Started: bash /home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/entrypoint.sh
[20](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:21)
INPUT_REPOSITORY value: .
[21](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:22)
INPUT_STATUS_OPTIONS: 
[22](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:23)
INPUT_FILE_PATTERN: *.g.dart
[23](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:24)
INPUT_BRANCH value: card
[24](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:25)
From https://github.com/lukepighetti/mastodon_dart
[25](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:26)
 * [new branch]      lukepighetti/actions-task-2 -> origin/lukepighetti/actions-task-2
[26](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:27)
 * [new branch]      lukepighetti/cleanup-nov-15 -> origin/lukepighetti/cleanup-nov-15
[27](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:28)
 * [new branch]      lukepighetti/null-safety -> origin/lukepighetti/null-safety
[28](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:29)
 * [new branch]      main       -> origin/main
[29](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:30)
fatal: invalid reference: card
[30](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:31)
Error: Invalid status code: 128
[31](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:32)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
[32](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:33)
    at ChildProcess.emit (node:events:390:28)
[33](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:34)
    at maybeClose (node:internal/child_process:1064:16)
[34](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:35)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
[35](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:36)
  code: 128
[36](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:37)
}
[37](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:38)
Error: Invalid status code: 128
[38](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:39)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
[39](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:40)
    at ChildProcess.emit (node:events:390:28)
[40](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:41)
    at maybeClose (node:internal/child_process:1064:16)
[41](https://github.com/lukepighetti/mastodon_dart/actions/runs/3846888265/jobs/6552794001#step:6:42)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
stefanzweifel commented 1 year ago

I assume it's this workflow file, right? https://github.com/lukepighetti/mastodon_dart/blob/82b76b990435f9b3d8b69ec1778c686adedbc105/.github/workflows/main.yml#L4

You probably need to switch to listen to the pull_request_target event. Pushing commits in forks is a bit of a hassle. We added a section to the README a while ago about this: https://github.com/stefanzweifel/git-auto-commit-action#advanced-uses

I'm not 100% sure, if you can keep triggers for both pull_request_target and pull_request in your workflow. (I have an open task to check if this behaviour still works with forks; just haven't had the time yet to test it.)


We should probably also update the example in the README, to make it clearer how the example works with forks.

deitch commented 1 year ago

Ah, just came across this. Good thing I looked in issues first.

So the net of it is that it kind of is doable, but is hard to config, and might not work at all depending on the setup of the fork? And all due to GitHub limitations?

stefanzweifel commented 1 year ago

@deitch Yeah, this sums it up pretty nicely. Technically kinda doable but you run into road blocks constantly, due to how GitHub wants GitHub Actions to work for forks.

deitch commented 1 year ago

That really is a pity. I can see some real patterns where you might want generated stuff as part of your repo (i.e. committed in), but not have the user do it. This is like compilation, but unlike normal compiled binaries (where it doesn't make sense), here it does. My current use case is language bindings generated from protobufs, but I can see transpiled code, graph images, lots of other cases.

stefanzweifel commented 1 year ago

@deitch That's exactly the use case why I've created this project; and it does work as you described.

Problems sometimes appear when people use this Action in workflows that should work for both Maintainers and Forks in the exact same way.

In the past we had many discussions/issues around forks. Almost all issues have been resolved by changing the workflow or repository settings. I'm liking a few here; maybe they help you or others coming across this thread.

I also know of a couple of bigger GitHub organisations that use this action to fix code style issues in their open source projects.

For example @spatie is using the Action in a workflow that just listens to the push event. In a pull request from May the action successfully pushed a commit to the fork (commit sha 4e853b5)

Or the @laravel org uses this workflow in all repositories to fix code style uses. In their repositories they also just listen to the push event (link).

Both orgs receive a lot of community contributions for forks. So this Action seems to work for them. 🤔


But I have to be honest: I haven't invested much time into this project in the last few weeks or even months. I just saw that the project is already being used by 60,000 repositories; my time investment doesn't give the usage justice.

In the next few weeks or months I would like to comb all issues and discussions and extract all relevant information and put that into the documentation and close/lock discussions with a link to the right place in the documentation.

deitch commented 1 year ago

I just saw that the project is already being used by 60,000 repositories; my time investment doesn't give the usage justice.

I have that with some OSS stuff over the years. It is hard to find time to maintain them, unless you can build something commercial on top of it.

stefanzweifel commented 4 months ago

I'm closing this issue.

Usage of this action in forks has been documented in the README. Thank you all for the feedback you've given in this thread.