Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env variables don't get expanded in task definitions #1146

Open
indykoning opened this issue Jul 31, 2024 · 1 comment
Open

Env variables don't get expanded in task definitions #1146

indykoning opened this issue Jul 31, 2024 · 1 comment

Comments

@indykoning
Copy link

indykoning commented Jul 31, 2024

Q A
Version GrumPHP 2.6.0
Bug? yes
New feature? no
Question? no
Documentation? yes

Following the docs on using environment variables and parameters doesn't actually function as expected.
The example seems to work, however setting the variable to false still has the config enabled.

i've debugged it by using it in a task and dumping the task definition in the code. Which results in:

GrumPHP\Task\Config\Metadata^ {#659
  -metadata: array:5 [
    "blocking" => true
    "task" => ""
    "label" => ""
    "priority" => 0
    "enabled" => "env_19eeff9b12d8f08c_bool_GRUM_COMPOSER_NORMALIZE_ENABLED_b9f45633a4808b98cb74867bcd84c333"
  ]
}

instead of the expected bool value, it is a string identifying the variable to be resolved.
This feels similar to symfony/symfony#45868

My configuration

# grumphp.yml
parameters:
    env(GRUM_COMPOSER_NORMALIZE_ENABLED): 'false'
    env(GRUM_COMPOSER_NORMALIZE_VERBOSE): 'false'
    
grumphp:
    tasks:
        composer_normalize:
            metadata:
                enabled: '%env(bool:GRUM_COMPOSER_NORMALIZE_ENABLED)%'
            indent_size: 4
            indent_style: "space"
            no_update_lock: false
            verbose: '%env(bool:GRUM_COMPOSER_NORMALIZE_VERBOSE)%'

Steps to reproduce:

# Generate empty folder
mkdir tmp
cd tmp
git init
echo "vendor" > .gitignore
pbpaste > grumphp.yml
composer require --dev phpro/grumphp

# Run GrumPHP:
git add -A && git commit -m"Test"
# or
./vendor/bin/grumphp run

Result:

Composer normalize is still excecuted instead of not excecuting at all
@veewee
Copy link
Contributor

veewee commented Aug 30, 2024

Thanks for reporting, I can confirm this is a bug but haven't found a solution yet.
Feel free to dive into the specifics to figure out what is going wrong here.

What I've found so far is that the \GrumPHP\Configuration\Compiler\TaskCompilerPass is being executed before the env vars are being replaced inside \Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass when executing $container->compile(true); inside \GrumPHP\Configuration\ContainerBuilder::buildFromConfiguration().

This results in the task instances that are registered inside the container to have this env_19eeff9b12d8f08c_bool_GRUM_COMPOSER_NORMALIZE_ENABLED_b9f45633a4808b98cb74867bcd84c333 placeholder instead of the actual replaced value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants