mirror of
https://github.com/go-task/task.git
synced 2026-07-01 16:44:34 +00:00
feat: looping over dependencies (#1541)
* feat: support for loops in deps * chore: tests * docs: looping over deps
This commit is contained in:
@@ -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
|
||||
|
||||
83
docs/static/schema.json
vendored
83
docs/static/schema.json
vendored
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user