Skip to content

Set path and/or full filename in triggered_by #1157

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

Closed
evs-xsarus opened this issue Oct 31, 2024 · 7 comments
Closed

Set path and/or full filename in triggered_by #1157

evs-xsarus opened this issue Oct 31, 2024 · 7 comments

Comments

@evs-xsarus
Copy link
Contributor

Q A
Version 2.5.0
Bug? no
New feature? yes
Question? no
Documentation? no
Related tickets comma-separated list of related tickets

Due to the use of dockers, my grump config only uses shell tasks , example:

grumphp:
    process_timeout: 512
    tasks:
        magento_composer:
            scripts:
                - ["-c", "/usr/local/bin/composer2 --working-dir=./magento validate"]
            metadata:
                task: shell
        magento_stan-check:
            scripts:
                - ["-c", "/usr/local/bin/composer2 --working-dir=./magento stan-check"]
            metadata:
                task: shell

        integrations_composer:
            scripts:
                - ["-c", "/usr/local/bin/composer2 --working-dir=./integrations validate"]
            metadata:
                task: shell
        integrations_cs-check:
            scripts:
                - ["-c", "/usr/local/bin/composer2 --working-dir=./integrations cs-check"]
            metadata:
                task: shell

Most of these tasks start properly when PHP files are changed as per documentation https://github.com/phpro/grumphp/blob/v2.x/doc/tasks/shell.md for triggered_by .

Sadly, the composer validate is not triggered if only composer.json/composer.lock is changed. I can add these:

        magento_composer:
            scripts:
                - ["-c", "/usr/local/bin/composer2 --working-dir=./magento validate"]
            metadata:
                task: shell
            triggered_by: [json, lock]

But that means the task will run even if a non-related json or lock file is changed.

To avoid this, specifying a complete filename should help as in this example:

            triggered_by: [composer.lock, composer.json]

or even with wildcards:

            triggered_by: [composer.*]

As you can see in my example, I've duplicate tasks but for different folders. The path should be definable too in triggered by, full example:

        magento_composer:
            scripts:
                - ["-c", "/usr/local/bin/composer2 --working-dir=./magento validate"]
            metadata:
                task: shell
            triggered_by: ['./magento/composer.*']
@veewee
Copy link
Contributor

veewee commented Nov 26, 2024

Hello @evs-xsarus,

That would be possible. We do a similir thing for the ComposerRequireChecker task.
However : since we are now filtering triggered_by as extensions, it would be considered a BC break.
Maybe an alternate solution could be to introduce a new parameter for this specific case? Something like triggered_by_filenames (which will use the $files->names() filter)?

Feel free to propose changes in a PR.

@evs-xsarus
Copy link
Contributor Author

@veewee could you have a look at my draft MR?

evs-xsarus added a commit to evs-xsarus/grumphp that referenced this issue Feb 28, 2025
@evs-xsarus
Copy link
Contributor Author

@veewee I've refactored a bit and applied the same approach as in SymfonyConsole. That whilelist + ignore pattern works great as can be tested with this configuration:

grumphp:
    process_timeout: 360
    tasks:
        magento_composer:
            triggered_by: ['json', 'lock']
            whitelist_patterns:
                - "#^magento/composer.json#"
                - "#^magento/composer.lock#"
            scripts:
                - ["-c", "/usr/local/bin/composer2 --working-dir=./magento validate"]
            metadata:
                task: shell

@evs-xsarus
Copy link
Contributor Author

@veewee does this refactored approach work for you?

evs-xsarus added a commit to evs-xsarus/grumphp that referenced this issue Mar 11, 2025
veewee added a commit that referenced this issue Mar 11, 2025
…lenames

Ticket #1157: support specific filenames as trigger for Shell.
@veewee veewee closed this as completed Mar 11, 2025
@evs-xsarus
Copy link
Contributor Author

@veewee do you have an ETA for the next release so I can start using this ?

@veewee
Copy link
Contributor

veewee commented Mar 20, 2025

Hopefully next week

@veewee
Copy link
Contributor

veewee commented Mar 21, 2025

It's released ;)

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