grumphp not working correclty with custom directory structure

  docker, git, grumphp, php

For some reason grumphp not working for me as expected.
First of all my project directory structure is:

.git/
devops/
app/
   src/
   confing/
   bin/
   vendor/
   grumphp.yml
   phpcs.xml
   ...

so I in the git repo I have some docker related files in the devops folder, and symfony app int the app folder, also in app folder I have grumphp and all linters configs.

I want to run grumphp from inside of the docker container when I commit some changes to check if my code is correct.

Here is my grumphp.yml

grumphp:
    environment:
        variables:
            GRUMPHP_PROJECT_DIR: "."
            GRUMPHP_GIT_WORKING_DIR: "../"
            GRUMPHP_BIN_DIR: "vendor/bin/"
            GRUMPHP_GIT_REPOSITORY_DIR: "../.git/"
    git_hook_variables:
        EXEC_GRUMPHP_COMMAND: docker exec php-fpm
    stop_on_failure: false
    ignore_unstaged_changes: false
    hide_circumvention_tip: false
    process_timeout: 6
    tasks:
        composer: ~
        phpcs:
            standard: phpcs.xml
            ignore_patterns: [./var/*, ./public/*, ./config/*, ./bin/*]
        phpcsfixer2:
            config: .php_cs
        phpstan:
            autoload_file: ./bin/.phpunit/phpunit-9.0.1-0/vendor/autoload.php
            memory_limit: "-1"
        git_commit_message:
            allow_empty_message: false
            enforce_capitalized_subject: false
            enforce_no_subject_punctuations: false
            enforce_no_subject_trailing_period: true
            enforce_single_lined_subject: true
            type_scope_conventions: []
            max_body_width: 0
            max_subject_width: 72
            matchers:
                Must contain JIRA issue number: /^(Merge)|([A-Z_0-9]+-[0-9]+)/
            case_insensitive: true
            multiline: true
            additional_modifiers: ''
        yamllint:
            whitelist_patterns: [ ]
            ignore_patterns:
                - /^vendor/(.*)/
            object_support: false
            exception_on_invalid_type: false
            parse_constant: false
            parse_custom_tags: false
    testsuites:
        pre-commit:
            tasks:
                - composer
                - phpcs
                - phpcsfixer2
                - phpstan
                - yamllint
                - git_commit_message

and when I’m running vendor/bin/grumphp git:init from inside of the docker container, pre-commit file generated in the .git/hooks directory, generated pre-commit file content:

#!/bin/sh

#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#

# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false -c diff.noprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)

# Grumphp env vars

export GRUMPHP_GIT_WORKING_DIR="$(git rev-parse --show-toplevel)"

# Run GrumPHP
(cd "app/" && printf "%sn" "${DIFF}" | docker exec php-fpm 'vendor/phpro/grumphp/bin/grumphp' 'git:pre-commit' '--skip-success-output')

SO what is the issue?

When I run git commit having php files with a broken styles, grumphp telling that all is fine and allowing me to commit this files, but when I run vendor/bin/grumphp run from inside of the container all working fine and I see list of all the issues I need to fix.

So why all linters checks passing on commit when they should not, but when I’m running vendor/bin/grumphp run it’s working as expected?

I’m not sure but I think it somehow related to my directory structure, I have .git in the root of repository, but symfony and grumphp.yml in the app directory.

Thanks in advance!

Source: Docker Questions

LEAVE A COMMENT