phpro / grumphp

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

git commit not triggering grumphp #881

Closed bogdandubyk closed 3 years ago

bogdandubyk commented 3 years ago
Q A
Version 1.3.1
Bug? no
New feature? no
Question? yes

I have used grumphp version below 1 on few previous projects and all worked fine under docker, but I can't make it work with version 1.3.1

My configuration

grumphp:
    git_hook_variables:
        EXEC_GRUMPHP_COMMAND: docker-compose  -f ../devops/docker/docker-compose.yaml exec php-fpm bash
    stop_on_failure: false
    ignore_unstaged_changes: false
    hide_circumvention_tip: false
    process_timeout: 6
    ascii:
        succeeded: -
        failed: -
    tasks:
        composer:
            file: ./composer.json
            no_check_all: true
            no_check_lock: true
            no_check_publish: true
            no_local_repository: true
            with_dependencies: false
            strict: false
        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:
                - phpcs
                - phpcsfixer2
                - phpstan
                - yamllint
                - git_commit_message

I do not have git in the docker container, so I'm committing from a local machine where I do not have PHP installed and grumph not triggering. From container I did ./vendor/bin/grumphp git:init . Also I tried to override hooks_dir and add own hook like

#!/usr/bin/env sh

docker-compose -f ../devops/docker/docker-compose-test.yml exec -T php-fpm vendor/bin/grumphp run --testsuite=pre-commit -vvv

but it's not working either

I know I'm doing something wrong, but not sure what....

bogdandubyk commented 3 years ago

I made it work adding all variables like GRUMPHP_PROJECT_DIR GRUMPHP_GIT_WORKING_DIR GRUMPHP_BIN_DIR GRUMPHP_GIT_REPOSITORY_DIR , but now I'm getting error

git commit                                                                                                                                1 err | % | 15:43:38 
vendor/phpro/grumphp/bin/grumphp: line 2: ?php: No such file or directory
vendor/phpro/grumphp/bin/grumphp: line 4: use: command not found
vendor/phpro/grumphp/bin/grumphp: line 5: use: command not found
vendor/phpro/grumphp/bin/grumphp: line 6: use: command not found
vendor/phpro/grumphp/bin/grumphp: line 8: syntax error near unexpected token `('
vendor/phpro/grumphp/bin/grumphp: line 8: `(function () {'
veewee commented 3 years ago

Hello @bogdandubyk ,

You are executing grumphp with bash.

You can try changing it?

grumphp:
    git_hook_variables:
         EXEC_GRUMPHP_COMMAND: docker-compose  -f ../devops/docker/docker-compose.yaml exec php-fpm php
veewee commented 3 years ago

I assume the solution provided fixed the issue. Feel free to create another issue if this is still a problem.