Skip to content

Reusing placeholder with another value than previous run (cache should be invalidate) #311

@llaville

Description

@llaville

While I continue to use/implement my plugin https://github.com/llaville/captainhook-bin-plugin in real condition (project), I discover other issues.

  1. one issue on my plugin that will be fixed soon with version 1.0.2
  2. second, is related to CaptainHook itself. I'll explain now.

I've the two actions for the same hook, that both uses the same placeholder but with different values.
This is origin/reason of this issue, because https://github.com/captainhook-git/captainhook/blob/5.28.5/src/Runner/Action/Cli/Command/Formatter.php#L164 once computed reused the cached value.

Now the example to understand, and why I found it.
My plugin is able to detect vendor binary config files and set it to XDG_CONFIG_HOME environment variable.

Here is what I'm expected to have :

PHP_CodeSniffer and PHP-CS-Fixer use their respectives config file !

Image

Now, this is what I get :

Image

The captainhook.json config file

The {$ENV|value-of:XDG_CONFIG_HOME} placeholder is computed first time with PHPCS action, and reused by PHP-CS-Fixer, even if value has changed (and should be re-apply), because it exists in cache (see https://github.com/captainhook-git/captainhook/blob/5.28.5/src/Runner/Action/Cli/Command/Formatter.php#L167)

Details

{
    "config": {
        "verbosity": "normal",
        "allow-failure": false,
        "ansi-colors": true,
        "bootstrap": "autoload.php",
        "git-directory": ".git",
        "fail-on-first-error": false,
        "plugins": [
            {
                "plugin": "\\Bartlett\\CaptainHookBinPlugin\\BinPlugin",
                "options": {
                    "binary-directory": "{$ENV|value-of:VENDOR_BIN_DIR|default:vendor/bin}",
                    "config-directory": ".github/linters",
                    "ansi-colors-flag": "--ansi",
                    "auto-colors-flag": "--colors=auto",
                    "always-colors-flag": "--colors=always",
                    "never-colors-flag": "--colors=never"
                }
            }
        ]
    },
    "pre-commit": {
        "enabled": true,
        "actions": [
            {
                "action": [
                    "{$ENV|value-of:XDG_BIN_HOME}phpcs",
                    "--standard={$ENV|value-of:XDG_CONFIG_HOME}",
                    "--warning-severity=0",
                    "--colors",
                    "{$STAGED_FILES|of-type:php|separated-by: }"
                ],
                "config": {
                    "label": "Checks Coding Standard (with PHP_CodeSniffer)"
                },
                "options": {
                    "config-file": ".phpcs.xml.dist",
                    "package-require": [
                        "squizlabs/php_codesniffer",
                        "^3.3"
                    ]
                }
            },
            {
                "action": [
                    "{$ENV|value-of:XDG_BIN_HOME}php-cs-fixer",
                    "fix",
                    "--dry-run",
                    "--config={$ENV|value-of:XDG_CONFIG_HOME}",
                    "--using-cache=no",
                    "--verbose",
                    "{$CONFIG|value-of:plugin>>\\Bartlett\\CaptainHookBinPlugin\\BinPlugin.ansi-colors-flag}",
                    "{$STAGED_FILES|of-type:php|separated-by: }"
                ],
                "config": {
                    "label": "Checks Coding Standard (with PHP-CS-Fixer)"
                },
                "options": {
                    "config-file": ".php-cs-fixer.dist.php",
                    "package-require": [
                        "friendsofphp/php-cs-fixer",
                        "^3.5"
                    ]
                }
            }
        ]
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions