phpro / grumphp

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

Environment variables are not getting picked up #856

Closed Rohan-Jalil closed 3 years ago

Rohan-Jalil commented 3 years ago
Q A
Version 1.3.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets https://github.com/phpro/grumphp/issues/676

I wanted phpcsfixer2 to pick my environment variable PHP_CS_FIXER_IGNORE_ENV which I am passing through my grumphp.yml as mentioned below to ignore the PHP version I am using. Basically, I am using PHP 8 but it is not yet supported at PHP-CS-FIXER side so they have added an environment variable which when passed, ignores the PHP version https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/2.17/doc/usage.rst#environment-options. But Grumphp is not picking up this environment variable and not calling phpcsfixer2 task with this environment variable.

My configuration

# grumphp.yml
grumphp:
    ascii:
        failed: failed.txt
        succeeded: successded.txt
    environment:
        files:
            - .env
        variables:
            PHP_CS_FIXER_IGNORE_ENV: 1
    tasks:
        phpcsfixer2:
            allow_risky: ~
            cache_file: ~
            config: ~
            rules:
                - '@@PSR2'
                - -line_ending
                - array_syntax
            using_cache: ~
            config_contains_finder: true
            verbose: true
            diff: true
            triggered_by: [ 'php' ]

Run GrumpPHP

./vendor/bin/grumphp run

Result:

phpcsfixer2
===========

PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*.
To ignore this requirement please set `PHP_CS_FIXER_IGNORE_ENV`.
If you use PHP version higher than supported, you may experience code modified in a wrong way.
Please report such cases at https://github.com/FriendsOfPHP/PHP-CS-Fixer .

You can fix errors by running the following command:
'/var/www/html/vendor/bin/php-cs-fixer' '--rules=@@PSR2,-line_ending,array_syntax' '--verbose' '--diff' 'fix'
To skip commit checks, add -n or --no-verify flag to commit command

 I can fix some stuff automatically, do you want me to? (yes/no) [no]:
veewee commented 3 years ago

Investigated this one a bit further.

In order for the env var to be passed by symfony/process, the value needs to be a string instead of an int:

grumphp:
    environment:
      variables:
        PHP_CS_FIXER_IGNORE_ENV: "1"

This works if parallel execution is disabled. If parallel is enabled, amp/parallel-functions is not setting the env variables in the child process. We'll need to find a way around this.

veewee commented 3 years ago

Fixed the behaviour in #863 and added documentation about the integer value.