From 5601cd8bf1ceb92cb23928aed60807ce17898a64 Mon Sep 17 00:00:00 2001 From: task-bot <106601941+task-bot@users.noreply.github.com> Date: Thu, 6 Apr 2023 00:55:17 +0000 Subject: [PATCH] deploy: a6d57496c2829b3078255c6438b060a285a51de1 --- 404.html | 4 ++-- api/index.html | 4 ++-- assets/js/6476eba6.af576646.js | 1 - assets/js/6476eba6.f5165ba7.js | 1 + ...{runtime~main.41cc59d1.js => runtime~main.41568f2f.js} | 2 +- changelog/index.html | 4 ++-- community/index.html | 4 ++-- contributing/index.html | 4 ++-- donate/index.html | 4 ++-- faq/index.html | 4 ++-- index.html | 4 ++-- installation/index.html | 4 ++-- releasing/index.html | 4 ++-- search/index.html | 4 ++-- styleguide/index.html | 4 ++-- taskfile-versions/index.html | 4 ++-- translate/index.html | 4 ++-- usage/index.html | 8 ++++---- 18 files changed, 34 insertions(+), 34 deletions(-) delete mode 100644 assets/js/6476eba6.af576646.js create mode 100644 assets/js/6476eba6.f5165ba7.js rename assets/js/{runtime~main.41cc59d1.js => runtime~main.41568f2f.js} (98%) diff --git a/404.html b/404.html index af255170..3e840bbd 100644 --- a/404.html +++ b/404.html @@ -10,13 +10,13 @@ - +
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

- + \ No newline at end of file diff --git a/api/index.html b/api/index.html index afdfe380..ce569044 100644 --- a/api/index.html +++ b/api/index.html @@ -10,7 +10,7 @@ - + @@ -20,7 +20,7 @@ variable

ShortFlagTypecmds and everything else will be set to their default values:

tasks:
foo: echo "foo"

foobar:
- echo "foo"
- echo "bar"

baz:
cmd: echo "baz"

Command

AttributeTypeDefaultDescription
cmdstringThe shell command to be executed.
silentboolfalseSkips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected.
taskstringSet this to trigger execution of another task instead of running a command. This cannot be set together with cmd.
varsmap[string]VariableOptional additional variables to be passed to the referenced task. Only relevant when setting task instead of cmd.
ignore_errorboolfalseContinue execution if errors happen while executing the command.
deferstringAlternative 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[]stringAll platformsSpecifies which platforms the command should be run on. Valid GOOS and GOARCH values allowed. Command will be skipped otherwise.
set[]stringSpecify options for the set builtin.
shopt[]stringSpecify option for the shopt builtin.
info

If given as a a string, the value will be assigned to cmd:

tasks:
foo:
cmds:
- echo "foo"
- echo "bar"

Dependency

AttributeTypeDefaultDescription
taskstringThe task to be execute as a dependency.
varsmap[string]VariableOptional additional variables to be passed to this task.
tip

If you don't want to set additional variables, it's enough to declare the dependency as a list of strings (they will be assigned to task):

tasks:
foo:
deps: [foo, bar]

Precondition

AttributeTypeDefaultDescription
shstringCommand to be executed. If a non-zero exit code is returned, the task errors without executing its commands.
msgstringOptional message to print if the precondition isn't met.
tip

If you don't want to set a different message, you can declare a precondition like this and the value will be assigned to sh:

tasks:
foo:
precondition: test -f Taskfile.yml
- + \ No newline at end of file diff --git a/assets/js/6476eba6.af576646.js b/assets/js/6476eba6.af576646.js deleted file mode 100644 index 59bee1f1..00000000 --- a/assets/js/6476eba6.af576646.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktaskfile_dev=self.webpackChunktaskfile_dev||[]).push([[827],{3905:function(e,n,t){t.d(n,{Zo:function(){return d},kt:function(){return k}});var a=t(7294);function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function l(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function s(e){for(var n=1;n=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}var r=a.createContext({}),p=function(e){var n=a.useContext(r),t=n;return e&&(t="function"==typeof e?e(n):s(s({},n),e)),t},d=function(e){var n=p(e.components);return a.createElement(r.Provider,{value:n},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},c=a.forwardRef((function(e,n){var t=e.components,i=e.mdxType,l=e.originalType,r=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),u=p(t),c=i,k=u["".concat(r,".").concat(c)]||u[c]||m[c]||l;return t?a.createElement(k,s(s({ref:n},d),{},{components:t})):a.createElement(k,s({ref:n},d))}));function k(e,n){var t=arguments,i=n&&n.mdxType;if("string"==typeof e||i){var l=t.length,s=new Array(l);s[0]=c;var o={};for(var r in n)hasOwnProperty.call(n,r)&&(o[r]=n[r]);o.originalType=e,o[u]="string"==typeof e?e:i,s[1]=o;for(var p=2;pdefer",id:"doing-task-cleanup-with-defer",level:2},{value:"Go's template engine",id:"gos-template-engine",level:2},{value:"Help",id:"help",level:2},{value:"Display summary of task",id:"display-summary-of-task",level:2},{value:"Task aliases",id:"task-aliases",level:2},{value:"Overriding task name",id:"overriding-task-name",level:2},{value:"Silent mode",id:"silent-mode",level:2},{value:"Dry run mode",id:"dry-run-mode",level:2},{value:"Ignore errors",id:"ignore-errors",level:2},{value:"Output syntax",id:"output-syntax",level:2},{value:"Interactive CLI application",id:"interactive-cli-application",level:2},{value:"Short task syntax",id:"short-task-syntax",level:2},{value:"set and shopt",id:"set-and-shopt",level:2},{value:"Watch tasks",id:"watch-tasks",level:2}],d={toc:p};function u(e){let{components:n,...t}=e;return(0,i.kt)("wrapper",(0,a.Z)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"usage"},"Usage"),(0,i.kt)("h2",{id:"getting-started"},"Getting started"),(0,i.kt)("p",null,"Create a file called ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml")," in the root of your project.\nThe ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds")," attribute should contain the commands of a task.\nThe example below allows compiling a Go app and uses ",(0,i.kt)("a",{parentName:"p",href:"https://esbuild.github.io/"},"esbuild")," to concat\nand minify multiple CSS files into a single one."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - go build -v -i main.go\n\n assets:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"Running the tasks is as simple as running:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"task assets build\n")),(0,i.kt)("p",null,"Task uses ",(0,i.kt)("a",{parentName:"p",href:"https://mvdan.cc/sh/"},"mvdan.cc/sh"),", a native Go sh\ninterpreter. So you can write sh/bash commands, and it will work even on\nWindows, where ",(0,i.kt)("inlineCode",{parentName:"p"},"sh")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"bash")," are usually not available. Just remember any\nexecutable called must be available by the OS or in PATH."),(0,i.kt)("p",null,'If you omit a task name, "default" will be assumed.'),(0,i.kt)("h2",{id:"supported-file-names"},"Supported file names"),(0,i.kt)("p",null,"Task will look for the following file names, in order of priority:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Taskfile.yml"),(0,i.kt)("li",{parentName:"ul"},"Taskfile.yaml"),(0,i.kt)("li",{parentName:"ul"},"Taskfile.dist.yml"),(0,i.kt)("li",{parentName:"ul"},"Taskfile.dist.yaml")),(0,i.kt)("p",null,"The intention of having the ",(0,i.kt)("inlineCode",{parentName:"p"},".dist")," variants is to allow projects to have one\ncommitted version (",(0,i.kt)("inlineCode",{parentName:"p"},".dist"),") while still allowing individual users to override\nthe Taskfile by adding an additional ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml")," (which would be on\n",(0,i.kt)("inlineCode",{parentName:"p"},".gitignore"),")."),(0,i.kt)("h3",{id:"running-a-taskfile-from-a-subdirectory"},"Running a Taskfile from a subdirectory"),(0,i.kt)("p",null,"If a Taskfile cannot be found in the current working directory, it will walk up\nthe file tree until it finds one (similar to how ",(0,i.kt)("inlineCode",{parentName:"p"},"git")," works). When running Task\nfrom a subdirectory like this, it will behave as if you ran it from the\ndirectory containing the Taskfile."),(0,i.kt)("p",null,"You can use this functionality along with the special ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.USER_WORKING_DIR}}"),"\nvariable to create some very useful reusable tasks. For example, if you have a\nmonorepo with directories for each microservice, you can ",(0,i.kt)("inlineCode",{parentName:"p"},"cd")," into a\nmicroservice directory and run a task command to bring it up without having to\ncreate multiple tasks or Taskfiles with identical content. For example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n up:\n dir: '{{.USER_WORKING_DIR}}'\n preconditions:\n - test -f docker-compose.yml\n cmds:\n - docker-compose up -d\n")),(0,i.kt)("p",null,"In this example, we can run ",(0,i.kt)("inlineCode",{parentName:"p"},"cd ")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"task up")," and as long as the\n",(0,i.kt)("inlineCode",{parentName:"p"},"")," directory contains a ",(0,i.kt)("inlineCode",{parentName:"p"},"docker-compose.yml"),", the Docker composition will be\nbrought up."),(0,i.kt)("h3",{id:"running-a-global-taskfile"},"Running a global Taskfile"),(0,i.kt)("p",null,"If you call Task with the ",(0,i.kt)("inlineCode",{parentName:"p"},"--global")," (alias ",(0,i.kt)("inlineCode",{parentName:"p"},"-g"),") flag, it will look for your\nhome directory instead of your working directory. In short, Task will look for\na Taskfile on either ",(0,i.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yml")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yaml")," paths."),(0,i.kt)("p",null,"This is useful to have automation that you can run from anywhere in your\nsystem!"),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"When running your global Taskfile with ",(0,i.kt)("inlineCode",{parentName:"p"},"-g"),", tasks will run on ",(0,i.kt)("inlineCode",{parentName:"p"},"$HOME")," by\ndefault, and not on your working directory!"),(0,i.kt)("p",{parentName:"admonition"},"As mentioned in the previous section, the ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.USER_WORKING_DIR}}")," special\nvariable can be very handy here to run stuff on the directory you're calling\n",(0,i.kt)("inlineCode",{parentName:"p"},"task -g")," from."),(0,i.kt)("pre",{parentName:"admonition"},(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n from-home:\n cmds:\n - pwd\n\n from-working-directory:\n dir: '{{.USER_WORKING_DIR}}'\n cmds:\n - pwd\n"))),(0,i.kt)("h2",{id:"environment-variables"},"Environment variables"),(0,i.kt)("h3",{id:"task"},"Task"),(0,i.kt)("p",null,"You can use ",(0,i.kt)("inlineCode",{parentName:"p"},"env")," to set custom environment variables for a specific task:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n greet:\n cmds:\n - echo $GREETING\n env:\n GREETING: Hey, there!\n")),(0,i.kt)("p",null,"Additionally, you can set global environment variables that will be available\nto all tasks:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nenv:\n GREETING: Hey, there!\n\ntasks:\n greet:\n cmds:\n - echo $GREETING\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"env")," supports expansion and retrieving output from a shell command\njust like variables, as you can see in the ",(0,i.kt)("a",{parentName:"p",href:"#variables"},"Variables")," section.")),(0,i.kt)("h3",{id:"env-files"},".env files"),(0,i.kt)("p",null,"You can also ask Task to include ",(0,i.kt)("inlineCode",{parentName:"p"},".env")," like files by using the ",(0,i.kt)("inlineCode",{parentName:"p"},"dotenv:"),"\nsetting:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash",metastring:'title=".env"',title:'".env"'},"KEYNAME=VALUE\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash",metastring:'title="testing/.env"',title:'"testing/.env"'},"ENDPOINT=testing.com\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml",metastring:'title="Taskfile.yml"',title:'"Taskfile.yml"'},"version: '3'\n\nenv:\n ENV: testing\n\ndotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']\n\ntasks:\n greet:\n cmds:\n - echo \"Using $KEYNAME and endpoint $ENDPOINT\"\n")),(0,i.kt)("p",null,"Dotenv files can also be specified at the task level:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nenv:\n ENV: testing\n\ntasks:\n greet:\n dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']\n cmds:\n - echo \"Using $KEYNAME and endpoint $ENDPOINT\"\n")),(0,i.kt)("p",null,"Environment variables specified explicitly at the task-level will override\nvariables defined in dotfiles:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nenv:\n ENV: testing\n\ntasks:\n greet:\n dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']\n env:\n KEYNAME: DIFFERENT_VALUE\n cmds:\n - echo \"Using $KEYNAME and endpoint $ENDPOINT\"\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Please note that you are not currently able to use the ",(0,i.kt)("inlineCode",{parentName:"p"},"dotenv")," key inside included Taskfiles.")),(0,i.kt)("h2",{id:"including-other-taskfiles"},"Including other Taskfiles"),(0,i.kt)("p",null,"If you want to share tasks between different projects (Taskfiles), you can use\nthe importing mechanism to include other Taskfiles using the ",(0,i.kt)("inlineCode",{parentName:"p"},"includes")," keyword:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n docs: ./documentation # will look for ./documentation/Taskfile.yml\n docker: ./DockerTasks.yml\n")),(0,i.kt)("p",null,"The tasks described in the given Taskfiles will be available with the informed\nnamespace. So, you'd call ",(0,i.kt)("inlineCode",{parentName:"p"},"task docs:serve")," to run the ",(0,i.kt)("inlineCode",{parentName:"p"},"serve")," task from\n",(0,i.kt)("inlineCode",{parentName:"p"},"documentation/Taskfile.yml")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"task docker:build")," to run the ",(0,i.kt)("inlineCode",{parentName:"p"},"build")," task\nfrom the ",(0,i.kt)("inlineCode",{parentName:"p"},"DockerTasks.yml")," file."),(0,i.kt)("p",null,"Relative paths are resolved relative to the directory containing the including Taskfile."),(0,i.kt)("h3",{id:"os-specific-taskfiles"},"OS-specific Taskfiles"),(0,i.kt)("p",null,"With ",(0,i.kt)("inlineCode",{parentName:"p"},"version: '2'"),", task automatically includes any ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_{{OS}}.yml"),"\nif it exists (for example: ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_windows.yml"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_linux.yml")," or\n",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_darwin.yml"),"). Since this behavior was a bit too implicit, it\nwas removed on version 3, but you still can have a similar behavior by\nexplicitly importing these files:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n build: ./Taskfile_{{OS}}.yml\n")),(0,i.kt)("h3",{id:"directory-of-included-taskfile"},"Directory of included Taskfile"),(0,i.kt)("p",null,"By default, included Taskfile's tasks are run in the current directory, even\nif the Taskfile is in another directory, but you can force its tasks to run\nin another directory by using this alternative syntax:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n docs:\n taskfile: ./docs/Taskfile.yml\n dir: ./docs\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The included Taskfiles must be using the same schema version as the main\nTaskfile uses.")),(0,i.kt)("h3",{id:"optional-includes"},"Optional includes"),(0,i.kt)("p",null,"Includes marked as optional will allow Task to continue execution as normal if\nthe included file is missing."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n tests:\n taskfile: ./tests/Taskfile.yml\n optional: true\n\ntasks:\n greet:\n cmds:\n - echo \"This command can still be successfully executed if ./tests/Taskfile.yml does not exist\"\n")),(0,i.kt)("h3",{id:"internal-includes"},"Internal includes"),(0,i.kt)("p",null,"Includes marked as internal will set all the tasks of the included file to be\ninternal as well (see the ",(0,i.kt)("a",{parentName:"p",href:"#internal-tasks"},"Internal tasks")," section below).\nThis is useful when including utility tasks that are not intended to be used\ndirectly by the user."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n tests:\n taskfile: ./taskfiles/Utils.yml\n internal: true\n")),(0,i.kt)("h3",{id:"vars-of-included-taskfiles"},"Vars of included Taskfiles"),(0,i.kt)("p",null,"You can also specify variables when including a Taskfile. This may be useful\nfor having reusable Taskfile that can be tweaked or even included more than once:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n backend:\n taskfile: ./taskfiles/Docker.yml\n vars:\n DOCKER_IMAGE: backend_image\n\n frontend:\n taskfile: ./taskfiles/Docker.yml\n vars:\n DOCKER_IMAGE: frontend_image\n")),(0,i.kt)("h3",{id:"namespace-aliases"},"Namespace aliases"),(0,i.kt)("p",null,"When including a Taskfile, you can give the namespace a list of ",(0,i.kt)("inlineCode",{parentName:"p"},"aliases"),".\nThis works in the same way as ",(0,i.kt)("a",{parentName:"p",href:"#task-aliases"},"task aliases")," and can be used\ntogether to create shorter and easier-to-type commands."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n generate:\n taskfile: ./taskfiles/Generate.yml\n aliases: [gen]\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Vars declared in the included Taskfile have preference over the\nvariables in the including Taskfile! If you want a variable in an included Taskfile to be overridable,\nuse the ",(0,i.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/defaults.html"},"default function"),":\n",(0,i.kt)("inlineCode",{parentName:"p"},"MY_VAR: '{{.MY_VAR | default \"my-default-value\"}}'"),".")),(0,i.kt)("h2",{id:"internal-tasks"},"Internal tasks"),(0,i.kt)("p",null,"Internal tasks are tasks that cannot be called directly by the user. They will\nnot appear in the output when running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --list|--list-all"),". Other tasks may\ncall internal tasks in the usual way. This is useful for creating reusable,\nfunction-like tasks that have no useful purpose on the command line."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-image-1:\n cmds:\n - task: build-image\n vars:\n DOCKER_IMAGE: image-1\n\n build-image:\n internal: true\n cmds:\n - docker build -t {{.DOCKER_IMAGE}} .\n")),(0,i.kt)("h2",{id:"task-directory"},"Task directory"),(0,i.kt)("p",null,"By default, tasks will be executed in the directory where the Taskfile is\nlocated. But you can easily make the task run in another folder, informing\n",(0,i.kt)("inlineCode",{parentName:"p"},"dir"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n serve:\n dir: public/www\n cmds:\n # run http server\n - caddy\n")),(0,i.kt)("p",null,"If the directory does not exist, ",(0,i.kt)("inlineCode",{parentName:"p"},"task")," creates it."),(0,i.kt)("h2",{id:"task-dependencies"},"Task dependencies"),(0,i.kt)("blockquote",null,(0,i.kt)("p",{parentName:"blockquote"},"Dependencies run in parallel, so dependencies of a task should not depend one\nanother. If you want to force tasks to run serially, take a look at the\n",(0,i.kt)("a",{parentName:"p",href:"#calling-another-task"},"Calling Another Task")," section below.")),(0,i.kt)("p",null,"You may have tasks that depend on others. Just pointing them on ",(0,i.kt)("inlineCode",{parentName:"p"},"deps")," will\nmake them run automatically before running the parent task:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n deps: [assets]\n cmds:\n - go build -v -i main.go\n\n assets:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"In the above example, ",(0,i.kt)("inlineCode",{parentName:"p"},"assets")," will always run right before ",(0,i.kt)("inlineCode",{parentName:"p"},"build")," if you run\n",(0,i.kt)("inlineCode",{parentName:"p"},"task build"),"."),(0,i.kt)("p",null,"A task can have only dependencies and no commands to group tasks together:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n assets:\n deps: [js, css]\n\n js:\n cmds:\n - esbuild --bundle --minify js/index.js > public/bundle.js\n\n css:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"If there is more than one dependency, they always run in parallel for better\nperformance."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also make the tasks given by the command line run in parallel by\nusing the ",(0,i.kt)("inlineCode",{parentName:"p"},"--parallel")," flag (alias ",(0,i.kt)("inlineCode",{parentName:"p"},"-p"),"). Example: ",(0,i.kt)("inlineCode",{parentName:"p"},"task --parallel js css"),".")),(0,i.kt)("p",null,"If you want to pass information to dependencies, you can do that the same\nmanner as you would to ",(0,i.kt)("a",{parentName:"p",href:"#calling-another-task"},"call another task"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n default:\n deps:\n - task: echo_sth\n vars: {TEXT: "before 1"}\n - task: echo_sth\n vars: {TEXT: "before 2"}\n cmds:\n - echo "after"\n\n echo_sth:\n cmds:\n - echo {{.TEXT}}\n')),(0,i.kt)("h2",{id:"platform-specific-tasks-and-commands"},"Platform specific tasks and commands"),(0,i.kt)("p",null,"If you want to restrict the running of tasks to explicit platforms, this can be achieved\nusing the ",(0,i.kt)("inlineCode",{parentName:"p"},"platforms:")," key. Tasks can be restricted to a specific OS, architecture or a\ncombination of both.\nOn a mismatch, the task or command will be skipped, and no error will be thrown."),(0,i.kt)("p",null,"The values allowed as OS or Arch are valid ",(0,i.kt)("inlineCode",{parentName:"p"},"GOOS")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"GOARCH")," values, as\ndefined by the Go language\n",(0,i.kt)("a",{parentName:"p",href:"https://github.com/golang/go/blob/master/src/go/build/syslist.go"},"here"),"."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"build-windows")," task below will run only on Windows, and on any architecture:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-windows:\n platforms: [windows]\n cmds:\n - echo 'Running command on Windows'\n")),(0,i.kt)("p",null,"This can be restricted to a specific architecture as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-windows-amd64:\n platforms: [windows/amd64]\n cmds:\n - echo 'Running command on Windows (amd64)'\n")),(0,i.kt)("p",null,"It is also possible to restrict the task to specific architectures:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-amd64:\n platforms: [amd64]\n cmds:\n - echo 'Running command on amd64'\n")),(0,i.kt)("p",null,"Multiple platforms can be specified as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n platforms: [windows/amd64, darwin]\n cmds:\n - echo 'Running command on Windows (amd64) and macOS'\n")),(0,i.kt)("p",null,"Individual commands can also be restricted to specific platforms:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - cmd: echo 'Running command on Windows (amd64) and macOS'\n platforms: [windows/amd64, darwin]\n - cmd: echo 'Running on all platforms'\n")),(0,i.kt)("h2",{id:"calling-another-task"},"Calling another task"),(0,i.kt)("p",null,"When a task has many dependencies, they are executed concurrently. This will\noften result in a faster build pipeline. However, in some situations, you may need\nto call other tasks serially. In this case, use the following syntax:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n main-task:\n cmds:\n - task: task-to-be-called\n - task: another-task\n - echo "Both done"\n\n task-to-be-called:\n cmds:\n - echo "Task to be called"\n\n another-task:\n cmds:\n - echo "Another task"\n')),(0,i.kt)("p",null,"Overriding variables in the called task is as simple as informing ",(0,i.kt)("inlineCode",{parentName:"p"},"vars"),"\nattribute:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n greet:\n vars:\n RECIPIENT: \'{{default "World" .RECIPIENT}}\'\n cmds:\n - echo "Hello, {{.RECIPIENT}}!"\n\n greet-pessimistically:\n cmds:\n - task: greet\n vars: {RECIPIENT: "Cruel World"}\n')),(0,i.kt)("p",null,"The above syntax is also supported in ",(0,i.kt)("inlineCode",{parentName:"p"},"deps"),"."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"NOTE: If you want to call a task declared in the root Taskfile from within an\n",(0,i.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"included Taskfile"),", add a leading ",(0,i.kt)("inlineCode",{parentName:"p"},":")," like this:\n",(0,i.kt)("inlineCode",{parentName:"p"},"task: :task-name"),".")),(0,i.kt)("h2",{id:"prevent-unnecessary-work"},"Prevent unnecessary work"),(0,i.kt)("h3",{id:"by-fingerprinting-locally-generated-files-and-their-sources"},"By fingerprinting locally generated files and their sources"),(0,i.kt)("p",null,"If a task generates something, you can inform Task the source and generated\nfiles, so Task will prevent running them if not necessary."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n deps: [js, css]\n cmds:\n - go build -v -i main.go\n\n js:\n cmds:\n - esbuild --bundle --minify js/index.js > public/bundle.js\n sources:\n - src/js/**/*.js\n generates:\n - public/bundle.js\n\n css:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n sources:\n - src/css/**/*.css\n generates:\n - public/bundle.css\n")),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"sources")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"generates")," can be files or file patterns. When given,\nTask will compare the checksum of the source files to determine if it's\nnecessary to run the task. If not, it will just print a message like\n",(0,i.kt)("inlineCode",{parentName:"p"},'Task "js" is up to date'),"."),(0,i.kt)("p",null,"If you prefer this check to be made by the modification timestamp of the files,\ninstead of its checksum (content), just set the ",(0,i.kt)("inlineCode",{parentName:"p"},"method")," property to ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamp"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - go build .\n sources:\n - ./*.go\n generates:\n - app{{exeExt}}\n method: timestamp\n")),(0,i.kt)("p",null,"In situations where you need more flexibility the ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," keyword can be used.\nYou can even combine the two. See the documentation for\n",(0,i.kt)("a",{parentName:"p",href:"#using-programmatic-checks-to-indicate-a-task-is-up-to-date"},"status")," for an\nexample."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"By default, task stores checksums on a local ",(0,i.kt)("inlineCode",{parentName:"p"},".task")," directory in the project's\ndirectory. Most of the time, you'll want to have this directory on ",(0,i.kt)("inlineCode",{parentName:"p"},".gitignore"),"\n(or equivalent) so it isn't committed. (If you have a task for code generation\nthat is committed it may make sense to commit the checksum of that task as\nwell, though)."),(0,i.kt)("p",{parentName:"admonition"},"If you want these files to be stored in another directory, you can set a\n",(0,i.kt)("inlineCode",{parentName:"p"},"TASK_TEMP_DIR")," environment variable in your machine. It can contain a relative\npath like ",(0,i.kt)("inlineCode",{parentName:"p"},"tmp/task")," that will be interpreted as relative to the project\ndirectory, or an absolute or home path like ",(0,i.kt)("inlineCode",{parentName:"p"},"/tmp/.task")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"~/.task"),"\n(subdirectories will be created for each project)."),(0,i.kt)("pre",{parentName:"admonition"},(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"export TASK_TEMP_DIR='~/.task'\n"))),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Each task has only one checksum stored for its ",(0,i.kt)("inlineCode",{parentName:"p"},"sources"),". If you want\nto distinguish a task by any of its input variables, you can add those\nvariables as part of the task's label, and it will be considered a different\ntask."),(0,i.kt)("p",{parentName:"admonition"},"This is useful if you want to run a task once for each distinct set of\ninputs until the sources actually change. For example, if the sources depend\non the value of a variable, or you if you want the task to rerun if some arguments\nchange even if the source has not.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The method ",(0,i.kt)("inlineCode",{parentName:"p"},"none")," skips any validation and always run the task.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"For the ",(0,i.kt)("inlineCode",{parentName:"p"},"checksum")," (default) or ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamp")," method to work, it is only necessary to\ninform the source files.\nWhen the ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamp")," method is used, the last time of the running the task is considered as a generate.")),(0,i.kt)("h3",{id:"using-programmatic-checks-to-indicate-a-task-is-up-to-date"},"Using programmatic checks to indicate a task is up to date."),(0,i.kt)("p",null,"Alternatively, you can inform a sequence of tests as ",(0,i.kt)("inlineCode",{parentName:"p"},"status"),". If no error\nis returned (exit status 0), the task is considered up-to-date:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n generate-files:\n cmds:\n - mkdir directory\n - touch directory/file1.txt\n - touch directory/file2.txt\n # test existence of files\n status:\n - test -d directory\n - test -f directory/file1.txt\n - test -f directory/file2.txt\n")),(0,i.kt)("p",null,"Normally, you would use ",(0,i.kt)("inlineCode",{parentName:"p"},"sources")," in combination with\n",(0,i.kt)("inlineCode",{parentName:"p"},"generates")," - but for tasks that generate remote artifacts (Docker images,\ndeploys, CD releases) the checksum source and timestamps require either\naccess to the artifact or for an out-of-band refresh of the ",(0,i.kt)("inlineCode",{parentName:"p"},".checksum"),"\nfingerprint file."),(0,i.kt)("p",null,"Two special variables ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.CHECKSUM}}")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.TIMESTAMP}}")," are available\nfor interpolation within ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," commands, depending on the method assigned\nto fingerprint the sources. Only ",(0,i.kt)("inlineCode",{parentName:"p"},"source")," globs are fingerprinted."),(0,i.kt)("p",null,"Note that the ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.TIMESTAMP}}"),' variable is a "live" Go ',(0,i.kt)("inlineCode",{parentName:"p"},"time.Time")," struct, and\ncan be formatted using any of the methods that ",(0,i.kt)("inlineCode",{parentName:"p"},"time.Time")," responds to."),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"https://golang.org/pkg/time/"},"the Go Time documentation")," for more information."),(0,i.kt)("p",null,"You can use ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"-f")," if you want to force a task to run even when\nup-to-date."),(0,i.kt)("p",null,"Also, ",(0,i.kt)("inlineCode",{parentName:"p"},"task --status [tasks]...")," will exit with a non-zero exit code if any of\nthe tasks are not up-to-date."),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"status")," can be combined with the ",(0,i.kt)("a",{parentName:"p",href:"#by-fingerprinting-locally-generated-files-and-their-sources"},"fingerprinting"),"\nto have a task run if either the the source/generated artifacts changes, or the\nprogrammatic check fails:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:prod:\n desc: Build for production usage.\n cmds:\n - composer install\n # Run this task if source files changes.\n sources:\n - composer.json\n - composer.lock\n generates:\n - ./vendor/composer/installed.json\n - ./vendor/autoload.php\n # But also run the task if the last build was not a production build.\n status:\n - grep -q '\"dev\": false' ./vendor/composer/installed.json\n")),(0,i.kt)("h3",{id:"using-programmatic-checks-to-cancel-the-execution-of-a-task-and-its-dependencies"},"Using programmatic checks to cancel the execution of a task and its dependencies"),(0,i.kt)("p",null,"In addition to ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," checks, ",(0,i.kt)("inlineCode",{parentName:"p"},"preconditions")," checks are\nthe logical inverse of ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," checks. That is, if you need a certain set of\nconditions to be ",(0,i.kt)("em",{parentName:"p"},"true")," you can use the ",(0,i.kt)("inlineCode",{parentName:"p"},"preconditions")," stanza.\n",(0,i.kt)("inlineCode",{parentName:"p"},"preconditions")," are similar to ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," lines, except they support ",(0,i.kt)("inlineCode",{parentName:"p"},"sh"),"\nexpansion, and they SHOULD all return 0."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n generate-files:\n cmds:\n - mkdir directory\n - touch directory/file1.txt\n - touch directory/file2.txt\n # test existence of files\n preconditions:\n - test -f .env\n - sh: "[ 1 = 0 ]"\n msg: "One doesn\'t equal Zero, Halting"\n')),(0,i.kt)("p",null,"Preconditions can set specific failure messages that can tell\na user what steps to take using the ",(0,i.kt)("inlineCode",{parentName:"p"},"msg")," field."),(0,i.kt)("p",null,"If a task has a dependency on a sub-task with a precondition, and that\nprecondition is not met - the calling task will fail. Note that a task\nexecuted with a failing precondition will not run unless ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," is\ngiven."),(0,i.kt)("p",null,"Unlike ",(0,i.kt)("inlineCode",{parentName:"p"},"status"),", which will skip a task if it is up to date and continue\nexecuting tasks that depend on it, a ",(0,i.kt)("inlineCode",{parentName:"p"},"precondition")," will fail a task, along\nwith any other tasks that depend on it."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n task-will-fail:\n preconditions:\n - sh: "exit 1"\n\n task-will-also-fail:\n deps:\n - task-will-fail\n\n task-will-still-fail:\n cmds:\n - task: task-will-fail\n - echo "I will not run"\n')),(0,i.kt)("h3",{id:"limiting-when-tasks-run"},"Limiting when tasks run"),(0,i.kt)("p",null,"If a task executed by multiple ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds")," or multiple ",(0,i.kt)("inlineCode",{parentName:"p"},"deps")," you can control\nwhen it is executed using ",(0,i.kt)("inlineCode",{parentName:"p"},"run"),". ",(0,i.kt)("inlineCode",{parentName:"p"},"run")," can also be set at the root\nof the Taskfile to change the behavior of all the tasks unless explicitly\noverridden."),(0,i.kt)("p",null,"Supported values for ",(0,i.kt)("inlineCode",{parentName:"p"},"run"),":"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"always")," (default) always attempt to invoke the task regardless of the\nnumber of previous executions"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"once")," only invoke this task once regardless of the number of references"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"when_changed")," only invokes the task once for each unique set of variables\npassed into the task")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - task: generate-file\n vars: { CONTENT: '1' }\n - task: generate-file\n vars: { CONTENT: '2' }\n - task: generate-file\n vars: { CONTENT: '2' }\n\n generate-file:\n run: when_changed\n deps:\n - install-deps\n cmds:\n - echo {{.CONTENT}}\n\n install-deps:\n run: once\n cmds:\n - sleep 5 # long operation like installing packages\n")),(0,i.kt)("h2",{id:"variables"},"Variables"),(0,i.kt)("p",null,"When doing interpolation of variables, Task will look for the below.\nThey are listed below in order of importance (i.e. most important first):"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Variables declared in the task definition"),(0,i.kt)("li",{parentName:"ul"},"Variables given while calling a task from another\n(See ",(0,i.kt)("a",{parentName:"li",href:"#calling-another-task"},"Calling another task")," above)"),(0,i.kt)("li",{parentName:"ul"},"Variables of the ",(0,i.kt)("a",{parentName:"li",href:"#including-other-taskfiles"},"included Taskfile")," (when the task is included)"),(0,i.kt)("li",{parentName:"ul"},"Variables of the ",(0,i.kt)("a",{parentName:"li",href:"#vars-of-included-taskfiles"},"inclusion of the Taskfile")," (when the task is included)"),(0,i.kt)("li",{parentName:"ul"},"Global variables (those declared in the ",(0,i.kt)("inlineCode",{parentName:"li"},"vars:")," option in the Taskfile)"),(0,i.kt)("li",{parentName:"ul"},"Environment variables")),(0,i.kt)("p",null,"Example of sending parameters with environment variables:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ TASK_VARIABLE=a-value task do-something\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"A special variable ",(0,i.kt)("inlineCode",{parentName:"p"},".TASK")," is always available containing the task name.")),(0,i.kt)("p",null,"Since some shells do not support the above syntax to set environment variables\n(Windows) tasks also accept a similar style when not at the beginning of\nthe command."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},'$ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!"\n')),(0,i.kt)("p",null,"Example of locally declared vars:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n print-var:\n cmds:\n - echo \"{{.VAR}}\"\n vars:\n VAR: Hello!\n")),(0,i.kt)("p",null,"Example of global vars in a ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nvars:\n GREETING: Hello from Taskfile!\n\ntasks:\n greet:\n cmds:\n - echo \"{{.GREETING}}\"\n")),(0,i.kt)("h3",{id:"dynamic-variables"},"Dynamic variables"),(0,i.kt)("p",null,"The below syntax (",(0,i.kt)("inlineCode",{parentName:"p"},"sh:")," prop in a variable) is considered a dynamic variable.\nThe value will be treated as a command and the output assigned. If there are one\nor more trailing newlines, the last newline will be trimmed."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - go build -ldflags=\"-X main.Version={{.GIT_COMMIT}}\" main.go\n vars:\n GIT_COMMIT:\n sh: git log -n 1 --format=%h\n")),(0,i.kt)("p",null,"This works for all types of variables."),(0,i.kt)("h2",{id:"forwarding-cli-arguments-to-commands"},"Forwarding CLI arguments to commands"),(0,i.kt)("p",null,"If ",(0,i.kt)("inlineCode",{parentName:"p"},"--")," is given in the CLI, all following parameters are added to a\nspecial ",(0,i.kt)("inlineCode",{parentName:"p"},".CLI_ARGS")," variable. This is useful to forward arguments to another\ncommand."),(0,i.kt)("p",null,"The below example will run ",(0,i.kt)("inlineCode",{parentName:"p"},"yarn install"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ task yarn -- install\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n yarn:\n cmds:\n - yarn {{.CLI_ARGS}}\n")),(0,i.kt)("h2",{id:"doing-task-cleanup-with-defer"},"Doing task cleanup with ",(0,i.kt)("inlineCode",{parentName:"h2"},"defer")),(0,i.kt)("p",null,"With the ",(0,i.kt)("inlineCode",{parentName:"p"},"defer")," keyword, it's possible to schedule cleanup to be run once\nthe task finishes. The difference with just putting it as the last command is\nthat this command will run even when the task fails."),(0,i.kt)("p",null,"In the example below, ",(0,i.kt)("inlineCode",{parentName:"p"},"rm -rf tmpdir/")," will run even if the third command fails:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - mkdir -p tmpdir/\n - defer: rm -rf tmpdir/\n - echo 'Do work on tmpdir/'\n")),(0,i.kt)("p",null,"If you want to move the cleanup command into another task, that is possible as\nwell:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - mkdir -p tmpdir/\n - defer: { task: cleanup }\n - echo 'Do work on tmpdir/'\n\n cleanup: rm -rf tmpdir/\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Due to the nature of how the\n",(0,i.kt)("a",{parentName:"p",href:"https://go.dev/tour/flowcontrol/13"},"Go's own ",(0,i.kt)("inlineCode",{parentName:"a"},"defer")," work"),", the deferred\ncommands are executed in the reverse order if you schedule multiple of them.")),(0,i.kt)("h2",{id:"gos-template-engine"},"Go's template engine"),(0,i.kt)("p",null,"Task parse commands as ",(0,i.kt)("a",{parentName:"p",href:"https://golang.org/pkg/text/template/"},"Go's template engine")," before executing\nthem. Variables are accessible through dot syntax (",(0,i.kt)("inlineCode",{parentName:"p"},".VARNAME"),")."),(0,i.kt)("p",null,"All functions by the Go's ",(0,i.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/"},"slim-sprig lib"),"\nare available. The following example gets the current date in a given format:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n print-date:\n cmds:\n - echo {{now | date \"2006-01-02\"}}\n")),(0,i.kt)("p",null,"Task also adds the following functions:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"OS"),': Returns the operating system. Possible values are "windows", "linux",\n"darwin" (macOS) and "freebsd".'),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"ARCH"),': return the architecture Task was compiled to: "386", "amd64", "arm"\nor "s390x".'),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"splitLines"),": Splits Unix (\\n) and Windows (\\r\\n) styled newlines."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"catLines"),": Replaces Unix (\\n) and Windows (\\r\\n) styled newlines with a space."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"toSlash"),": Does nothing on Unix, but on Windows converts a string from ",(0,i.kt)("inlineCode",{parentName:"li"},"\\"),"\npath format to ",(0,i.kt)("inlineCode",{parentName:"li"},"/"),"."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"fromSlash"),": Opposite of ",(0,i.kt)("inlineCode",{parentName:"li"},"toSlash"),". Does nothing on Unix, but on Windows\nconverts a string from ",(0,i.kt)("inlineCode",{parentName:"li"},"/")," path format to ",(0,i.kt)("inlineCode",{parentName:"li"},"\\"),"."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"exeExt"),": Returns the right executable extension for the current OS\n(",(0,i.kt)("inlineCode",{parentName:"li"},'".exe"')," for Windows, ",(0,i.kt)("inlineCode",{parentName:"li"},'""')," for others)."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"shellQuote"),": Quotes a string to make it safe for use in shell scripts.\nTask uses ",(0,i.kt)("a",{parentName:"li",href:"https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/syntax#Quote"},"this Go function"),"\nfor this. The Bash dialect is assumed."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"splitArgs"),": Splits a string as if it were a command's arguments.\nTask uses ",(0,i.kt)("a",{parentName:"li",href:"https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/shell#Fields"},"this Go function"))),(0,i.kt)("p",null,"Example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n print-os:\n cmds:\n - echo '{{OS}} {{ARCH}}'\n - echo '{{if eq OS \"windows\"}}windows-command{{else}}unix-command{{end}}'\n # This will be path/to/file on Unix but path\\to\\file on Windows\n - echo '{{fromSlash \"path/to/file\"}}'\n enumerated-file:\n vars:\n CONTENT: |\n foo\n bar\n cmds:\n - |\n cat << EOF > output.txt\n {{range $i, $line := .CONTENT | splitLines -}}\n {{printf \"%3d\" $i}}: {{$line}}\n {{end}}EOF\n")),(0,i.kt)("h2",{id:"help"},"Help"),(0,i.kt)("p",null,"Running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --list")," (or ",(0,i.kt)("inlineCode",{parentName:"p"},"task -l"),") lists all tasks with a description.\nThe following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n desc: Build the go binary.\n cmds:\n - go build -v -i main.go\n\n test:\n desc: Run all the go tests.\n cmds:\n - go test -race ./...\n\n js:\n cmds:\n - esbuild --bundle --minify js/index.js > public/bundle.js\n\n css:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"would print the following output:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"* build: Build the go binary.\n* test: Run all the go tests.\n")),(0,i.kt)("p",null,"If you want to see all tasks, there's a ",(0,i.kt)("inlineCode",{parentName:"p"},"--list-all")," (alias ",(0,i.kt)("inlineCode",{parentName:"p"},"-a"),") flag as well."),(0,i.kt)("h2",{id:"display-summary-of-task"},"Display summary of task"),(0,i.kt)("p",null,"Running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --summary task-name")," will show a summary of a task.\nThe following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n release:\n deps: [build]\n summary: |\n Release your project to github\n\n It will build your project before starting the release.\n Please make sure that you have set GITHUB_TOKEN before starting.\n cmds:\n - your-release-tool\n\n build:\n cmds:\n - your-build-tool\n")),(0,i.kt)("p",null,"with running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --summary release")," would print the following output:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"task: release\n\nRelease your project to github\n\nIt will build your project before starting the release.\nPlease make sure that you have set GITHUB_TOKEN before starting.\n\ndependencies:\n - build\n\ncommands:\n - your-release-tool\n")),(0,i.kt)("p",null,"If a summary is missing, the description will be printed.\nIf the task does not have a summary or a description, a warning is printed."),(0,i.kt)("p",null,"Please note: ",(0,i.kt)("em",{parentName:"p"},"showing the summary will not execute the command"),"."),(0,i.kt)("h2",{id:"task-aliases"},"Task aliases"),(0,i.kt)("p",null,"Aliases are alternative names for tasks. They can be used to make it easier and\nquicker to run tasks with long or hard-to-type names. You can use them on the\ncommand line, when ",(0,i.kt)("a",{parentName:"p",href:"#calling-another-task"},"calling sub-tasks")," in your Taskfile\nand when ",(0,i.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"including tasks")," with aliases from another\nTaskfile. They can also be used together with ",(0,i.kt)("a",{parentName:"p",href:"#namespace-aliases"},"namespace\naliases"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n generate:\n aliases: [gen]\n cmds:\n - task: gen-mocks\n\n generate-mocks:\n aliases: [gen-mocks]\n cmds:\n - echo \"generating...\"\n")),(0,i.kt)("h2",{id:"overriding-task-name"},"Overriding task name"),(0,i.kt)("p",null,"Sometimes you may want to override the task name printed on the summary, up-to-date\nmessages to STDOUT, etc. In this case, you can just set ",(0,i.kt)("inlineCode",{parentName:"p"},"label:"),", which can also\nbe interpolated with variables:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n - task: print\n vars:\n MESSAGE: hello\n - task: print\n vars:\n MESSAGE: world\n\n print:\n label: 'print-{{.MESSAGE}}'\n cmds:\n - echo \"{{.MESSAGE}}\"\n")),(0,i.kt)("h2",{id:"silent-mode"},"Silent mode"),(0,i.kt)("p",null,"Silent mode disables the echoing of commands before Task runs it.\nFor the following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n")),(0,i.kt)("p",null,"Normally this will be printed:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-sh"},'echo "Print something"\nPrint something\n')),(0,i.kt)("p",null,"With silent mode on, the below will be printed instead:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-sh"},"Print something\n")),(0,i.kt)("p",null,"There are four ways to enable silent mode:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"At command level:")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - cmd: echo \"Print something\"\n silent: true\n")),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"At task level:")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n silent: true\n")),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Globally at Taskfile level:")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nsilent: true\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n")),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Or globally with ",(0,i.kt)("inlineCode",{parentName:"li"},"--silent")," or ",(0,i.kt)("inlineCode",{parentName:"li"},"-s")," flag")),(0,i.kt)("p",null,"If you want to suppress STDOUT instead, just redirect a command to ",(0,i.kt)("inlineCode",{parentName:"p"},"/dev/null"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"This will print nothing\" > /dev/null\n")),(0,i.kt)("h2",{id:"dry-run-mode"},"Dry run mode"),(0,i.kt)("p",null,"Dry run mode (",(0,i.kt)("inlineCode",{parentName:"p"},"--dry"),") compiles and steps through each task, printing the commands\nthat would be run without executing them. This is useful for debugging your Taskfiles."),(0,i.kt)("h2",{id:"ignore-errors"},"Ignore errors"),(0,i.kt)("p",null,"You have the option to ignore errors during command execution.\nGiven the following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - exit 1\n - echo \"Hello World\"\n")),(0,i.kt)("p",null,"Task will abort the execution after running ",(0,i.kt)("inlineCode",{parentName:"p"},"exit 1")," because the status code ",(0,i.kt)("inlineCode",{parentName:"p"},"1")," stands for ",(0,i.kt)("inlineCode",{parentName:"p"},"EXIT_FAILURE"),".\nHowever, it is possible to continue with execution using ",(0,i.kt)("inlineCode",{parentName:"p"},"ignore_error"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - cmd: exit 1\n ignore_error: true\n - echo \"Hello World\"\n")),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"ignore_error")," can also be set for a task, which means errors will be suppressed\nfor all commands. Nevertheless, keep in mind that this option will not propagate to other tasks\ncalled either by ",(0,i.kt)("inlineCode",{parentName:"p"},"deps")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds"),"!"),(0,i.kt)("h2",{id:"output-syntax"},"Output syntax"),(0,i.kt)("p",null,"By default, Task just redirects the STDOUT and STDERR of the running commands\nto the shell in real-time. This is good for having live feedback for logging\nprinted by commands, but the output can become messy if you have multiple\ncommands running simultaneously and printing lots of stuff."),(0,i.kt)("p",null,"To make this more customizable, there are currently three different output\noptions you can choose:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"interleaved")," (default)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"group")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"prefixed"))),(0,i.kt)("p",null,"To choose another one, just set it to root in the Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\noutput: 'group'\n\ntasks:\n # ...\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"group")," output will print the entire output of a command once after it\nfinishes, so you will not have live feedback for commands that take a long time\nto run."),(0,i.kt)("p",null,"When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"group")," output, you can optionally provide a templated message\nto print at the start and end of the group. This can be useful for instructing\nCI systems to group all of the output for a given task, such as with\n",(0,i.kt)("a",{parentName:"p",href:"https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#grouping-log-lines"},"GitHub Actions' ",(0,i.kt)("inlineCode",{parentName:"a"},"::group::")," command"),"\nor ",(0,i.kt)("a",{parentName:"p",href:"https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?expand=1&view=azure-devops&tabs=bash#formatting-commands"},"Azure Pipelines"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\noutput:\n group:\n begin: '::group::{{.TASK}}'\n end: '::endgroup::'\n\ntasks:\n default:\n cmds:\n - echo 'Hello, World!'\n silent: true\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ task default\n::group::default\nHello, World!\n::endgroup::\n")),(0,i.kt)("p",null,"When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"group")," output, you may swallow the output of the executed command\non standard output and standard error if it does not fail (zero exit code)."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nsilent: true\n\noutput:\n group:\n error_only: true\n\ntasks:\n passes: echo 'output-of-passes'\n errors: echo 'output-of-errors' && exit 1\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},'$ task passes\n$ task errors\noutput-of-errors\ntask: Failed to run task "errors": exit status 1\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"prefix")," output will prefix every line printed by a command with\n",(0,i.kt)("inlineCode",{parentName:"p"},"[task-name] ")," as the prefix, but you can customize the prefix for a command\nwith the ",(0,i.kt)("inlineCode",{parentName:"p"},"prefix:")," attribute:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\noutput: prefixed\n\ntasks:\n default:\n deps:\n - task: print\n vars: {TEXT: foo}\n - task: print\n vars: {TEXT: bar}\n - task: print\n vars: {TEXT: baz}\n\n print:\n cmds:\n - echo "{{.TEXT}}"\n prefix: "print-{{.TEXT}}"\n silent: true\n')),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ task default\n[print-foo] foo\n[print-bar] bar\n[print-baz] baz\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"output")," option can also be specified by the ",(0,i.kt)("inlineCode",{parentName:"p"},"--output")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"-o")," flags.")),(0,i.kt)("h2",{id:"interactive-cli-application"},"Interactive CLI application"),(0,i.kt)("p",null,"When running interactive CLI applications inside Task they can sometimes behave\nweirdly, especially when the ",(0,i.kt)("a",{parentName:"p",href:"#output-syntax"},"output mode")," is set to something\nother than ",(0,i.kt)("inlineCode",{parentName:"p"},"interleaved")," (the default), or when interactive apps are run in\nparallel with other tasks."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"interactive: true")," tells Task this is an interactive application and Task\nwill try to optimize for it:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - vim my-file.txt\n interactive: true\n")),(0,i.kt)("p",null,"If you still have problems running an interactive app through Task, please open\nan issue about it."),(0,i.kt)("h2",{id:"short-task-syntax"},"Short task syntax"),(0,i.kt)("p",null,"Starting on Task v3, you can now write tasks with a shorter syntax if they\nhave the default settings (e.g. no custom ",(0,i.kt)("inlineCode",{parentName:"p"},"env:"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"vars:"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"desc:"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"silent:")," , etc):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build: go build -v -o ./app{{exeExt}} .\n\n run:\n - task: build\n - ./app{{exeExt}} -h localhost -p 8080\n")),(0,i.kt)("h2",{id:"set-and-shopt"},(0,i.kt)("inlineCode",{parentName:"h2"},"set")," and ",(0,i.kt)("inlineCode",{parentName:"h2"},"shopt")),(0,i.kt)("p",null,"It's possible to specify options to the\n",(0,i.kt)("a",{parentName:"p",href:"https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html"},(0,i.kt)("inlineCode",{parentName:"a"},"set")),"\nand ",(0,i.kt)("a",{parentName:"p",href:"https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html"},(0,i.kt)("inlineCode",{parentName:"a"},"shopt")),"\nbuiltins. This can be added at global, task or command level."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nset: [pipefail]\nshopt: [globstar]\n\ntasks:\n # `globstar` required for double star globs to work\n default: echo **/*.go\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Keep in mind that not all options are available in the\n",(0,i.kt)("a",{parentName:"p",href:"https://github.com/mvdan/sh"},"shell interpreter library")," that Task uses.")),(0,i.kt)("h2",{id:"watch-tasks"},"Watch tasks"),(0,i.kt)("p",null,"With the flags ",(0,i.kt)("inlineCode",{parentName:"p"},"--watch")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"-w")," task will watch for file changes\nand run the task again. This requires the ",(0,i.kt)("inlineCode",{parentName:"p"},"sources")," attribute to be given,\nso task knows which files to watch."),(0,i.kt)("p",null,"The default watch interval is 5 seconds, but it's possible to change it by\neither setting ",(0,i.kt)("inlineCode",{parentName:"p"},"interval: '500ms'")," in the root of the Taskfile passing it\nas an argument like ",(0,i.kt)("inlineCode",{parentName:"p"},"--interval=500ms"),"."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/6476eba6.f5165ba7.js b/assets/js/6476eba6.f5165ba7.js new file mode 100644 index 00000000..5b067093 --- /dev/null +++ b/assets/js/6476eba6.f5165ba7.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktaskfile_dev=self.webpackChunktaskfile_dev||[]).push([[827],{3905:function(e,n,t){t.d(n,{Zo:function(){return d},kt:function(){return k}});var a=t(7294);function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function l(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function s(e){for(var n=1;n=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}var r=a.createContext({}),p=function(e){var n=a.useContext(r),t=n;return e&&(t="function"==typeof e?e(n):s(s({},n),e)),t},d=function(e){var n=p(e.components);return a.createElement(r.Provider,{value:n},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},c=a.forwardRef((function(e,n){var t=e.components,i=e.mdxType,l=e.originalType,r=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),u=p(t),c=i,k=u["".concat(r,".").concat(c)]||u[c]||m[c]||l;return t?a.createElement(k,s(s({ref:n},d),{},{components:t})):a.createElement(k,s({ref:n},d))}));function k(e,n){var t=arguments,i=n&&n.mdxType;if("string"==typeof e||i){var l=t.length,s=new Array(l);s[0]=c;var o={};for(var r in n)hasOwnProperty.call(n,r)&&(o[r]=n[r]);o.originalType=e,o[u]="string"==typeof e?e:i,s[1]=o;for(var p=2;pdefer",id:"doing-task-cleanup-with-defer",level:2},{value:"Go's template engine",id:"gos-template-engine",level:2},{value:"Help",id:"help",level:2},{value:"Display summary of task",id:"display-summary-of-task",level:2},{value:"Task aliases",id:"task-aliases",level:2},{value:"Overriding task name",id:"overriding-task-name",level:2},{value:"Silent mode",id:"silent-mode",level:2},{value:"Dry run mode",id:"dry-run-mode",level:2},{value:"Ignore errors",id:"ignore-errors",level:2},{value:"Output syntax",id:"output-syntax",level:2},{value:"Interactive CLI application",id:"interactive-cli-application",level:2},{value:"Short task syntax",id:"short-task-syntax",level:2},{value:"set and shopt",id:"set-and-shopt",level:2},{value:"Watch tasks",id:"watch-tasks",level:2}],d={toc:p};function u(e){let{components:n,...t}=e;return(0,i.kt)("wrapper",(0,a.Z)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"usage"},"Usage"),(0,i.kt)("h2",{id:"getting-started"},"Getting started"),(0,i.kt)("p",null,"Create a file called ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml")," in the root of your project.\nThe ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds")," attribute should contain the commands of a task.\nThe example below allows compiling a Go app and uses ",(0,i.kt)("a",{parentName:"p",href:"https://esbuild.github.io/"},"esbuild")," to concat\nand minify multiple CSS files into a single one."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - go build -v -i main.go\n\n assets:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"Running the tasks is as simple as running:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"task assets build\n")),(0,i.kt)("p",null,"Task uses ",(0,i.kt)("a",{parentName:"p",href:"https://mvdan.cc/sh/"},"mvdan.cc/sh"),", a native Go sh\ninterpreter. So you can write sh/bash commands, and it will work even on\nWindows, where ",(0,i.kt)("inlineCode",{parentName:"p"},"sh")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"bash")," are usually not available. Just remember any\nexecutable called must be available by the OS or in PATH."),(0,i.kt)("p",null,'If you omit a task name, "default" will be assumed.'),(0,i.kt)("h2",{id:"supported-file-names"},"Supported file names"),(0,i.kt)("p",null,"Task will look for the following file names, in order of priority:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Taskfile.yml"),(0,i.kt)("li",{parentName:"ul"},"Taskfile.yaml"),(0,i.kt)("li",{parentName:"ul"},"Taskfile.dist.yml"),(0,i.kt)("li",{parentName:"ul"},"Taskfile.dist.yaml")),(0,i.kt)("p",null,"The intention of having the ",(0,i.kt)("inlineCode",{parentName:"p"},".dist")," variants is to allow projects to have one\ncommitted version (",(0,i.kt)("inlineCode",{parentName:"p"},".dist"),") while still allowing individual users to override\nthe Taskfile by adding an additional ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml")," (which would be on\n",(0,i.kt)("inlineCode",{parentName:"p"},".gitignore"),")."),(0,i.kt)("h3",{id:"running-a-taskfile-from-a-subdirectory"},"Running a Taskfile from a subdirectory"),(0,i.kt)("p",null,"If a Taskfile cannot be found in the current working directory, it will walk up\nthe file tree until it finds one (similar to how ",(0,i.kt)("inlineCode",{parentName:"p"},"git")," works). When running Task\nfrom a subdirectory like this, it will behave as if you ran it from the\ndirectory containing the Taskfile."),(0,i.kt)("p",null,"You can use this functionality along with the special ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.USER_WORKING_DIR}}"),"\nvariable to create some very useful reusable tasks. For example, if you have a\nmonorepo with directories for each microservice, you can ",(0,i.kt)("inlineCode",{parentName:"p"},"cd")," into a\nmicroservice directory and run a task command to bring it up without having to\ncreate multiple tasks or Taskfiles with identical content. For example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n up:\n dir: '{{.USER_WORKING_DIR}}'\n preconditions:\n - test -f docker-compose.yml\n cmds:\n - docker-compose up -d\n")),(0,i.kt)("p",null,"In this example, we can run ",(0,i.kt)("inlineCode",{parentName:"p"},"cd ")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"task up")," and as long as the\n",(0,i.kt)("inlineCode",{parentName:"p"},"")," directory contains a ",(0,i.kt)("inlineCode",{parentName:"p"},"docker-compose.yml"),", the Docker composition will be\nbrought up."),(0,i.kt)("h3",{id:"running-a-global-taskfile"},"Running a global Taskfile"),(0,i.kt)("p",null,"If you call Task with the ",(0,i.kt)("inlineCode",{parentName:"p"},"--global")," (alias ",(0,i.kt)("inlineCode",{parentName:"p"},"-g"),") flag, it will look for your\nhome directory instead of your working directory. In short, Task will look for\na Taskfile on either ",(0,i.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yml")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yaml")," paths."),(0,i.kt)("p",null,"This is useful to have automation that you can run from anywhere in your\nsystem!"),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"When running your global Taskfile with ",(0,i.kt)("inlineCode",{parentName:"p"},"-g"),", tasks will run on ",(0,i.kt)("inlineCode",{parentName:"p"},"$HOME")," by\ndefault, and not on your working directory!"),(0,i.kt)("p",{parentName:"admonition"},"As mentioned in the previous section, the ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.USER_WORKING_DIR}}")," special\nvariable can be very handy here to run stuff on the directory you're calling\n",(0,i.kt)("inlineCode",{parentName:"p"},"task -g")," from."),(0,i.kt)("pre",{parentName:"admonition"},(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n from-home:\n cmds:\n - pwd\n\n from-working-directory:\n dir: '{{.USER_WORKING_DIR}}'\n cmds:\n - pwd\n"))),(0,i.kt)("h2",{id:"environment-variables"},"Environment variables"),(0,i.kt)("h3",{id:"task"},"Task"),(0,i.kt)("p",null,"You can use ",(0,i.kt)("inlineCode",{parentName:"p"},"env")," to set custom environment variables for a specific task:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n greet:\n cmds:\n - echo $GREETING\n env:\n GREETING: Hey, there!\n")),(0,i.kt)("p",null,"Additionally, you can set global environment variables that will be available\nto all tasks:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nenv:\n GREETING: Hey, there!\n\ntasks:\n greet:\n cmds:\n - echo $GREETING\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},(0,i.kt)("inlineCode",{parentName:"p"},"env")," supports expansion and retrieving output from a shell command\njust like variables, as you can see in the ",(0,i.kt)("a",{parentName:"p",href:"#variables"},"Variables")," section.")),(0,i.kt)("h3",{id:"env-files"},".env files"),(0,i.kt)("p",null,"You can also ask Task to include ",(0,i.kt)("inlineCode",{parentName:"p"},".env")," like files by using the ",(0,i.kt)("inlineCode",{parentName:"p"},"dotenv:"),"\nsetting:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash",metastring:'title=".env"',title:'".env"'},"KEYNAME=VALUE\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash",metastring:'title="testing/.env"',title:'"testing/.env"'},"ENDPOINT=testing.com\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml",metastring:'title="Taskfile.yml"',title:'"Taskfile.yml"'},"version: '3'\n\nenv:\n ENV: testing\n\ndotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']\n\ntasks:\n greet:\n cmds:\n - echo \"Using $KEYNAME and endpoint $ENDPOINT\"\n")),(0,i.kt)("p",null,"Dotenv files can also be specified at the task level:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nenv:\n ENV: testing\n\ntasks:\n greet:\n dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']\n cmds:\n - echo \"Using $KEYNAME and endpoint $ENDPOINT\"\n")),(0,i.kt)("p",null,"Environment variables specified explicitly at the task-level will override\nvariables defined in dotfiles:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nenv:\n ENV: testing\n\ntasks:\n greet:\n dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']\n env:\n KEYNAME: DIFFERENT_VALUE\n cmds:\n - echo \"Using $KEYNAME and endpoint $ENDPOINT\"\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Please note that you are not currently able to use the ",(0,i.kt)("inlineCode",{parentName:"p"},"dotenv")," key inside included Taskfiles.")),(0,i.kt)("h2",{id:"including-other-taskfiles"},"Including other Taskfiles"),(0,i.kt)("p",null,"If you want to share tasks between different projects (Taskfiles), you can use\nthe importing mechanism to include other Taskfiles using the ",(0,i.kt)("inlineCode",{parentName:"p"},"includes")," keyword:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n docs: ./documentation # will look for ./documentation/Taskfile.yml\n docker: ./DockerTasks.yml\n")),(0,i.kt)("p",null,"The tasks described in the given Taskfiles will be available with the informed\nnamespace. So, you'd call ",(0,i.kt)("inlineCode",{parentName:"p"},"task docs:serve")," to run the ",(0,i.kt)("inlineCode",{parentName:"p"},"serve")," task from\n",(0,i.kt)("inlineCode",{parentName:"p"},"documentation/Taskfile.yml")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"task docker:build")," to run the ",(0,i.kt)("inlineCode",{parentName:"p"},"build")," task\nfrom the ",(0,i.kt)("inlineCode",{parentName:"p"},"DockerTasks.yml")," file."),(0,i.kt)("p",null,"Relative paths are resolved relative to the directory containing the including Taskfile."),(0,i.kt)("h3",{id:"os-specific-taskfiles"},"OS-specific Taskfiles"),(0,i.kt)("p",null,"With ",(0,i.kt)("inlineCode",{parentName:"p"},"version: '2'"),", task automatically includes any ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_{{OS}}.yml"),"\nif it exists (for example: ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_windows.yml"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_linux.yml")," or\n",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_darwin.yml"),"). Since this behavior was a bit too implicit, it\nwas removed on version 3, but you still can have a similar behavior by\nexplicitly importing these files:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n build: ./Taskfile_{{OS}}.yml\n")),(0,i.kt)("h3",{id:"directory-of-included-taskfile"},"Directory of included Taskfile"),(0,i.kt)("p",null,"By default, included Taskfile's tasks are run in the current directory, even\nif the Taskfile is in another directory, but you can force its tasks to run\nin another directory by using this alternative syntax:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n docs:\n taskfile: ./docs/Taskfile.yml\n dir: ./docs\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"The included Taskfiles must be using the same schema version as the main\nTaskfile uses.")),(0,i.kt)("h3",{id:"optional-includes"},"Optional includes"),(0,i.kt)("p",null,"Includes marked as optional will allow Task to continue execution as normal if\nthe included file is missing."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n tests:\n taskfile: ./tests/Taskfile.yml\n optional: true\n\ntasks:\n greet:\n cmds:\n - echo \"This command can still be successfully executed if ./tests/Taskfile.yml does not exist\"\n")),(0,i.kt)("h3",{id:"internal-includes"},"Internal includes"),(0,i.kt)("p",null,"Includes marked as internal will set all the tasks of the included file to be\ninternal as well (see the ",(0,i.kt)("a",{parentName:"p",href:"#internal-tasks"},"Internal tasks")," section below).\nThis is useful when including utility tasks that are not intended to be used\ndirectly by the user."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n tests:\n taskfile: ./taskfiles/Utils.yml\n internal: true\n")),(0,i.kt)("h3",{id:"vars-of-included-taskfiles"},"Vars of included Taskfiles"),(0,i.kt)("p",null,"You can also specify variables when including a Taskfile. This may be useful\nfor having reusable Taskfile that can be tweaked or even included more than once:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n backend:\n taskfile: ./taskfiles/Docker.yml\n vars:\n DOCKER_IMAGE: backend_image\n\n frontend:\n taskfile: ./taskfiles/Docker.yml\n vars:\n DOCKER_IMAGE: frontend_image\n")),(0,i.kt)("h3",{id:"namespace-aliases"},"Namespace aliases"),(0,i.kt)("p",null,"When including a Taskfile, you can give the namespace a list of ",(0,i.kt)("inlineCode",{parentName:"p"},"aliases"),".\nThis works in the same way as ",(0,i.kt)("a",{parentName:"p",href:"#task-aliases"},"task aliases")," and can be used\ntogether to create shorter and easier-to-type commands."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n generate:\n taskfile: ./taskfiles/Generate.yml\n aliases: [gen]\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Vars declared in the included Taskfile have preference over the\nvariables in the including Taskfile! If you want a variable in an included Taskfile to be overridable,\nuse the ",(0,i.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/defaults.html"},"default function"),":\n",(0,i.kt)("inlineCode",{parentName:"p"},"MY_VAR: '{{.MY_VAR | default \"my-default-value\"}}'"),".")),(0,i.kt)("h2",{id:"internal-tasks"},"Internal tasks"),(0,i.kt)("p",null,"Internal tasks are tasks that cannot be called directly by the user. They will\nnot appear in the output when running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --list|--list-all"),". Other tasks may\ncall internal tasks in the usual way. This is useful for creating reusable,\nfunction-like tasks that have no useful purpose on the command line."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-image-1:\n cmds:\n - task: build-image\n vars:\n DOCKER_IMAGE: image-1\n\n build-image:\n internal: true\n cmds:\n - docker build -t {{.DOCKER_IMAGE}} .\n")),(0,i.kt)("h2",{id:"task-directory"},"Task directory"),(0,i.kt)("p",null,"By default, tasks will be executed in the directory where the Taskfile is\nlocated. But you can easily make the task run in another folder, informing\n",(0,i.kt)("inlineCode",{parentName:"p"},"dir"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n serve:\n dir: public/www\n cmds:\n # run http server\n - caddy\n")),(0,i.kt)("p",null,"If the directory does not exist, ",(0,i.kt)("inlineCode",{parentName:"p"},"task")," creates it."),(0,i.kt)("h2",{id:"task-dependencies"},"Task dependencies"),(0,i.kt)("blockquote",null,(0,i.kt)("p",{parentName:"blockquote"},"Dependencies run in parallel, so dependencies of a task should not depend one\nanother. If you want to force tasks to run serially, take a look at the\n",(0,i.kt)("a",{parentName:"p",href:"#calling-another-task"},"Calling Another Task")," section below.")),(0,i.kt)("p",null,"You may have tasks that depend on others. Just pointing them on ",(0,i.kt)("inlineCode",{parentName:"p"},"deps")," will\nmake them run automatically before running the parent task:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n deps: [assets]\n cmds:\n - go build -v -i main.go\n\n assets:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"In the above example, ",(0,i.kt)("inlineCode",{parentName:"p"},"assets")," will always run right before ",(0,i.kt)("inlineCode",{parentName:"p"},"build")," if you run\n",(0,i.kt)("inlineCode",{parentName:"p"},"task build"),"."),(0,i.kt)("p",null,"A task can have only dependencies and no commands to group tasks together:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n assets:\n deps: [js, css]\n\n js:\n cmds:\n - esbuild --bundle --minify js/index.js > public/bundle.js\n\n css:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"If there is more than one dependency, they always run in parallel for better\nperformance."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"You can also make the tasks given by the command line run in parallel by\nusing the ",(0,i.kt)("inlineCode",{parentName:"p"},"--parallel")," flag (alias ",(0,i.kt)("inlineCode",{parentName:"p"},"-p"),"). Example: ",(0,i.kt)("inlineCode",{parentName:"p"},"task --parallel js css"),".")),(0,i.kt)("p",null,"If you want to pass information to dependencies, you can do that the same\nmanner as you would to ",(0,i.kt)("a",{parentName:"p",href:"#calling-another-task"},"call another task"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n default:\n deps:\n - task: echo_sth\n vars: {TEXT: "before 1"}\n - task: echo_sth\n vars: {TEXT: "before 2"}\n cmds:\n - echo "after"\n\n echo_sth:\n cmds:\n - echo {{.TEXT}}\n')),(0,i.kt)("h2",{id:"platform-specific-tasks-and-commands"},"Platform specific tasks and commands"),(0,i.kt)("p",null,"If you want to restrict the running of tasks to explicit platforms, this can be achieved\nusing the ",(0,i.kt)("inlineCode",{parentName:"p"},"platforms:")," key. Tasks can be restricted to a specific OS, architecture or a\ncombination of both.\nOn a mismatch, the task or command will be skipped, and no error will be thrown."),(0,i.kt)("p",null,"The values allowed as OS or Arch are valid ",(0,i.kt)("inlineCode",{parentName:"p"},"GOOS")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"GOARCH")," values, as\ndefined by the Go language\n",(0,i.kt)("a",{parentName:"p",href:"https://github.com/golang/go/blob/master/src/go/build/syslist.go"},"here"),"."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"build-windows")," task below will run only on Windows, and on any architecture:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-windows:\n platforms: [windows]\n cmds:\n - echo 'Running command on Windows'\n")),(0,i.kt)("p",null,"This can be restricted to a specific architecture as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-windows-amd64:\n platforms: [windows/amd64]\n cmds:\n - echo 'Running command on Windows (amd64)'\n")),(0,i.kt)("p",null,"It is also possible to restrict the task to specific architectures:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build-amd64:\n platforms: [amd64]\n cmds:\n - echo 'Running command on amd64'\n")),(0,i.kt)("p",null,"Multiple platforms can be specified as follows:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n platforms: [windows/amd64, darwin]\n cmds:\n - echo 'Running command on Windows (amd64) and macOS'\n")),(0,i.kt)("p",null,"Individual commands can also be restricted to specific platforms:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - cmd: echo 'Running command on Windows (amd64) and macOS'\n platforms: [windows/amd64, darwin]\n - cmd: echo 'Running on all platforms'\n")),(0,i.kt)("h2",{id:"calling-another-task"},"Calling another task"),(0,i.kt)("p",null,"When a task has many dependencies, they are executed concurrently. This will\noften result in a faster build pipeline. However, in some situations, you may need\nto call other tasks serially. In this case, use the following syntax:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n main-task:\n cmds:\n - task: task-to-be-called\n - task: another-task\n - echo "Both done"\n\n task-to-be-called:\n cmds:\n - echo "Task to be called"\n\n another-task:\n cmds:\n - echo "Another task"\n')),(0,i.kt)("p",null,"Overriding variables in the called task is as simple as informing ",(0,i.kt)("inlineCode",{parentName:"p"},"vars"),"\nattribute:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n greet:\n vars:\n RECIPIENT: \'{{default "World" .RECIPIENT}}\'\n cmds:\n - echo "Hello, {{.RECIPIENT}}!"\n\n greet-pessimistically:\n cmds:\n - task: greet\n vars: {RECIPIENT: "Cruel World"}\n')),(0,i.kt)("p",null,"The above syntax is also supported in ",(0,i.kt)("inlineCode",{parentName:"p"},"deps"),"."),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"NOTE: If you want to call a task declared in the root Taskfile from within an\n",(0,i.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"included Taskfile"),", add a leading ",(0,i.kt)("inlineCode",{parentName:"p"},":")," like this:\n",(0,i.kt)("inlineCode",{parentName:"p"},"task: :task-name"),".")),(0,i.kt)("h2",{id:"prevent-unnecessary-work"},"Prevent unnecessary work"),(0,i.kt)("h3",{id:"by-fingerprinting-locally-generated-files-and-their-sources"},"By fingerprinting locally generated files and their sources"),(0,i.kt)("p",null,"If a task generates something, you can inform Task the source and generated\nfiles, so Task will prevent running them if not necessary."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n deps: [js, css]\n cmds:\n - go build -v -i main.go\n\n js:\n cmds:\n - esbuild --bundle --minify js/index.js > public/bundle.js\n sources:\n - src/js/**/*.js\n generates:\n - public/bundle.js\n\n css:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n sources:\n - src/css/**/*.css\n generates:\n - public/bundle.css\n")),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"sources")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"generates")," can be files or file patterns. When given,\nTask will compare the checksum of the source files to determine if it's\nnecessary to run the task. If not, it will just print a message like\n",(0,i.kt)("inlineCode",{parentName:"p"},'Task "js" is up to date'),"."),(0,i.kt)("p",null,"If you prefer this check to be made by the modification timestamp of the files,\ninstead of its checksum (content), just set the ",(0,i.kt)("inlineCode",{parentName:"p"},"method")," property to ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamp"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - go build .\n sources:\n - ./*.go\n generates:\n - app{{exeExt}}\n method: timestamp\n")),(0,i.kt)("p",null,"In situations where you need more flexibility the ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," keyword can be used.\nYou can even combine the two. See the documentation for\n",(0,i.kt)("a",{parentName:"p",href:"#using-programmatic-checks-to-indicate-a-task-is-up-to-date"},"status")," for an\nexample."),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"By default, task stores checksums on a local ",(0,i.kt)("inlineCode",{parentName:"p"},".task")," directory in the project's\ndirectory. Most of the time, you'll want to have this directory on ",(0,i.kt)("inlineCode",{parentName:"p"},".gitignore"),"\n(or equivalent) so it isn't committed. (If you have a task for code generation\nthat is committed it may make sense to commit the checksum of that task as\nwell, though)."),(0,i.kt)("p",{parentName:"admonition"},"If you want these files to be stored in another directory, you can set a\n",(0,i.kt)("inlineCode",{parentName:"p"},"TASK_TEMP_DIR")," environment variable in your machine. It can contain a relative\npath like ",(0,i.kt)("inlineCode",{parentName:"p"},"tmp/task")," that will be interpreted as relative to the project\ndirectory, or an absolute or home path like ",(0,i.kt)("inlineCode",{parentName:"p"},"/tmp/.task")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"~/.task"),"\n(subdirectories will be created for each project)."),(0,i.kt)("pre",{parentName:"admonition"},(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"export TASK_TEMP_DIR='~/.task'\n"))),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Each task has only one checksum stored for its ",(0,i.kt)("inlineCode",{parentName:"p"},"sources"),". If you want\nto distinguish a task by any of its input variables, you can add those\nvariables as part of the task's label, and it will be considered a different\ntask."),(0,i.kt)("p",{parentName:"admonition"},"This is useful if you want to run a task once for each distinct set of\ninputs until the sources actually change. For example, if the sources depend\non the value of a variable, or you if you want the task to rerun if some arguments\nchange even if the source has not.")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The method ",(0,i.kt)("inlineCode",{parentName:"p"},"none")," skips any validation and always run the task.")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"For the ",(0,i.kt)("inlineCode",{parentName:"p"},"checksum")," (default) or ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamp")," method to work, it is only necessary to\ninform the source files.\nWhen the ",(0,i.kt)("inlineCode",{parentName:"p"},"timestamp")," method is used, the last time of the running the task is considered as a generate.")),(0,i.kt)("h3",{id:"using-programmatic-checks-to-indicate-a-task-is-up-to-date"},"Using programmatic checks to indicate a task is up to date"),(0,i.kt)("p",null,"Alternatively, you can inform a sequence of tests as ",(0,i.kt)("inlineCode",{parentName:"p"},"status"),". If no error\nis returned (exit status 0), the task is considered up-to-date:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n generate-files:\n cmds:\n - mkdir directory\n - touch directory/file1.txt\n - touch directory/file2.txt\n # test existence of files\n status:\n - test -d directory\n - test -f directory/file1.txt\n - test -f directory/file2.txt\n")),(0,i.kt)("p",null,"Normally, you would use ",(0,i.kt)("inlineCode",{parentName:"p"},"sources")," in combination with\n",(0,i.kt)("inlineCode",{parentName:"p"},"generates")," - but for tasks that generate remote artifacts (Docker images,\ndeploys, CD releases) the checksum source and timestamps require either\naccess to the artifact or for an out-of-band refresh of the ",(0,i.kt)("inlineCode",{parentName:"p"},".checksum"),"\nfingerprint file."),(0,i.kt)("p",null,"Two special variables ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.CHECKSUM}}")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.TIMESTAMP}}")," are available\nfor interpolation within ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," commands, depending on the method assigned\nto fingerprint the sources. Only ",(0,i.kt)("inlineCode",{parentName:"p"},"source")," globs are fingerprinted."),(0,i.kt)("p",null,"Note that the ",(0,i.kt)("inlineCode",{parentName:"p"},"{{.TIMESTAMP}}"),' variable is a "live" Go ',(0,i.kt)("inlineCode",{parentName:"p"},"time.Time")," struct, and\ncan be formatted using any of the methods that ",(0,i.kt)("inlineCode",{parentName:"p"},"time.Time")," responds to."),(0,i.kt)("p",null,"See ",(0,i.kt)("a",{parentName:"p",href:"https://golang.org/pkg/time/"},"the Go Time documentation")," for more information."),(0,i.kt)("p",null,"You can use ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"-f")," if you want to force a task to run even when\nup-to-date."),(0,i.kt)("p",null,"Also, ",(0,i.kt)("inlineCode",{parentName:"p"},"task --status [tasks]...")," will exit with a non-zero exit code if any of\nthe tasks are not up-to-date."),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"status")," can be combined with the ",(0,i.kt)("a",{parentName:"p",href:"#by-fingerprinting-locally-generated-files-and-their-sources"},"fingerprinting"),"\nto have a task run if either the the source/generated artifacts changes, or the\nprogrammatic check fails:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:prod:\n desc: Build for production usage.\n cmds:\n - composer install\n # Run this task if source files changes.\n sources:\n - composer.json\n - composer.lock\n generates:\n - ./vendor/composer/installed.json\n - ./vendor/autoload.php\n # But also run the task if the last build was not a production build.\n status:\n - grep -q '\"dev\": false' ./vendor/composer/installed.json\n")),(0,i.kt)("h3",{id:"using-programmatic-checks-to-cancel-the-execution-of-a-task-and-its-dependencies"},"Using programmatic checks to cancel the execution of a task and its dependencies"),(0,i.kt)("p",null,"In addition to ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," checks, ",(0,i.kt)("inlineCode",{parentName:"p"},"preconditions")," checks are\nthe logical inverse of ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," checks. That is, if you need a certain set of\nconditions to be ",(0,i.kt)("em",{parentName:"p"},"true")," you can use the ",(0,i.kt)("inlineCode",{parentName:"p"},"preconditions")," stanza.\n",(0,i.kt)("inlineCode",{parentName:"p"},"preconditions")," are similar to ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," lines, except they support ",(0,i.kt)("inlineCode",{parentName:"p"},"sh"),"\nexpansion, and they SHOULD all return 0."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n generate-files:\n cmds:\n - mkdir directory\n - touch directory/file1.txt\n - touch directory/file2.txt\n # test existence of files\n preconditions:\n - test -f .env\n - sh: "[ 1 = 0 ]"\n msg: "One doesn\'t equal Zero, Halting"\n')),(0,i.kt)("p",null,"Preconditions can set specific failure messages that can tell\na user what steps to take using the ",(0,i.kt)("inlineCode",{parentName:"p"},"msg")," field."),(0,i.kt)("p",null,"If a task has a dependency on a sub-task with a precondition, and that\nprecondition is not met - the calling task will fail. Note that a task\nexecuted with a failing precondition will not run unless ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," is\ngiven."),(0,i.kt)("p",null,"Unlike ",(0,i.kt)("inlineCode",{parentName:"p"},"status"),", which will skip a task if it is up to date and continue\nexecuting tasks that depend on it, a ",(0,i.kt)("inlineCode",{parentName:"p"},"precondition")," will fail a task, along\nwith any other tasks that depend on it."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\ntasks:\n task-will-fail:\n preconditions:\n - sh: "exit 1"\n\n task-will-also-fail:\n deps:\n - task-will-fail\n\n task-will-still-fail:\n cmds:\n - task: task-will-fail\n - echo "I will not run"\n')),(0,i.kt)("h3",{id:"limiting-when-tasks-run"},"Limiting when tasks run"),(0,i.kt)("p",null,"If a task executed by multiple ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds")," or multiple ",(0,i.kt)("inlineCode",{parentName:"p"},"deps")," you can control\nwhen it is executed using ",(0,i.kt)("inlineCode",{parentName:"p"},"run"),". ",(0,i.kt)("inlineCode",{parentName:"p"},"run")," can also be set at the root\nof the Taskfile to change the behavior of all the tasks unless explicitly\noverridden."),(0,i.kt)("p",null,"Supported values for ",(0,i.kt)("inlineCode",{parentName:"p"},"run"),":"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"always")," (default) always attempt to invoke the task regardless of the\nnumber of previous executions"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"once")," only invoke this task once regardless of the number of references"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"when_changed")," only invokes the task once for each unique set of variables\npassed into the task")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - task: generate-file\n vars: { CONTENT: '1' }\n - task: generate-file\n vars: { CONTENT: '2' }\n - task: generate-file\n vars: { CONTENT: '2' }\n\n generate-file:\n run: when_changed\n deps:\n - install-deps\n cmds:\n - echo {{.CONTENT}}\n\n install-deps:\n run: once\n cmds:\n - sleep 5 # long operation like installing packages\n")),(0,i.kt)("h2",{id:"variables"},"Variables"),(0,i.kt)("p",null,"When doing interpolation of variables, Task will look for the below.\nThey are listed below in order of importance (i.e. most important first):"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Variables declared in the task definition"),(0,i.kt)("li",{parentName:"ul"},"Variables given while calling a task from another\n(See ",(0,i.kt)("a",{parentName:"li",href:"#calling-another-task"},"Calling another task")," above)"),(0,i.kt)("li",{parentName:"ul"},"Variables of the ",(0,i.kt)("a",{parentName:"li",href:"#including-other-taskfiles"},"included Taskfile")," (when the task is included)"),(0,i.kt)("li",{parentName:"ul"},"Variables of the ",(0,i.kt)("a",{parentName:"li",href:"#vars-of-included-taskfiles"},"inclusion of the Taskfile")," (when the task is included)"),(0,i.kt)("li",{parentName:"ul"},"Global variables (those declared in the ",(0,i.kt)("inlineCode",{parentName:"li"},"vars:")," option in the Taskfile)"),(0,i.kt)("li",{parentName:"ul"},"Environment variables")),(0,i.kt)("p",null,"Example of sending parameters with environment variables:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ TASK_VARIABLE=a-value task do-something\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"A special variable ",(0,i.kt)("inlineCode",{parentName:"p"},".TASK")," is always available containing the task name.")),(0,i.kt)("p",null,"Since some shells do not support the above syntax to set environment variables\n(Windows) tasks also accept a similar style when not at the beginning of\nthe command."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},'$ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!"\n')),(0,i.kt)("p",null,"Example of locally declared vars:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n print-var:\n cmds:\n - echo \"{{.VAR}}\"\n vars:\n VAR: Hello!\n")),(0,i.kt)("p",null,"Example of global vars in a ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nvars:\n GREETING: Hello from Taskfile!\n\ntasks:\n greet:\n cmds:\n - echo \"{{.GREETING}}\"\n")),(0,i.kt)("h3",{id:"dynamic-variables"},"Dynamic variables"),(0,i.kt)("p",null,"The below syntax (",(0,i.kt)("inlineCode",{parentName:"p"},"sh:")," prop in a variable) is considered a dynamic variable.\nThe value will be treated as a command and the output assigned. If there are one\nor more trailing newlines, the last newline will be trimmed."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n cmds:\n - go build -ldflags=\"-X main.Version={{.GIT_COMMIT}}\" main.go\n vars:\n GIT_COMMIT:\n sh: git log -n 1 --format=%h\n")),(0,i.kt)("p",null,"This works for all types of variables."),(0,i.kt)("h2",{id:"forwarding-cli-arguments-to-commands"},"Forwarding CLI arguments to commands"),(0,i.kt)("p",null,"If ",(0,i.kt)("inlineCode",{parentName:"p"},"--")," is given in the CLI, all following parameters are added to a\nspecial ",(0,i.kt)("inlineCode",{parentName:"p"},".CLI_ARGS")," variable. This is useful to forward arguments to another\ncommand."),(0,i.kt)("p",null,"The below example will run ",(0,i.kt)("inlineCode",{parentName:"p"},"yarn install"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ task yarn -- install\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n yarn:\n cmds:\n - yarn {{.CLI_ARGS}}\n")),(0,i.kt)("h2",{id:"doing-task-cleanup-with-defer"},"Doing task cleanup with ",(0,i.kt)("inlineCode",{parentName:"h2"},"defer")),(0,i.kt)("p",null,"With the ",(0,i.kt)("inlineCode",{parentName:"p"},"defer")," keyword, it's possible to schedule cleanup to be run once\nthe task finishes. The difference with just putting it as the last command is\nthat this command will run even when the task fails."),(0,i.kt)("p",null,"In the example below, ",(0,i.kt)("inlineCode",{parentName:"p"},"rm -rf tmpdir/")," will run even if the third command fails:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - mkdir -p tmpdir/\n - defer: rm -rf tmpdir/\n - echo 'Do work on tmpdir/'\n")),(0,i.kt)("p",null,"If you want to move the cleanup command into another task, that is possible as\nwell:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - mkdir -p tmpdir/\n - defer: { task: cleanup }\n - echo 'Do work on tmpdir/'\n\n cleanup: rm -rf tmpdir/\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Due to the nature of how the\n",(0,i.kt)("a",{parentName:"p",href:"https://go.dev/tour/flowcontrol/13"},"Go's own ",(0,i.kt)("inlineCode",{parentName:"a"},"defer")," work"),", the deferred\ncommands are executed in the reverse order if you schedule multiple of them.")),(0,i.kt)("h2",{id:"gos-template-engine"},"Go's template engine"),(0,i.kt)("p",null,"Task parse commands as ",(0,i.kt)("a",{parentName:"p",href:"https://golang.org/pkg/text/template/"},"Go's template engine")," before executing\nthem. Variables are accessible through dot syntax (",(0,i.kt)("inlineCode",{parentName:"p"},".VARNAME"),")."),(0,i.kt)("p",null,"All functions by the Go's ",(0,i.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/"},"slim-sprig lib"),"\nare available. The following example gets the current date in a given format:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n print-date:\n cmds:\n - echo {{now | date \"2006-01-02\"}}\n")),(0,i.kt)("p",null,"Task also adds the following functions:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"OS"),': Returns the operating system. Possible values are "windows", "linux",\n"darwin" (macOS) and "freebsd".'),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"ARCH"),': return the architecture Task was compiled to: "386", "amd64", "arm"\nor "s390x".'),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"splitLines"),": Splits Unix (\\n) and Windows (\\r\\n) styled newlines."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"catLines"),": Replaces Unix (\\n) and Windows (\\r\\n) styled newlines with a space."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"toSlash"),": Does nothing on Unix, but on Windows converts a string from ",(0,i.kt)("inlineCode",{parentName:"li"},"\\"),"\npath format to ",(0,i.kt)("inlineCode",{parentName:"li"},"/"),"."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"fromSlash"),": Opposite of ",(0,i.kt)("inlineCode",{parentName:"li"},"toSlash"),". Does nothing on Unix, but on Windows\nconverts a string from ",(0,i.kt)("inlineCode",{parentName:"li"},"/")," path format to ",(0,i.kt)("inlineCode",{parentName:"li"},"\\"),"."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"exeExt"),": Returns the right executable extension for the current OS\n(",(0,i.kt)("inlineCode",{parentName:"li"},'".exe"')," for Windows, ",(0,i.kt)("inlineCode",{parentName:"li"},'""')," for others)."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"shellQuote"),": Quotes a string to make it safe for use in shell scripts.\nTask uses ",(0,i.kt)("a",{parentName:"li",href:"https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/syntax#Quote"},"this Go function"),"\nfor this. The Bash dialect is assumed."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"splitArgs"),": Splits a string as if it were a command's arguments.\nTask uses ",(0,i.kt)("a",{parentName:"li",href:"https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/shell#Fields"},"this Go function"))),(0,i.kt)("p",null,"Example:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n print-os:\n cmds:\n - echo '{{OS}} {{ARCH}}'\n - echo '{{if eq OS \"windows\"}}windows-command{{else}}unix-command{{end}}'\n # This will be path/to/file on Unix but path\\to\\file on Windows\n - echo '{{fromSlash \"path/to/file\"}}'\n enumerated-file:\n vars:\n CONTENT: |\n foo\n bar\n cmds:\n - |\n cat << EOF > output.txt\n {{range $i, $line := .CONTENT | splitLines -}}\n {{printf \"%3d\" $i}}: {{$line}}\n {{end}}EOF\n")),(0,i.kt)("h2",{id:"help"},"Help"),(0,i.kt)("p",null,"Running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --list")," (or ",(0,i.kt)("inlineCode",{parentName:"p"},"task -l"),") lists all tasks with a description.\nThe following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build:\n desc: Build the go binary.\n cmds:\n - go build -v -i main.go\n\n test:\n desc: Run all the go tests.\n cmds:\n - go test -race ./...\n\n js:\n cmds:\n - esbuild --bundle --minify js/index.js > public/bundle.js\n\n css:\n cmds:\n - esbuild --bundle --minify css/index.css > public/bundle.css\n")),(0,i.kt)("p",null,"would print the following output:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"* build: Build the go binary.\n* test: Run all the go tests.\n")),(0,i.kt)("p",null,"If you want to see all tasks, there's a ",(0,i.kt)("inlineCode",{parentName:"p"},"--list-all")," (alias ",(0,i.kt)("inlineCode",{parentName:"p"},"-a"),") flag as well."),(0,i.kt)("h2",{id:"display-summary-of-task"},"Display summary of task"),(0,i.kt)("p",null,"Running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --summary task-name")," will show a summary of a task.\nThe following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n release:\n deps: [build]\n summary: |\n Release your project to github\n\n It will build your project before starting the release.\n Please make sure that you have set GITHUB_TOKEN before starting.\n cmds:\n - your-release-tool\n\n build:\n cmds:\n - your-build-tool\n")),(0,i.kt)("p",null,"with running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --summary release")," would print the following output:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"task: release\n\nRelease your project to github\n\nIt will build your project before starting the release.\nPlease make sure that you have set GITHUB_TOKEN before starting.\n\ndependencies:\n - build\n\ncommands:\n - your-release-tool\n")),(0,i.kt)("p",null,"If a summary is missing, the description will be printed.\nIf the task does not have a summary or a description, a warning is printed."),(0,i.kt)("p",null,"Please note: ",(0,i.kt)("em",{parentName:"p"},"showing the summary will not execute the command"),"."),(0,i.kt)("h2",{id:"task-aliases"},"Task aliases"),(0,i.kt)("p",null,"Aliases are alternative names for tasks. They can be used to make it easier and\nquicker to run tasks with long or hard-to-type names. You can use them on the\ncommand line, when ",(0,i.kt)("a",{parentName:"p",href:"#calling-another-task"},"calling sub-tasks")," in your Taskfile\nand when ",(0,i.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"including tasks")," with aliases from another\nTaskfile. They can also be used together with ",(0,i.kt)("a",{parentName:"p",href:"#namespace-aliases"},"namespace\naliases"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n generate:\n aliases: [gen]\n cmds:\n - task: gen-mocks\n\n generate-mocks:\n aliases: [gen-mocks]\n cmds:\n - echo \"generating...\"\n")),(0,i.kt)("h2",{id:"overriding-task-name"},"Overriding task name"),(0,i.kt)("p",null,"Sometimes you may want to override the task name printed on the summary, up-to-date\nmessages to STDOUT, etc. In this case, you can just set ",(0,i.kt)("inlineCode",{parentName:"p"},"label:"),", which can also\nbe interpolated with variables:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n - task: print\n vars:\n MESSAGE: hello\n - task: print\n vars:\n MESSAGE: world\n\n print:\n label: 'print-{{.MESSAGE}}'\n cmds:\n - echo \"{{.MESSAGE}}\"\n")),(0,i.kt)("h2",{id:"silent-mode"},"Silent mode"),(0,i.kt)("p",null,"Silent mode disables the echoing of commands before Task runs it.\nFor the following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n")),(0,i.kt)("p",null,"Normally this will be printed:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-sh"},'echo "Print something"\nPrint something\n')),(0,i.kt)("p",null,"With silent mode on, the below will be printed instead:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-sh"},"Print something\n")),(0,i.kt)("p",null,"There are four ways to enable silent mode:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"At command level:")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - cmd: echo \"Print something\"\n silent: true\n")),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"At task level:")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n silent: true\n")),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Globally at Taskfile level:")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nsilent: true\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n")),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Or globally with ",(0,i.kt)("inlineCode",{parentName:"li"},"--silent")," or ",(0,i.kt)("inlineCode",{parentName:"li"},"-s")," flag")),(0,i.kt)("p",null,"If you want to suppress STDOUT instead, just redirect a command to ",(0,i.kt)("inlineCode",{parentName:"p"},"/dev/null"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"This will print nothing\" > /dev/null\n")),(0,i.kt)("h2",{id:"dry-run-mode"},"Dry run mode"),(0,i.kt)("p",null,"Dry run mode (",(0,i.kt)("inlineCode",{parentName:"p"},"--dry"),") compiles and steps through each task, printing the commands\nthat would be run without executing them. This is useful for debugging your Taskfiles."),(0,i.kt)("h2",{id:"ignore-errors"},"Ignore errors"),(0,i.kt)("p",null,"You have the option to ignore errors during command execution.\nGiven the following Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - exit 1\n - echo \"Hello World\"\n")),(0,i.kt)("p",null,"Task will abort the execution after running ",(0,i.kt)("inlineCode",{parentName:"p"},"exit 1")," because the status code ",(0,i.kt)("inlineCode",{parentName:"p"},"1")," stands for ",(0,i.kt)("inlineCode",{parentName:"p"},"EXIT_FAILURE"),".\nHowever, it is possible to continue with execution using ",(0,i.kt)("inlineCode",{parentName:"p"},"ignore_error"),":"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - cmd: exit 1\n ignore_error: true\n - echo \"Hello World\"\n")),(0,i.kt)("p",null,(0,i.kt)("inlineCode",{parentName:"p"},"ignore_error")," can also be set for a task, which means errors will be suppressed\nfor all commands. Nevertheless, keep in mind that this option will not propagate to other tasks\ncalled either by ",(0,i.kt)("inlineCode",{parentName:"p"},"deps")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds"),"!"),(0,i.kt)("h2",{id:"output-syntax"},"Output syntax"),(0,i.kt)("p",null,"By default, Task just redirects the STDOUT and STDERR of the running commands\nto the shell in real-time. This is good for having live feedback for logging\nprinted by commands, but the output can become messy if you have multiple\ncommands running simultaneously and printing lots of stuff."),(0,i.kt)("p",null,"To make this more customizable, there are currently three different output\noptions you can choose:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"interleaved")," (default)"),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"group")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"prefixed"))),(0,i.kt)("p",null,"To choose another one, just set it to root in the Taskfile:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\noutput: 'group'\n\ntasks:\n # ...\n")),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"group")," output will print the entire output of a command once after it\nfinishes, so you will not have live feedback for commands that take a long time\nto run."),(0,i.kt)("p",null,"When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"group")," output, you can optionally provide a templated message\nto print at the start and end of the group. This can be useful for instructing\nCI systems to group all of the output for a given task, such as with\n",(0,i.kt)("a",{parentName:"p",href:"https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#grouping-log-lines"},"GitHub Actions' ",(0,i.kt)("inlineCode",{parentName:"a"},"::group::")," command"),"\nor ",(0,i.kt)("a",{parentName:"p",href:"https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?expand=1&view=azure-devops&tabs=bash#formatting-commands"},"Azure Pipelines"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\noutput:\n group:\n begin: '::group::{{.TASK}}'\n end: '::endgroup::'\n\ntasks:\n default:\n cmds:\n - echo 'Hello, World!'\n silent: true\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ task default\n::group::default\nHello, World!\n::endgroup::\n")),(0,i.kt)("p",null,"When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"group")," output, you may swallow the output of the executed command\non standard output and standard error if it does not fail (zero exit code)."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nsilent: true\n\noutput:\n group:\n error_only: true\n\ntasks:\n passes: echo 'output-of-passes'\n errors: echo 'output-of-errors' && exit 1\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},'$ task passes\n$ task errors\noutput-of-errors\ntask: Failed to run task "errors": exit status 1\n')),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"prefix")," output will prefix every line printed by a command with\n",(0,i.kt)("inlineCode",{parentName:"p"},"[task-name] ")," as the prefix, but you can customize the prefix for a command\nwith the ",(0,i.kt)("inlineCode",{parentName:"p"},"prefix:")," attribute:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},'version: \'3\'\n\noutput: prefixed\n\ntasks:\n default:\n deps:\n - task: print\n vars: {TEXT: foo}\n - task: print\n vars: {TEXT: bar}\n - task: print\n vars: {TEXT: baz}\n\n print:\n cmds:\n - echo "{{.TEXT}}"\n prefix: "print-{{.TEXT}}"\n silent: true\n')),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-bash"},"$ task default\n[print-foo] foo\n[print-bar] bar\n[print-baz] baz\n")),(0,i.kt)("admonition",{type:"tip"},(0,i.kt)("p",{parentName:"admonition"},"The ",(0,i.kt)("inlineCode",{parentName:"p"},"output")," option can also be specified by the ",(0,i.kt)("inlineCode",{parentName:"p"},"--output")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"-o")," flags.")),(0,i.kt)("h2",{id:"interactive-cli-application"},"Interactive CLI application"),(0,i.kt)("p",null,"When running interactive CLI applications inside Task they can sometimes behave\nweirdly, especially when the ",(0,i.kt)("a",{parentName:"p",href:"#output-syntax"},"output mode")," is set to something\nother than ",(0,i.kt)("inlineCode",{parentName:"p"},"interleaved")," (the default), or when interactive apps are run in\nparallel with other tasks."),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},"interactive: true")," tells Task this is an interactive application and Task\nwill try to optimize for it:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n default:\n cmds:\n - vim my-file.txt\n interactive: true\n")),(0,i.kt)("p",null,"If you still have problems running an interactive app through Task, please open\nan issue about it."),(0,i.kt)("h2",{id:"short-task-syntax"},"Short task syntax"),(0,i.kt)("p",null,"Starting on Task v3, you can now write tasks with a shorter syntax if they\nhave the default settings (e.g. no custom ",(0,i.kt)("inlineCode",{parentName:"p"},"env:"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"vars:"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"desc:"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"silent:")," , etc):"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n build: go build -v -o ./app{{exeExt}} .\n\n run:\n - task: build\n - ./app{{exeExt}} -h localhost -p 8080\n")),(0,i.kt)("h2",{id:"set-and-shopt"},(0,i.kt)("inlineCode",{parentName:"h2"},"set")," and ",(0,i.kt)("inlineCode",{parentName:"h2"},"shopt")),(0,i.kt)("p",null,"It's possible to specify options to the\n",(0,i.kt)("a",{parentName:"p",href:"https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html"},(0,i.kt)("inlineCode",{parentName:"a"},"set")),"\nand ",(0,i.kt)("a",{parentName:"p",href:"https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html"},(0,i.kt)("inlineCode",{parentName:"a"},"shopt")),"\nbuiltins. This can be added at global, task or command level."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nset: [pipefail]\nshopt: [globstar]\n\ntasks:\n # `globstar` required for double star globs to work\n default: echo **/*.go\n")),(0,i.kt)("admonition",{type:"info"},(0,i.kt)("p",{parentName:"admonition"},"Keep in mind that not all options are available in the\n",(0,i.kt)("a",{parentName:"p",href:"https://github.com/mvdan/sh"},"shell interpreter library")," that Task uses.")),(0,i.kt)("h2",{id:"watch-tasks"},"Watch tasks"),(0,i.kt)("p",null,"With the flags ",(0,i.kt)("inlineCode",{parentName:"p"},"--watch")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"-w")," task will watch for file changes\nand run the task again. This requires the ",(0,i.kt)("inlineCode",{parentName:"p"},"sources")," attribute to be given,\nso task knows which files to watch."),(0,i.kt)("p",null,"The default watch interval is 5 seconds, but it's possible to change it by\neither setting ",(0,i.kt)("inlineCode",{parentName:"p"},"interval: '500ms'")," in the root of the Taskfile passing it\nas an argument like ",(0,i.kt)("inlineCode",{parentName:"p"},"--interval=500ms"),"."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/runtime~main.41cc59d1.js b/assets/js/runtime~main.41568f2f.js similarity index 98% rename from assets/js/runtime~main.41cc59d1.js rename to assets/js/runtime~main.41568f2f.js index b40d433b..055cfeb4 100644 --- a/assets/js/runtime~main.41cc59d1.js +++ b/assets/js/runtime~main.41568f2f.js @@ -1 +1 @@ -!function(){"use strict";var e,t,n,r,o,f={},u={};function i(e){var t=u[e];if(void 0!==t)return t.exports;var n=u[e]={id:e,loaded:!1,exports:{}};return f[e].call(n.exports,n,n.exports,i),n.loaded=!0,n.exports}i.m=f,i.c=u,e=[],i.O=function(t,n,r,o){if(!n){var f=1/0;for(d=0;d=o)&&Object.keys(i.O).every((function(e){return i.O[e](n[a])}))?n.splice(a--,1):(u=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[n,r,o]},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,{a:t}),t},n=Object.getPrototypeOf?function(e){return Object.getPrototypeOf(e)}:function(e){return e.__proto__},i.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var o=Object.create(null);i.r(o);var f={};t=t||[null,n({}),n([]),n(n)];for(var u=2&r&&e;"object"==typeof u&&!~t.indexOf(u);u=n(u))Object.getOwnPropertyNames(u).forEach((function(t){f[t]=function(){return e[t]}}));return f.default=function(){return e},i.d(o,f),o},i.d=function(e,t){for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.f={},i.e=function(e){return Promise.all(Object.keys(i.f).reduce((function(t,n){return i.f[n](e,t),t}),[]))},i.u=function(e){return"assets/js/"+({34:"9beb87c2",53:"935f2afb",80:"4d54d076",133:"f1d66b0d",217:"3b8c55ea",252:"02371786",514:"1be78505",552:"0afd354a",582:"f7fd502c",595:"d0766b26",648:"3c140c84",671:"0e384e19",705:"7d415946",713:"1c56b476",827:"6476eba6",836:"0480b142",880:"5ef0e9d6",918:"17896441",920:"1a4e3797"}[e]||e)+"."+{34:"ae7d3c47",53:"8872dd05",80:"5e69e92c",133:"6862b446",217:"6a334942",252:"2e4dab92",514:"9062895a",552:"e8bad103",582:"91900bbc",595:"c5627647",648:"b629b889",671:"649e4736",705:"6bf3701e",713:"63036b78",780:"b979b06f",827:"af576646",836:"098568bb",880:"9579102c",894:"4bf7d380",918:"e75765f6",920:"a9132d06",945:"3694633c",972:"01a5a892"}[e]+".js"},i.miniCssF=function(e){},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r={},o="taskfile-dev:",i.l=function(e,t,n,f){if(r[e])r[e].push(t);else{var u,a;if(void 0!==n)for(var c=document.getElementsByTagName("script"),d=0;d=o)&&Object.keys(i.O).every((function(e){return i.O[e](n[a])}))?n.splice(a--,1):(u=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[n,r,o]},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,{a:t}),t},n=Object.getPrototypeOf?function(e){return Object.getPrototypeOf(e)}:function(e){return e.__proto__},i.t=function(e,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var o=Object.create(null);i.r(o);var f={};t=t||[null,n({}),n([]),n(n)];for(var u=2&r&&e;"object"==typeof u&&!~t.indexOf(u);u=n(u))Object.getOwnPropertyNames(u).forEach((function(t){f[t]=function(){return e[t]}}));return f.default=function(){return e},i.d(o,f),o},i.d=function(e,t){for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.f={},i.e=function(e){return Promise.all(Object.keys(i.f).reduce((function(t,n){return i.f[n](e,t),t}),[]))},i.u=function(e){return"assets/js/"+({34:"9beb87c2",53:"935f2afb",80:"4d54d076",133:"f1d66b0d",217:"3b8c55ea",252:"02371786",514:"1be78505",552:"0afd354a",582:"f7fd502c",595:"d0766b26",648:"3c140c84",671:"0e384e19",705:"7d415946",713:"1c56b476",827:"6476eba6",836:"0480b142",880:"5ef0e9d6",918:"17896441",920:"1a4e3797"}[e]||e)+"."+{34:"ae7d3c47",53:"8872dd05",80:"5e69e92c",133:"6862b446",217:"6a334942",252:"2e4dab92",514:"9062895a",552:"e8bad103",582:"91900bbc",595:"c5627647",648:"b629b889",671:"649e4736",705:"6bf3701e",713:"63036b78",780:"b979b06f",827:"f5165ba7",836:"098568bb",880:"9579102c",894:"4bf7d380",918:"e75765f6",920:"a9132d06",945:"3694633c",972:"01a5a892"}[e]+".js"},i.miniCssF=function(e){},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r={},o="taskfile-dev:",i.l=function(e,t,n,f){if(r[e])r[e].push(t);else{var u,a;if(void 0!==n)for(var c=document.getElementsByTagName("script"),d=0;d