phpro / grumphp

A PHP code-quality tool
MIT License
4.14k stars 429 forks source link

Add support for DDEV environments. #972

Closed bserem closed 2 years ago

bserem commented 2 years ago
Q A
Branch master for features and deprecations
Bug fix? no
New feature? yes
BC breaks? yes/no
Deprecations? no
Documented? yes
Fixed tickets -

This PR adds support for running grumphp in DDEV environments. https://github.com/drud/ddev is a very popular (and rising in popularity) dockerized environment.

I am very new to Grum but I wanted this inside DDEV, so here it is. I'll be glad to hear your thoughts.

bserem commented 2 years ago

Apparently this is not getting much attention and in the meanwhile I've found an easier way to achieve this. I can alter the EXEC_GRUMPHP_COMMAND variable, although this will only make the script work outside of ddev, not both outside and inside the container.

grumphp:
  tasks:
    git_commit_message: ~
  git_hook_variables:
    EXEC_GRUMPHP_COMMAND: ddev exec php
veewee commented 2 years ago

Haven't found the time to look into ddev yet, sorry. Maybe it can start out as an extension and if there is a lot of traction, it can become GrumPHP core?

bserem commented 2 years ago

@veewee no need to be sorry! Grum works fine with ddev, the only issue is that it needs different configuration if you work outside the container and inside the container.

My previous comment is the easiest fix for those who want to work outside the container.

The updated PR takes care of running grumphp properly, regardless if you are committing for the host machine.

veewee commented 2 years ago

@bserem As mentioned above, the suggested way here is to use:

grumphp:
  git_hook_variables:
    EXEC_GRUMPHP_COMMAND: ddev exec php

We also use EXEC_GRUMPHP_COMMAND for running it on docker. The hook you provided is basically the same as the local hook. So it is best to change the exec command instead. That way we dont have to maintain all these different presets.

I've added this to the docs as well: https://github.com/phpro/grumphp/blob/master/doc/parameters.md -> git_hook_variables

Thanks for figuring this all out :)