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
1.98k stars 227 forks source link

error: pathspec '...' did not match any file(s) known to git in Forks #117

Closed VaibhavSaini19 closed 3 years ago

VaibhavSaini19 commented 3 years ago

Version of the Action v4

Describe the bug The repo uses this action to automatically commit workflow changes back to the repo. But when a PR is made from a branch of a fork (with actions enabled), the actions fails with

...
INPUT_BRANCH value: template-issue
From https://github.com/s-katte/React-Code-Pen
 * [new branch]      introduce-collaboration -> origin/introduce-collaboration
 * [new branch]      update-contributing     -> origin/update-contributing
 * [new branch]      update-readme           -> origin/update-readme
error: pathspec 'template-issue' did not match any file(s) known to git
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  code: 1
}
Error: Invalid status code: 1
    at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

I went through this thread which states that this (or similar) issue was fixed in v2, but I am still having this issue

To Reproduce Fork the repo, commit changes in a new branch, create a PR

Expected behavior The changes to be successfully committed in the PR branch which can be merged

I think git is unable to find the branch?

Screenshots

Failed workflow: https://github.com/s-katte/React-Code-Pen/pull/27/checks?check_run_id=1267689707

Used Workflow

name: Format
on:
    pull_request_target:
        branches:
            - master
jobs:
    format:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v2
            - uses: actions/setup-node@v1
              with:
                  node-version: "12.x"
            - name: Format
              run: |
                  npm ci
                  npm run format
            - name: Commit changes
              uses: stefanzweifel/git-auto-commit-action@v4
              with:
                  commit_message: Apply formatting changes
                  branch: ${{ github.head_ref }}

Additional context We even tried it without the branch option, but it still failed

stefanzweifel commented 3 years ago

Thanks for reporting!

I've now invested like +2 hours investigating this. In short: I have no idea why pull_request_target doesn't work as advertised. However, I could fix it by just using push in th workflow.

What I've done

Through a secondary Account I've created a fork of my test repository and made some changes: https://github.com/wnxtrash/git-auto-commit-action-demo-app/tree/fork/patch-2

The resulting PR never successfully runs the git-auto-commit Action with the pull_request or pull_request_target triggers: https://github.com/stefanzweifel/git-auto-commit-action-demo-app/pull/21

The Action isn't even triggered in the fork. Eventhough the pull_request_target is especially designed to run in an Action in the forked repository https://github.com/wnxtrash/git-auto-commit-action-demo-app/actions?query=workflow%3A%22Format+PHP%22

In a last attempt I just added the push-trigger. This worked and the workflow was run as expected on the fork.


The README already states that running this Action in forks is quite complicated.

As you can see, your contributors have to go through hoops to make this work. For Workflows which runter linters and fixers (like the example above) we recommend running them when a push happens on the master-branch.

I will update the README in 2 ways:


Sorry if I vent here. It's not targeted against you. 🙂

It's just very frustrating if something that worked a month ago no longer works as expected. It also feels to me that the pull_request_target-trigger is not really that stable. I personally think it's quite complicated to understand, when to use it and especially how to use it.

VaibhavSaini19 commented 3 years ago

Adding push to the trigger events did the job, thank you so much for your time.

And sorry for the inconvenience caused. Even I was frustrated with all these errors. Anyway, thanks again

stefanzweifel commented 3 years ago

@VaibhavSaini19 No worries! Thanks for reporting. Only thanks to issues and discussions we can make this Action better :D

HarshitaInfoblox commented 3 years ago

@stefanzweifel I see the exact same issue. For some reasons, adding commits after the PR changes are pushed to master is not an option. I need to update the same PR (from the fork) with additional commits. In short, is there a fix to this issue other than changing trigger to push ?

Note that, I have gone through the section in README on this and have-

stefanzweifel commented 3 years ago

@HarshitaInfoblox I don't think there is another option. My example project mentioned in https://github.com/stefanzweifel/git-auto-commit-action/issues/117#issuecomment-710822378 only worked after adding a push listener that wasn't scoped to a branch (https://github.com/stefanzweifel/git-auto-commit-action-demo-app/pull/21/commits/421eb666b88d8a07b0357c42eb2ace50914febaf).

You mention "Run workflows from pull requests". So I assume you're using the Action in private repositories with private forks? I couldn't test the Action in this environment so far. If you find a solution, feel free to update a PR to update the docs.