phpro / grumphp

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

[bug?] Yamllint does not retrieve correctly the application folder in exotic architecture #978

Closed adaniloff closed 1 year ago

adaniloff commented 2 years ago
Q A
Version 1.7.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets none

Note: the configuration is quite hard (exotic infrastructure, in containers) to explain, we made a reproducer just for you: https://github.com/NazarioR9/grumphp-exoctic-issue. Check the readme and after cloning and a few commands you should be able to reproduce the issue (reproducer made & tested on a linux env).

My configuration

# grumphp.yml
grumphp:
    git_hook_variables:
        EXEC_GRUMPHP_COMMAND: 'docker exec -t app_php'
    ignore_unstaged_changes: true
    process_timeout: 120
    fixer:
        enabled: true
        fix_by_default: false
    tasks:
        deptrac:
            formatter:
                - console
        phpstan:
            configuration: 'phpstan.neon.dist'
            ignore_patterns:
                - '/config/'
                - '/vendor/'
                - '/public/'
                - '/var/'
                - '/bin/'
                - '/templates/'
            triggered_by: ['php']
            memory_limit: "-1"
            use_grumphp_paths: false
        composer:
            strict: false
        phpcsfixer:
            config: '.php-cs-fixer.dist.php'
            allow_risky: true
        git_blacklist:
            match_word: true
            keywords:
                - 'dd('
                - 'die('
                - 'var_dump('
                - 'exit;'
                - 'exit('
                - 'dump('
            whitelist_patterns:
                - /^src\/(.*)/
        git_branch_name:
            whitelist:
                - '#^(feat|fix)\/AYR-\d+-.+#'
            blacklist:
                - '/^release/'
                - 'develop'
                - 'master'
                - 'main'
        git_commit_message:
            enforce_capitalized_subject: false
            max_body_width: 0
            max_subject_width: 72
            allow_empty_message: false
            type_scope_conventions:
                types:
                    - build
                    - ci
                    - chore
                    - docs
                    - feat
                    - fix
                    - perf
                    - refactor
                    - revert
                    - style
                    - test
                scopes: []
        securitychecker_local:
            run_always: true
        yamllint:
            parse_custom_tags: true
        make:
            make_file: Makefile
            task: 'test'
    environment:
        variables:
            GRUMPHP_BIN_DIR: "bin/dev"
        paths:
            - /usr/local/bin

Steps to reproduce:

  1. Have an exotic folder structure like below:
    • Project path: /home/username/projects/exotic-project This folder contains docker-compose and .git files
    • Application path: /home/username/projects/exotic-project/api This folder contains the application (under SF6 in my case) and the grumphp.yml file
  2. Have your application containerized like this:
    
    # docker-compose.yaml
    version: "3.4"

services: app_php: container_name: app_php restart: unless-stopped volumes:

Your actions

Run GrumPHP:

docker-compose exec app_php bin/dev/grumphp run

Result:

yamllint
========

SplFileInfo::openFile(api/config/api_platform/resources/Entity.yaml): Failed to open stream: No such file or directory

Hint: The file exists from the projet's path (/home/username/projects/exotic-project), but grumphp seems to try to get if from the application path (/home/username/projects/exotic-project/api), thus we get the previous error message.

# from /home/username/projects/exotic-project
~/projects/exotic-project on  feat/AYR-1476-grumphp ⌚ 10:43:05
$ ls -l api/config/api_platform/resources/Entity.yaml  
-rw-rw-r-- 1 username username 535 janv. 27 10:32 api/config/api_platform/resources/Entity.yaml

# from /home/username/projects/exotic-project/api
$ ls -l api/config/api_platform/resources/Entity.yaml
ls: impossible d'accéder à 'api/config/api_platform/resources/Entity.yaml': Aucun fichier ou dossier de ce type
veewee commented 2 years ago

Hello @adaniloff

Havent had the time to play with the provided repo, but from the grumphp file I can tell that you need to provide additional environment variables; You can do so either by adding them to grumphp.yaml or to your docker container:

More info:

https://github.com/phpro/grumphp/blob/master/doc/installation/exotic.md#changing-paths-by-using-environment-variables

By running grumphp -v, you can see the paths that got detected automatically:

$ ./vendor/bin/grumphp -v                                                                                                                                                                            

Config file: /Users/xxxx/grumphp.yml
Working dir: /Users/xxxx
Project dir: /Users/xxxx
GIT working dir: /Users/xxxx
GIT repository dir: /Users/xxxx/.git
Bin dir: /Users/xxxx/vendor/bin
Composer file: /Users/xxxx/composer.json

You can overwrite these paths by setting env vars:

GRUMPHP_PROJECT_DIR=...
GRUMPHP_GIT_WORKING_DIR=....
GRUMPHP_GIT_REPOSITORY_DIR=...
GRUMPHP_COMPOSER_DIR=...
GRUMPHP_BIN_DIR=...
PATH=/additional/bin/dirs:$PATH

SInce you are using docker, you can hardcode these to absolute paths in docker-compose.yaml right?

veewee commented 1 year ago

Closing this one because of inactivity If the issue still persists - feel free to reopen and provide some additional context.