phpro / grumphp

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

hooks_preset: vagrant doesn't execute GrumPHP inside the machine #362

Closed poteirard closed 7 years ago

poteirard commented 7 years ago
Q A
Version 0.11.5
Bug? yes/no
New feature? yes/no
Question? yes
Documentation? yes/no
Related tickets .

Hi,

First of all thank you for all this work :)

Is there a way to use GrumPHP inside and outside vagrant? I have a team where there are people who use git inside the vagrant machine and other people who use it from the host machine.

My configuration

# grumphp.yml
parameters:
    bin_dir: "./src/php/bin"
    git_dir: "."
    hooks_dir: ~
    hooks_preset: vagrant
    stop_on_failure: false
    ignore_unstaged_changes: false
    hide_circumvention_tip: false
    process_async_limit: 10
    process_async_wait: 1000
    process_timeout: 60
    tasks:
        composer: ~
        git_blacklist: ~
        git_commit_message:
            matchers:
                Commit must start with capital letter and end with the JIRA issure number: /[A-Z]{1}.*?\. \#MXB-\d+/
        jsonlint: ~
        npm_script:
            script: test
            triggered_by: [js, vue]
            working_directory: "./src/php/public/phoenix"
            is_run_task: true
        phpcsfixer: ~
        phpcsfixer2: ~
        php_cs_auto_fixer: ~
        php_cs_auto_fixerv2: ~
        phplint: ~
        phpmd: ~
        phpunit:
            config_file: src/php/tests/phpunit.xml
            testsuite: unit
            group: []
            always_execute: false

        xmllint: ~
        yamllint: ~

    testsuites: []
    extensions:
- Wearejust\GrumPHPExtra\Extension\Loader

Steps to reproduce:

$ git add -A && git commit -m "Test"
...executing GrumPHP correctly...

$ vagrant ssh
$guest: git add -A && git commit -m "Test"
.git/hooks/pre-commit: 12: .git/hooks/pre-commit: vagrant: not found

Maybe we need a hooks_preset like hybrid?

veewee commented 7 years ago

Hi @poteirard,

I would suggest your team to run GrumPHP the same way on every machine. Besides that advise, it is possible to override this choice per installation. This can be done by providing a grumphp.yml.dist file and add the grumphp.yml file to the .gitignore file. This way, everybody in the team can personalize the hooks_preset the way they want.

Does this answer your question?

poteirard commented 7 years ago

Yes. Thank you @veewee .

However I still think that we could add a conditional runner in this code to suit both possibilities, is this a bad idea?:



# Run GrumPHP 
# If vagrant isn't available run local run ????
vagrant ssh --command '$(which sh)' << COMMANDS

  # Transfer the DIFF
  DIFF=\$(cat <<- '__GRUMPHP_DIFF_HEREDOC__'
    ${DIFF}
    __GRUMPHP_DIFF_HEREDOC__
  )

  printf "%s\n" "\${DIFF}" | exec $(HOOK_COMMAND) '--ansi' '--skip-success-output'
COMMANDS```
veewee commented 7 years ago

Hi @poteirard,

It sure isn't a bad idea. You can add any preset you want to use to your project. I just want to keep the presets in this project as simple as possible: Vagrant = vagrant, local = local If we start adding these validation rules, people will get confused.

poteirard commented 7 years ago

I understand. Thank you again. And keep it rocking 😎