mirror of
https://github.com/go-task/task.git
synced 2025-06-06 23:46:46 +02:00
Documentation changes for v2.0.0 release
This commit is contained in:
parent
c1ae36866e
commit
d48a2f3ccf
147
README.md
147
README.md
@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
# Task - A task runner / simpler Make alternative written in Go
|
# Task - A task runner / simpler Make alternative written in Go
|
||||||
|
|
||||||
|
> We recently released version 2.0.0 of Task. The Taskfile changed a bit.
|
||||||
|
Please, check the [Taskfile versions](TASKFILE_VERSIONS.md) document to see
|
||||||
|
what changed and how to upgrade.
|
||||||
|
|
||||||
Task is a simple tool that allows you to easily run development and build
|
Task is a simple tool that allows you to easily run development and build
|
||||||
tasks. Task is written in Golang, but can be used to develop any language.
|
tasks. Task is written in Golang, but can be used to develop any language.
|
||||||
It aims to be simpler and easier to use then [GNU Make][make].
|
It aims to be simpler and easier to use then [GNU Make][make].
|
||||||
@ -73,6 +77,9 @@ The example below allows compile a Go app and uses [Minify][minify] to concat
|
|||||||
and minify multiple CSS files into a single one.
|
and minify multiple CSS files into a single one.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- go build -v -i main.go
|
- go build -v -i main.go
|
||||||
@ -100,6 +107,9 @@ If you ommit a task name, "default" will be assumed.
|
|||||||
You can specify environment variables that are added when running a command:
|
You can specify environment variables that are added when running a command:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- echo $hallo
|
- echo $hallo
|
||||||
@ -117,6 +127,9 @@ Example:
|
|||||||
Taskfile.yml:
|
Taskfile.yml:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- echo "default"
|
- echo "default"
|
||||||
@ -125,6 +138,7 @@ build:
|
|||||||
Taskfile_linux.yml:
|
Taskfile_linux.yml:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- echo "linux"
|
- echo "linux"
|
||||||
@ -143,6 +157,9 @@ located. But you can easily make the task run in another folder informing
|
|||||||
`dir`:
|
`dir`:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
serve:
|
serve:
|
||||||
dir: public/www
|
dir: public/www
|
||||||
cmds:
|
cmds:
|
||||||
@ -156,6 +173,9 @@ You may have tasks that depends on others. Just pointing them on `deps` will
|
|||||||
make them run automatically before running the parent task:
|
make them run automatically before running the parent task:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
deps: [assets]
|
deps: [assets]
|
||||||
cmds:
|
cmds:
|
||||||
@ -172,6 +192,9 @@ In the above example, `assets` will always run right before `build` if you run
|
|||||||
A task can have only dependencies and no commands to group tasks together:
|
A task can have only dependencies and no commands to group tasks together:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
assets:
|
assets:
|
||||||
deps: [js, css]
|
deps: [js, css]
|
||||||
|
|
||||||
@ -187,9 +210,13 @@ css:
|
|||||||
If there are more than one dependency, they always run in parallel for better
|
If there are more than one dependency, they always run in parallel for better
|
||||||
performance.
|
performance.
|
||||||
|
|
||||||
If you want to pass information to dependencies, you can do that the same manner as you would to [call another task](#calling-another-task):
|
If you want to pass information to dependencies, you can do that the same
|
||||||
|
manner as you would to [call another task](#calling-another-task):
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
default:
|
default:
|
||||||
deps:
|
deps:
|
||||||
- task: echo_sth
|
- task: echo_sth
|
||||||
@ -204,7 +231,6 @@ echo_sth:
|
|||||||
- echo {{.TEXT}}
|
- echo {{.TEXT}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Calling another task
|
### Calling another task
|
||||||
|
|
||||||
When a task has many dependencies, they are executed concurrently. This will
|
When a task has many dependencies, they are executed concurrently. This will
|
||||||
@ -212,6 +238,9 @@ often result in a faster build pipeline. But in some situations you may need
|
|||||||
to call other tasks serially. In this case, just use the following syntax:
|
to call other tasks serially. In this case, just use the following syntax:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
main-task:
|
main-task:
|
||||||
cmds:
|
cmds:
|
||||||
- task: task-to-be-called
|
- task: task-to-be-called
|
||||||
@ -231,6 +260,9 @@ Overriding variables in the called task is as simple as informing `vars`
|
|||||||
attribute:
|
attribute:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
main-task:
|
main-task:
|
||||||
cmds:
|
cmds:
|
||||||
- task: write-file
|
- task: write-file
|
||||||
@ -245,25 +277,15 @@ write-file:
|
|||||||
|
|
||||||
The above syntax is also supported in `deps`.
|
The above syntax is also supported in `deps`.
|
||||||
|
|
||||||
> NOTE: It's also possible to call a task without any param prefixing it
|
|
||||||
with `^`, but this syntax is deprecated:
|
|
||||||
|
|
||||||
```yml
|
|
||||||
a-task:
|
|
||||||
cmds:
|
|
||||||
- ^another-task
|
|
||||||
|
|
||||||
another-task:
|
|
||||||
cmds:
|
|
||||||
- echo "Another task"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prevent unnecessary work
|
### Prevent unnecessary work
|
||||||
|
|
||||||
If a task generates something, you can inform Task the source and generated
|
If a task generates something, you can inform Task the source and generated
|
||||||
files, so Task will prevent to run them if not necessary.
|
files, so Task will prevent to run them if not necessary.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
deps: [js, css]
|
deps: [js, css]
|
||||||
cmds:
|
cmds:
|
||||||
@ -298,6 +320,9 @@ You will probably want to ignore the `.task` folder in your `.gitignore` file
|
|||||||
This feature is still experimental and can change until it's stable.
|
This feature is still experimental and can change until it's stable.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- go build .
|
- go build .
|
||||||
@ -314,6 +339,9 @@ Alternatively, you can inform a sequence of tests as `status`. If no error
|
|||||||
is returned (exit status 0), the task is considered up-to-date:
|
is returned (exit status 0), the task is considered up-to-date:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
generate-files:
|
generate-files:
|
||||||
cmds:
|
cmds:
|
||||||
- mkdir directory
|
- mkdir directory
|
||||||
@ -337,13 +365,14 @@ the tasks is not up-to-date.
|
|||||||
When doing interpolation of variables, Task will look for the below.
|
When doing interpolation of variables, Task will look for the below.
|
||||||
They are listed below in order of importance (e.g. most important first):
|
They are listed below in order of importance (e.g. most important first):
|
||||||
|
|
||||||
|
- Variables declared locally in the task
|
||||||
- Variables given while calling a task from another.
|
- Variables given while calling a task from another.
|
||||||
(See [Calling another task](#calling-another-task) above)
|
(See [Calling another task](#calling-another-task) above)
|
||||||
- Environment variables
|
- Variables declared in the `vars:` option in the `Taskfile`
|
||||||
- Variables declared locally in the task
|
|
||||||
- Variables available in the `Taskvars.yml` file
|
- Variables available in the `Taskvars.yml` file
|
||||||
|
- Environment variables
|
||||||
|
|
||||||
Example of overriding with environment variables:
|
Example of sending parameters with environment variables:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ TASK_VARIABLE=a-value task do-something
|
$ TASK_VARIABLE=a-value task do-something
|
||||||
@ -361,6 +390,9 @@ $ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!
|
|||||||
Example of locally declared vars:
|
Example of locally declared vars:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
print-var:
|
print-var:
|
||||||
cmds:
|
cmds:
|
||||||
echo "{{.VAR}}"
|
echo "{{.VAR}}"
|
||||||
@ -368,6 +400,20 @@ print-var:
|
|||||||
VAR: Hello!
|
VAR: Hello!
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example of global vars in a `Taskfile.yml`:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
vars:
|
||||||
|
GREETING: Hello from Taskfile!
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
greet:
|
||||||
|
cmds:
|
||||||
|
- echo "{{.GREETING}}"
|
||||||
|
```
|
||||||
|
|
||||||
Example of `Taskvars.yml` file:
|
Example of `Taskvars.yml` file:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
@ -376,6 +422,30 @@ DEV_MODE: production
|
|||||||
GIT_COMMIT: {sh: git log -n 1 --format=%h}
|
GIT_COMMIT: {sh: git log -n 1 --format=%h}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Variables expansion
|
||||||
|
|
||||||
|
Variables are expanded 2 times by default. You can change that by setting the
|
||||||
|
`expansions:` option. Change that will be necessary if you compose many
|
||||||
|
variables together:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
expansions: 3
|
||||||
|
|
||||||
|
vars:
|
||||||
|
FOO: foo
|
||||||
|
BAR: bar
|
||||||
|
BAZ: baz
|
||||||
|
FOOBAR: "{{.FOO}}{{.BAR}}"
|
||||||
|
FOOBARBAZ: "{{.FOOBAR}}{{.BAZ}}"
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- echo "{{.FOOBARBAZ}}"
|
||||||
|
```
|
||||||
|
|
||||||
#### Dynamic variables
|
#### Dynamic variables
|
||||||
|
|
||||||
The below syntax (`sh:` prop in a variable) is considered a dynamic variable.
|
The below syntax (`sh:` prop in a variable) is considered a dynamic variable.
|
||||||
@ -383,6 +453,9 @@ The value will be treated as a command and the output assigned. If there is one
|
|||||||
or more trailing newlines, the last newline will be trimmed.
|
or more trailing newlines, the last newline will be trimmed.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- go build -ldflags="-X main.Version={{.GIT_COMMIT}}" main.go
|
- go build -ldflags="-X main.Version={{.GIT_COMMIT}}" main.go
|
||||||
@ -393,20 +466,6 @@ build:
|
|||||||
|
|
||||||
This works for all types of variables.
|
This works for all types of variables.
|
||||||
|
|
||||||
> It's also possible to prefix the variable with `$` to have a dynamic
|
|
||||||
variable, but this is now considered deprecated:
|
|
||||||
|
|
||||||
```yml
|
|
||||||
# Taskvars.yml
|
|
||||||
|
|
||||||
# recommended
|
|
||||||
GIT_COMMIT:
|
|
||||||
sh: git log -n 1 --format=%h
|
|
||||||
|
|
||||||
# deprecated
|
|
||||||
GIT_COMMIT: $git log -n 1 --format=%h
|
|
||||||
```
|
|
||||||
|
|
||||||
### Go's template engine
|
### Go's template engine
|
||||||
|
|
||||||
Task parse commands as [Go's template engine][gotemplate] before executing
|
Task parse commands as [Go's template engine][gotemplate] before executing
|
||||||
@ -416,6 +475,9 @@ All functions by the Go's [sprig lib](http://masterminds.github.io/sprig/)
|
|||||||
are available. The following example gets the current date in a given format:
|
are available. The following example gets the current date in a given format:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
print-date:
|
print-date:
|
||||||
cmds:
|
cmds:
|
||||||
- echo {{now | date "2006-01-02"}}
|
- echo {{now | date "2006-01-02"}}
|
||||||
@ -439,6 +501,9 @@ Task also adds the following functions:
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
print-os:
|
print-os:
|
||||||
cmds:
|
cmds:
|
||||||
- echo '{{OS}} {{ARCH}}'
|
- echo '{{OS}} {{ARCH}}'
|
||||||
@ -458,15 +523,15 @@ enumerated-file:
|
|||||||
{{end}}EOF
|
{{end}}EOF
|
||||||
```
|
```
|
||||||
|
|
||||||
> NOTE: There are some deprecated function names still available: `ToSlash`,
|
|
||||||
`FromSlash` and `ExeExt`. These where changed for consistency with sprig lib.
|
|
||||||
|
|
||||||
### Help
|
### Help
|
||||||
|
|
||||||
Running `task --list` (or `task -l`) lists all tasks with a description.
|
Running `task --list` (or `task -l`) lists all tasks with a description.
|
||||||
The following taskfile:
|
The following taskfile:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
build:
|
build:
|
||||||
desc: Build the go binary.
|
desc: Build the go binary.
|
||||||
cmds:
|
cmds:
|
||||||
@ -499,6 +564,9 @@ Silent mode disables echoing of commands before Task runs it.
|
|||||||
For the following Taskfile:
|
For the following Taskfile:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
echo:
|
echo:
|
||||||
cmds:
|
cmds:
|
||||||
- echo "Print something"
|
- echo "Print something"
|
||||||
@ -522,6 +590,9 @@ There's three ways to enable silent mode:
|
|||||||
* At command level:
|
* At command level:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
echo:
|
echo:
|
||||||
cmds:
|
cmds:
|
||||||
- cmd: echo "Print something"
|
- cmd: echo "Print something"
|
||||||
@ -531,6 +602,9 @@ echo:
|
|||||||
* At task level:
|
* At task level:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
echo:
|
echo:
|
||||||
cmds:
|
cmds:
|
||||||
- echo "Print something"
|
- echo "Print something"
|
||||||
@ -542,6 +616,9 @@ echo:
|
|||||||
If you want to suppress stdout instead, just redirect a command to `/dev/null`:
|
If you want to suppress stdout instead, just redirect a command to `/dev/null`:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
echo:
|
echo:
|
||||||
cmds:
|
cmds:
|
||||||
- echo "This will print nothing" > /dev/null
|
- echo "This will print nothing" > /dev/null
|
||||||
|
91
TASKFILE_VERSIONS.md
Normal file
91
TASKFILE_VERSIONS.md
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
# Taskfile version
|
||||||
|
|
||||||
|
The Taskfile syntax and features changed with time. This document explains what
|
||||||
|
changed on each version and how to upgrade your Taskfile.
|
||||||
|
|
||||||
|
# What the Taskfile version mean
|
||||||
|
|
||||||
|
The Taskfile version follows the Task version. E.g. the change to Taskfile
|
||||||
|
version `2` means that Task `v2.0.0` should be release to support it.
|
||||||
|
|
||||||
|
The `version:` key on Taskfile accepts a semver string, so either `2`, `2.0` or
|
||||||
|
`2.0.0` is accepted. You you choose to use `2.0` Task will not enable future
|
||||||
|
`2.1` features, but if you choose to use `2`, than any `2.x.x` features will be
|
||||||
|
available, but not `3.0.0+`.
|
||||||
|
|
||||||
|
## Version 1
|
||||||
|
|
||||||
|
In the first version of the `Taskfile`, the `version:` key was not available,
|
||||||
|
because the tasks was in the root of the YAML document. Like this:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
echo:
|
||||||
|
cmds:
|
||||||
|
- echo "Hello, World!"
|
||||||
|
```
|
||||||
|
|
||||||
|
The variable priority order was also different:
|
||||||
|
|
||||||
|
1. Call variables
|
||||||
|
2. Environment
|
||||||
|
3. Task variables
|
||||||
|
4. `Taskvars.yml` veriables
|
||||||
|
|
||||||
|
## Version 2.0
|
||||||
|
|
||||||
|
At version 2, we introduced the `version:` key, to allow us to envolve Task
|
||||||
|
with new features without breaking existing Taskfiles. The new syntax is as
|
||||||
|
follows:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
echo:
|
||||||
|
cmds:
|
||||||
|
- echo "Hello, World!"
|
||||||
|
```
|
||||||
|
|
||||||
|
Version 2 not allows you to write global variables directly in the Taskfile,
|
||||||
|
if you don't want to create a `Taskvars.yml`:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
vars:
|
||||||
|
GREETING: Hello, World!
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
greet:
|
||||||
|
cmds:
|
||||||
|
- echo "{{.GREETING}}"
|
||||||
|
```
|
||||||
|
|
||||||
|
The variable priority order changed to the following:
|
||||||
|
|
||||||
|
1. Task variables
|
||||||
|
2. Call variables
|
||||||
|
3. Taskfile variables
|
||||||
|
4. Taskvars file variables
|
||||||
|
5. Environment variables
|
||||||
|
|
||||||
|
A new global option was added to configure the number of variables expansions
|
||||||
|
(which default to 2):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
expansions: 3
|
||||||
|
|
||||||
|
vars:
|
||||||
|
FOO: foo
|
||||||
|
BAR: bar
|
||||||
|
BAZ: baz
|
||||||
|
FOOBAR: "{{.FOO}}{{.BAR}}"
|
||||||
|
FOOBARBAZ: "{{.FOOBAR}}{{.BAZ}}"
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- echo "{{.FOOBARBAZ}}"
|
||||||
|
```
|
Loading…
x
Reference in New Issue
Block a user