feat: looping over dependencies (#1541)

* feat: support for loops in deps

* chore: tests

* docs: looping over deps
This commit is contained in:
Pete Davison
2024-03-10 17:21:50 +00:00
committed by GitHub
parent 29e91a4137
commit f06f48e225
11 changed files with 384 additions and 78 deletions

View File

@@ -1197,6 +1197,43 @@ tasks:
- echo 'bar'
```
### Looping over dependencies
All of the above looping techniques can also be applied to the `deps` property.
This allows you to combine loops with concurrency:
```yaml
version: '3'
tasks:
default:
deps:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{.ITEM}}'
my-task:
cmds:
- echo '{{.FILE}}'
```
It is important to note that as `deps` are run in parallel, the order in which
the iterations are run is not guaranteed and the output may vary. For example,
the output of the above example may be either:
```shell
foo
bar
```
or
```shell
bar
foo
```
## Forwarding CLI arguments to commands
If `--` is given in the CLI, all following parameters are added to a special

View File

@@ -48,17 +48,7 @@
},
"deps": {
"description": "A list of dependencies of this task. Tasks defined here will run in parallel before this task.",
"type": "array",
"items": {
"oneOf": [
{
"type": "string"
},
{
"$ref": "#/definitions/task_call"
}
]
}
"$ref": "#/definitions/deps"
},
"label": {
"description": "Overrides the name of the task in the output when a task is run. Supports variables.",
@@ -216,10 +206,26 @@
"$ref": "#/definitions/defer_call"
},
{
"$ref": "#/definitions/for_call"
"$ref": "#/definitions/for_cmds_call"
}
]
},
"deps": {
"type": "array",
"items": {
"oneOf": [
{
"type": "string"
},
{
"$ref": "#/definitions/task_call"
},
{
"$ref": "#/definitions/for_deps_call"
}
]
}
},
"set": {
"type": "string",
"enum": [
@@ -367,21 +373,11 @@
"additionalProperties": false,
"required": ["defer"]
},
"for_call": {
"for_cmds_call": {
"type": "object",
"properties": {
"for": {
"anyOf": [
{
"$ref": "#/definitions/for_list"
},
{
"$ref": "#/definitions/for_attribute"
},
{
"$ref": "#/definitions/for_var"
}
]
"$ref": "#/definitions/for"
},
"cmd": {
"description": "Command to run",
@@ -407,6 +403,45 @@
"additionalProperties": false,
"required": ["for"]
},
"for_deps_call": {
"type": "object",
"properties": {
"for": {
"$ref": "#/definitions/for"
},
"silent": {
"description": "Silent mode disables echoing of command before Task runs it",
"type": "boolean"
},
"task": {
"description": "Task to run",
"type": "string"
},
"vars": {
"description": "Values passed to the task called",
"$ref": "#/definitions/vars"
}
},
"oneOf": [
{"required": ["cmd"]},
{"required": ["task"]}
],
"additionalProperties": false,
"required": ["for"]
},
"for": {
"anyOf": [
{
"$ref": "#/definitions/for_list"
},
{
"$ref": "#/definitions/for_attribute"
},
{
"$ref": "#/definitions/for_var"
}
]
},
"for_list": {
"description": "A list of values to iterate over",
"type": "array",