evilmartians/lefthook

Make `parallel: true` work with priorities

scop opened this issue · 3 comments

scop commented

⚡ Summary

Would good to have parallel: true work with priorities.

Value

Faster runs containing priorities (~ dependencies).

Behavior and configuration changes

For example:

foo:
  parallel: true
  commands:
    cmd-a:
      priority: 1
    cmd-b:
      priority: 2
    cmd-c:
      priority: 3
    cmd-d:
      # no priority set
    cmd-e:
      priority: 1
    cmd-f:
      priority: 3

...and lefthook run foo would result in the commands to be run in parallel within groups determined by priority.

So the order of execution would go in sequence

  1. priority 1: cmd-a and cmd-e in parallel
  2. priority 2 (after prio 1 jobs complete): cmd-b alone
  3. priority 3 (after prio 2 jobs complete): cmd-c and cmd-f in parallel
  4. priority +Infinity (after prio 3 jobs complete): cmd-d alone
mrexox commented

@scop, please, try new jobs feature released with 1.10.0, check the docs but for your order definition the config can look like this:

# lefthook.yml
foo:
  jobs:
    - group:
        parallel: true
        jobs:
          - run: cmd-a
          - run: cmd-e
    - run: cmd-b
    - group:
      parallel: true
      jobs:
        - run: cmd-c
        - run: cmd-f
    - run: cmd-d
scop commented

That looks otherwise nice and useful, but I suppose with the jobs config above, it would no longer be possible to run specific commands only?

With commands one could do lefthook run pre-commit --commands COMMANDNAME but there's no corresponding option to run only some job or group names?


Anyway for purposes of the actual topic in this issue, jobs and groups seem to fill the need fine, thanks!

mrexox commented

Hmm, nice note. I think it should be possible to add the same --jobs argument. But if you have jobs with the same name – all of them will be run. Do you find this useful? I think I can add it in future releases.