task icon indicating copy to clipboard operation
task copied to clipboard

Support loops in dependencies as well

Open eliad-wiz opened this issue 2 years ago • 4 comments

Allow specifying loops in task dependencies the same way they can be used in cmds

Taskfile:

version: '3'

tasks:
  deptask:
    desc: dependency task
    cmds:
      - echo dependency foo {{.FOO}}

  default:
    desc: some task
    deps:
      - for: ['foo', 'bar']
        task: deptask
        vars:
          FOO: "DEP-{{.ITEM}}"

    cmds:
      - for: ['foo', 'bar']
        task: deptask
        vars:
          FOO: "ROOT-{{.ITEM}}"

Expected output

task: [deptask] echo dependency foo DEP-foo
dependency foo DEP-foo
task: [deptask] echo dependency foo DEP-bar
dependency foo DEP-bar
task: [deptask] echo dependency foo ROOT-foo
dependency foo ROOT-foo
task: [deptask] echo dependency foo ROOT-bar
dependency foo ROOT-bar

Actual output

task: [deptask] echo dependency foo DEP-
dependency foo DEP-
task: [deptask] echo dependency foo ROOT-foo
dependency foo ROOT-foo
task: [deptask] echo dependency foo ROOT-bar
dependency foo ROOT-bar
  • Task version: v3.28.0 (h1:PGYGwevlGQdYrqhO6lLCYylC7YuGoQLlVwHkO42gf0I=)

eliad-wiz avatar Aug 09 '23 12:08 eliad-wiz

Perhaps this is obvious to others, but is there a reason this isn't desirable?

version: '3'

tasks:
  deptask:
    desc: dependency task
    cmds:
      - echo dependency foo {{.FOO}}

  default:
    desc: some task

    cmds:
      - for: ['foo', 'bar']
        task: deptask
        vars:
          FOO: "DEP-{{.ITEM}}"
      - for: ['foo', 'bar']
        task: deptask
        vars:
          FOO: "ROOT-{{.ITEM}}"

If it's because deptask isn't run in parallel, I wonder about your thoughts on #1300.

q0rban avatar Aug 09 '23 14:08 q0rban

sorry for not mentioning it, but the reason is parallelism, as you mentioned.

i don't like the "parallel for" syntax too much, as there's no reason to specialize it. something like this is more generic, and makes more sense to me:

version: '3'

tasks:
  deptask:
    desc: dependency task
    cmds:
      - echo dependency foo {{.FOO}}

  default:
    desc: some task

    cmds:
      - parallel:
        - echo first command
        - for: ['foo', 'bar']
          task: deptask
          vars:
            FOO: "DEP-{{.ITEM}}"
        - echo last command

i.e. specifying all the parallel commands in a separate group. it is also nicer since it can replace the deps altogether.

i think it is a better solution, but having loops support in "deps" (similar to "cmds") is good enough for my usecase.

eliad-wiz avatar Aug 09 '23 14:08 eliad-wiz

Would really love to see this feature too!

postlund avatar Nov 09 '23 07:11 postlund

+1 on the feature

sambhav avatar Jan 04 '24 14:01 sambhav