task
task copied to clipboard
Variable with list of namespace names for included files
I quite often end up in this situation when building monorepos using task:
version: "3"
includes:
app1: ./app1
app2: ./app2
app3: ./app3
app4: ./app4
vars:
APPS:
- app1
- app2
- app3
- app4
tasks:
build:
deps:
- for: { var: APPS }
task: "{{ .ITEM }}:build"
clean:
deps:
- for: { var: APPS }
task: "{{ .ITEM }}:clean"
test:
deps:
- for: { var: APPS }
task: "{{ .ITEM }}:test"
The same kind of pattern might exist in multiple places within a repository (e.g. for applications, libraries, test tools, etc.). It's OK syntax as it's quite easy to add new entries by just updating (in this case) APPS. But it would be very convenient with a variable containing the namespace name of all includes in the current file. So I basically could write something like this:
version: "3"
includes:
app1: ./app1
app2: ./app2
app3: ./app3
app4: ./app4
tasks:
build:
deps:
- for: { var: INCLUDE_NAMESPACES }
task: "{{ .ITEM }}:build"
clean:
deps:
- for: { var: INCLUDE_NAMESPACES }
task: "{{ .ITEM }}:clean"
test:
deps:
- for: { var: INCLUDE_NAMESPACES }
task: "{{ .ITEM }}:test"
In the long run, it would also be convenient to have some kind of wildcard support for includes as well (to make this situation even more automagic). But that's out of scope for this request.
@postlund how about:
version: "3"
includes:
app1: ./app1
app2: ./app2
app3: ./app3
app4: ./app4
tasks:
build:
deps:
- for:
includes:
filter: '/some/regex'
try: true # if the task does not exist, then next item
continue: true # continue next item if the task fails, overall the task fails
task: "{{ .ITEM }}:build"