davelosert/vitest-coverage-report-action

Coverage report from forked Repositories

Closed this issue · 6 comments

When trying to use this action for a repository that allows contributions from forks, this action fails to append the (successfully generated) report to the Pull Request, understandably due to missing permissions even when those are given within the config of the PR.

An idea would be to allow a configuration option which enables writing the report from outside of the context of a PR. This way the writing of the report could be done within a different context and the necessary permissions could be given. That solution worked for other tests apparently: csaf-poc/csaf_webview#2

Hi @JanHoefelmeyer , sorry for the late response here, the last weeks were quite busy ;)

So this is really an actions security feature which will be hard to fix from this action in itself.

However, you could theoretically achieve this already by basically following this example from the GitHub Docs for workflow_run actions in that you have two workflows:

  1. test.yml running on pull_request, executing the tests and then uploading the coverage-summary.json and the coverage-final.json as artifacts
  2. coverage.yml running on workflow_run with the first workflow as trigger, and then downloading the two reports

I think this is the same solution as you provided in the example.
I will try to test this within the next days and if it works, add it to the documentation.

If you prefer to do it yourself and want to put up a pull-request, I'll be more than happy to accept it! 🙂

Okay so I just tried this out and realized I actually do have to alter this action to allow an option to pass the Pull-Request-Number in order to be able to comment it, as this is not in the same context as when the action is triggered by pull_request.

I'll see if I can get something working soon.

@JanHoefelmeyer: I just merged a working solution and will release this in a bit (you'll see another comment here once released).

I had to jump through some hoops, though as the pull_request_number is not easily retrievable from a pull request coming from a fork.

You can read more about how to make it work and how I solved it in the new Readme.md Section: Working with pull requests from forks

This was now released in v2.2.0.

Let me know if it works for you! 👍

Yes, this worked flawlessly. Thank you very much!