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

Provide option to run a single/list of tasks from the config #580

Closed
paslandau opened this issue Jan 3, 2019 · 2 comments · Fixed by #587
Closed

Provide option to run a single/list of tasks from the config #580

paslandau opened this issue Jan 3, 2019 · 2 comments · Fixed by #587

Comments

@paslandau
Copy link

paslandau commented Jan 3, 2019

Q A
Version 0.14.3
Bug? no
New feature? yes
Question? yes
Documentation? probably
Related tickets

It would be great to have an option in the run command to specify a list of tasks that should be run by grumphp instead of running all tasks

Proposal

Consider the following grumphp.yml

parameters:
  tasks:
    composer: []
    composer_require_checker:
      ignore_parse_errors: true
    file_size:
      max_size: 1M

Run grumphp via

vendor/bin/grumphp run --tasks=composer,file_size

The --tasks option would be split on "," and the resulting values would act as a "whitelist" for the given config. I.e. only composer and file_size would run:

Running task  1/2: Composer... ✔
Running task  2/2: FileSize... ✔

composer_require_checker would be omitted since it is not listed in the option.

If --tasks is empty / not given, the default is the current behavior (maintaining bc).

Use cases

  • Being able to easily re-run a specific task
    • On "long" task chains this helps in verifying the reported issue is fixed without the need of running every other (probably unrelated) check as well
  • Quickly explore "new" tasks.
    • Currently, I need to duplicate my grumphp.yml, remove all tasks and keep only the required ones. This is really inconvenient, especially when setting up grumphp initially
  • Sometimes, I only need to run a specific taks / combination of tasks (e.g. parallel-lint and phpstan in order to quickly verify that there are no syntactical errors that will interrupt a subsequent unit/integration/end2end test run [which usually takes much longer])
  • Keep only one config file for different scenarios.
    • We use grumphp not only for commit hooks but also for general code checks on the "full" codebase, e.g. before we create a pull request for code review. Those include an extented set of tasks (e.g. composer-require-checker) that needs to only run before an actual push to remote but not on every commit. Currently, we need to maintain separate files to archieve this. With the --tasks option we could keep one file and pick the subset of tools that we need.

Implementation

I was having a quick look into the run command and this should be achievable with minimal effort, i.e.

  • add tasks option to RunCommand & parse comma separated string
  • add tasks property to TaskRunnerContext
  • in TaskRunner::run() filter TaskCollection based on the task name, i.e.
        $tasks = $this->tasks
            ->filterByContext($runnerContext->getTaskContext())
            ->filterByTestSuite($runnerContext->getTestSuite())
            ->filterByTaskName($runnerContext->getTasks())
            ->sortByPriority($this->grumPHP)
        ;
  • with TaskCollection::filterByTaskName() as
    /**
     * @param string[]|null $tasks
     *
     * @return TasksCollection
     */
    public function filterByTaskName($tasks)
    {
        return $this->filter(function (TaskInterface $task) use ($tasks) {
            if (empty($tasks)) {
                return true;
            }
            return in_array($task->getName(), $tasks);
        });
    }

I would prepare a PR if you'd like to move forward.

Cheers
Pascal

@veewee
Copy link
Contributor

veewee commented Jan 3, 2019

Hi @paslandau,

Looks like a great addition. I'dd accept a PR for that.
Note that the last 2 use cases can be covered by specifying testsuites (see https://github.com/phpro/grumphp/blob/master/doc/testsuites.md)

@paslandau
Copy link
Author

Note that the last 2 use cases can be covered by specifying testsuites (see https://github.com/phpro/grumphp/blob/master/doc/testsuites.md)

Ha. Totally missed that.. the PR anyway :)

paslandau pushed a commit to paslandau/grumphp that referenced this issue Jan 4, 2019
Landerstraeten pushed a commit to paslandau/grumphp that referenced this issue Apr 19, 2019
Landerstraeten pushed a commit to paslandau/grumphp that referenced this issue May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants