1
0
mirror of https://github.com/go-task/task.git synced 2025-12-13 23:45:44 +02:00

Add support for 'platforms' in both task and command (#980)

This commit is contained in:
Lea Anthony
2023-01-07 11:38:35 +11:00
committed by GitHub
parent 63c50d13ee
commit aa6c7e4b94
10 changed files with 295 additions and 0 deletions

View File

@@ -139,6 +139,7 @@ includes:
| `prefix` | `string` | | Defines a string to prefix the output of tasks running in parallel. Only used when the output mode is `prefixed`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing commands. |
| `run` | `string` | The one declared globally in the Taskfile or `always` | Specifies whether the task should run again or not if called more than once. Available options: `always`, `once` and `when_changed`. |
| `platforms` | `[]string` | All platforms | Specifies which platforms the task should be run on. |
:::info
@@ -189,6 +190,7 @@ tasks:
| `vars` | [`map[string]Variable`](#variable) | | Optional additional variables to be passed to the referenced task. Only relevant when setting `task` instead of `cmd`. |
| `ignore_error` | `bool` | `false` | Continue execution if errors happen while executing the command. |
| `defer` | `string` | | Alternative to `cmd`, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with `cmd`. |
| `platforms` | `[]string` | All platforms | Specifies which platforms the command should be run on. |
:::info

View File

@@ -439,6 +439,73 @@ tasks:
- echo {{.TEXT}}
```
## Platform specific tasks and commands
If you want to restrict the running of tasks to explicit platforms, this can be achieved
using the `platforms` key. Tasks can be restricted to a specific OS, architecture or a
combination of both.
The `build-windows` task below will run only on Windows, and on any architecture:
```yaml
version: '3'
tasks:
build-windows:
platforms: [windows]
cmds:
- echo 'Running command on windows'
```
This can be restricted to a specific architecture as follows:
```yaml
version: '3'
tasks:
build-windows-amd64:
platforms: [windows/amd64]
cmds:
- echo 'Running command on windows (amd64)'
```
It is also possible to restrict the task to specific architectures:
```yaml
version: '3'
tasks:
build-amd64:
platforms: [amd64]
cmds:
- echo 'Running command on amd64'
```
Multiple platforms can be specified as follows:
```yaml
version: '3'
tasks:
build-windows:
platforms: [windows/amd64, darwin]
cmds:
- echo 'Running command on windows (amd64) and darwin'
```
Individual commands can also be restricted to specific platforms:
```yaml
version: '3'
tasks:
build-windows:
cmds:
- cmd: echo 'Running command on windows (amd64) and darwin'
platforms: [windows/amd64, darwin]
- cmd: echo 'Running on all platforms'
```
## Calling another task
When a task has many dependencies, they are executed concurrently. This will

View File

@@ -155,6 +155,13 @@
"run": {
"description": "Specifies whether the task should run again or not if called more than once. Available options: `always`, `once` and `when_changed`.",
"$ref": "#/definitions/3/run"
},
"platforms": {
"description": "Specifies which platforms the task should be run on.",
"type": "array",
"items": {
"type": "string"
}
}
}
},
@@ -233,6 +240,13 @@
"defer": {
"description": "",
"type": "boolean"
},
"platforms": {
"description": "Specifies which platforms the command should be run on.",
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false,