Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
VaibhavSaini19 opened this issue Oct 17, 2020 · 5 comments
Closed

Comments

@VaibhavSaini19
Copy link

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 stefanzweifel changed the title error: pathspec '...' did not match any file(s) known to git error: pathspec '...' did not match any file(s) known to git in Forks Oct 17, 2020
@stefanzweifel
Copy link
Owner

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:
stefanzweifel/git-auto-commit-action-demo-app#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:

  • Add a big bold warning before the "use in fork" section is advanced usage and should be used on it's own risk.
  • Updating the example to use the push-trigger

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
Copy link
Author

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
Copy link
Owner

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

@HarshitaInfoblox
Copy link

HarshitaInfoblox commented May 24, 2021

@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-

  • used pull_request_target trigger.
  • Enabled github actions on forked repository.
  • Enabled "Run workflows from pull requests" in my repository (where PR is created) settings.

@stefanzweifel
Copy link
Owner

@HarshitaInfoblox I don't think there is another option. My example project mentioned in #117 (comment) only worked after adding a push listener that wasn't scoped to a branch (stefanzweifel/git-auto-commit-action-demo-app@421eb66).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants