rubyatscale / danger-packwerk

Danger plugin for packwerk
MIT License
22 stars 5 forks source link

Configuration for applications that are not in the root of the repo #39

Closed mbutsko closed 8 months ago

mbutsko commented 1 year ago

We are attempting to add todo's to an application that lives within a subfolder (in our example, 'server') of the repository, and we get the following error:

Invalid `Dangerfile` file: No such file or directory @ rb_sysopen - server/domains/admin_workflow/package_todo.yml

Would it be much trouble to add a an option to indicate that the application root should be chopped off of the path to the todos?

Related issue in danger itself: https://github.com/danger/danger/issues/1177#issuecomment-1030685400

alexevanczuk commented 1 year ago

Hi @mbutsko thanks for opening the issue.

Could you share the full stack trace of the error?

Is the issue here that you are running Dangerfile from the root, but your application lives within a subdirectory of that root? Is the issue in danger itself resolved for you or also an issue?

Thank you! I hope I can help.

jarredhawkins commented 1 year ago

I believe I am running into a similar issue here (although we run in a monorepo, which might be a little different from what @mbutsko is describing). Unfortunately I can't share a stack trace since it is a silent failure, but I managed to pinpoint where I think this is happening:

https://github.com/rubyatscale/danger-packwerk/blob/main/lib/danger-packwerk/danger_packwerk.rb#L72

On these specific lines, DangerPackwerk derives the changed files from the git changelog.

Using our monorepo example, a changed file from the perspective of git would be something like server/site/packs/domain/file.rb. It seems danger-packwerk expects relative paths from the rails app root to be passed in.

In this example, that would be packs/domain/file.rb. Using the CLI to validate this, it seems to work (DangerPackwerk::PackwerkWrapper.get_offenses_for_files(['packs/domain/file.rb']) reports violations as expected).

Naively the solution that comes to mind is passing in a config that strips the beginning of the filepath from the git output.

jarredhawkins commented 1 year ago

Threw up this one up as a proof of concept: https://github.com/rubyatscale/danger-packwerk/pull/40