diff --git a/zh-Hans/404.html b/zh-Hans/404.html index b63289f5..e59c95a9 100644 --- a/zh-Hans/404.html +++ b/zh-Hans/404.html @@ -10,13 +10,13 @@ - +
跳到主要内容

找不到页面

我们找不到您要找的页面。

请联系原始链接来源网站的所有者,并告知他们链接已损坏。

- + \ No newline at end of file diff --git a/zh-Hans/api/index.html b/zh-Hans/api/index.html index 83f40555..82e8ec3b 100644 --- a/zh-Hans/api/index.html +++ b/zh-Hans/api/index.html @@ -10,13 +10,13 @@ - +
跳到主要内容

API 参考

命令行

该命令的语法如下:

task [--flags] [tasks...] [-- CLI_ARGS...]
提示

如果 -- 给出,所有剩余参数将被分配给一个特殊的 CLI_ARGS 变量

缩写标志类型默认描述
-c--colorbooltrue彩色输出。 默认开启。 设置为 false 或使用 NO_COLOR=1 禁用。
-C--concurrencyint0限制并发运行的任务数。 零意味着无限。
-d--dirstring工作目录设置执行目录。
-n--dryboolfalse按运行顺序编译和打印任务,而不执行它们。
-x--exit-codeboolfalse传递任务命令的退出代码。
-f--forceboolfalse即使任务是最新的也强制执行。
-g--globalboolfalse$HOME/Taskfile.{yml,yaml} 运行全局任务文件。
-h--helpboolfalse显示任务使用情况。
-i--initboolfalse在当前目录创建一个新的 Taskfile.yml。
-I--intervalstring5s使用 --watch 设置不同的观察间隔,默认为 5 秒。 这个字符串应该是一个有效的 Go Duration
-l--listboolfalse列出当前文件的全部任务及对应描述。
-a--list-allboolfalse列出无论有没有描述的所有任务。
--jsonboolfalse查看 JSON 输出
-o--outputstring在 Taskfile 中设置默认值或 intervealed设置输出样式:[interleaved/group/prefixed]
--output-group-beginstring在任务组输出前打印的消息模板。
--output-group-endstring在任务组输出后打印的消息模板。
--output-group-error-onlyboolfalse在退出码为 0 时忽略命令输出。
-p--parallelboolfalse并行执行命令行上提供的任务。
-s--silentboolfalse禁用回显。
--statusboolfalse如果任何给定任务不是最新的,则以非 0 退出码退出。
--summaryboolfalse显示有关任务的摘要。
-t--taskfilestringTaskfile.ymlTaskfile.yaml
-v--verboseboolfalse启用详细模式。
--versionboolfalse显示 Task 版本。
-w--watchboolfalse启用给定任务的观察器。

JSON 输出

--json 标志与 --list--list-all 标志结合使用时,将输出具有以下结构的 JSON 对象:

{
"tasks": [
{
"name": "",
"desc": "",
"summary": "",
"up_to_date": false,
"location": {
"line": 54,
"column": 3,
"taskfile": "/path/to/Taskfile.yml"
}
},
// ...
],
"location": "/path/to/Taskfile.yml"
}

特殊变量

模板系统上有一些可用的特殊变量:

变量描述
CLI_ARGS当通过 CLI 调用 Task 时,传递包含在 -- 之后的所有额外参数。
TASK当前任务的名称。
ROOT_DIR根 Taskfile 的绝对路径。
TASKFILE_DIR包含 Taskfile 的绝对路径
USER_WORKING_DIR调用 task 的目录的绝对路径。
CHECKSUMsources 中列出的文件的 checksum。 仅在 status 参数中可用,并且如果方法设置为 checksum
TIMESTAMPsources 中列出的文件的最大时间戳的日期对象。 仅在 status 参数中可用,并且如果方法设置为 timestamp
TASK_VERSIONTask 的当前版本。

环境变量

可以覆盖某些环境变量以调整 Task 行为。

环境变量默认描述
TASK_TEMP_DIR.task临时目录的位置。 可以相对于项目比如 tmp/task 或绝对如 /tmp/.task~/.task
TASK_COLOR_RESET0用于白色的颜色。
TASK_COLOR_BLUE34用于蓝色的颜色。
TASK_COLOR_GREEN32用于绿色的颜色。
TASK_COLOR_CYAN36用于青色的颜色。
TASK_COLOR_YELLOW33用于黄色的颜色。
TASK_COLOR_MAGENTA35用于洋红色的颜色。
TASK_COLOR_RED31用于红色的颜色。
FORCE_COLOR强制使用颜色输出。

Taskfile Schema

属性类型默认描述
versionstringTaskfile 的版本。 当前版本是 3
outputstringinterleaved输出模式。 可用选项: interleavedgroupprefixed
methodstringchecksumTaskfile 中的默认方法。 可以在任务基础上覆盖。 可用选项:checksumtimestampnone
includesmap[string]Include要包含的其他 Taskfile。
varsmap[string]Variable一组全局变量。
envmap[string]Variable一组全局环境变量。
tasksmap[string]Task一组任务定义。
silentboolfalse此任务文件的默认“silent”选项。 如果为 false,则可以在任务的基础上用 true 覆盖。
dotenv[]string要解析的 .env 文件路径列表。
runstringalwaysTaskfile 中默认的 'run' 选项。 可用选项: alwaysoncewhen_changed
intervalstring5s设置 --watch 模式下的观察时间,默认 5 秒。 这个字符串应该是一个有效的 Go Duration
set[]string内置 set 指定选项。
shopt[]string内置 shopt 指定选项。

Include

属性类型默认描述
taskfilestring要包含的 Taskfile 或目录的路径。 如果是目录,Task 将在该目录中查找名为 Taskfile.ymlTaskfile.yaml 的文件。 如果是相对路径,则相对于包含 Taskfile 的目录进行解析。
dirstringTaskfile 文件父目录运行时包含的任务的工作目录。
optionalboolfalse设置为 true 时, 文件不存在也不会报错
internalboolfalse停止在命令行上调用包含的任务文件中的任何任务。 当与 --list 一起使用时,这些命令也将从输出中省略。
aliases[]string包含的 Taskfile 的命名空间的替代名称。
varsmap[string]Variable一组应用于包含的 Taskfile 的变量。
信息

像下面这样只赋值一个字符串,和把这个值设置到 taskfile 属性是一样的。

includes:
foo: ./path

Variable

属性类型默认描述
itselfstring将设置为变量的静态值。
shstring一个 shell 命令。 输出 (STDOUT) 将分配给变量。
信息

静态和动态变量有不同的语法,如下所示:

vars:
STATIC: static
DYNAMIC:
sh: echo "dynamic"

Task

属性类型默认描述
cmds[]Command要执行的 shell 命令列表。
deps[]Dependency此任务的依赖项列表。 此处定义的任务将在此任务之前并行运行。
labelstring运行任务时覆盖输出中的任务名称。 支持变量。
descstringTask 的简短描述。 这在调用 task --list 时显示。
summarystring任务的较长描述。 这在调用 task --summary [task] 时显示。
aliases[]string可以调用任务的别名列表。
sources[]string运行此任务之前要检查的源列表。 与 checksumtimestamp 相关。 可以是文件路径或星号。
generates[]string此任务要生成的文件列表。 与 timestamp 方法相关。 可以是文件路径或星号。
status[]string用于检查此 task 是否应运行的命令列表。 否则跳过该任务。 这个方法会覆盖 methodsourcesgenerates
preconditions[]Precondition用于检查此任务是否应运行的命令列表。 如果不满足条件,任务将出错。
dirstring此 task 应运行的目录。 默认为当前工作目录。
varsmap[string]Variable可在 task 中使用的一组变量。
envmap[string]Variable一组可用于 shell 命令的环境变量。
dotenv[]string要解析的 .env 文件路径列表。
silentboolfalse从输出中隐藏任务名称和命令。 命令的输出仍将重定向到 STDOUTSTDERR。 当与 --list 标志结合使用时,任务描述将被隐藏。
interactiveboolfalse告诉任务该命令是交互式的。
internalboolfalse停止在命令行上调用任务。 当与 --list 一起使用时,它也会从输出中省略。
methodstringchecksum定义用于检查任务是最新的方法。 timestamp 将比较源的时间戳并生成文件。 checksum 将检查 checksum(您可能想忽略 .gitignore 文件中的 .task 文件夹)。 none 跳过任何验证并始终运行任务。
prefixstring定义一个字符串作为并行运行 task 输出的前缀。 仅在输出模式是 prefixed 时使用。
ignore_errorboolfalse如果执行命令时发生错误,则继续执行。
runstringTaskfile 中全局声明的值或 always指定如果多次调用该任务是否应再次运行。 可用选项:alwaysoncewhen_changed
platforms[]string所有平台指定应在哪些平台上运行任务。 允许使用 有效的 GOOS 和 GOARCH 值。 否则将跳过任务。
set[]string内置 set 指定选项。
shopt[]string内置 shopt 指定选项。
信息

这些替代语法可用。 他们会将给定值设置为 cmds,其他所有内容都将设置为其默认值:

tasks:
foo: echo "foo"

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

baz:
cmd: echo "baz"

Command

属性类型默认描述
cmdstring要执行的 shell 命令
silentboolfalse跳过此命令的一些输出。 请注意,命令的 STDOUT 和 STDERR 仍将被重定向。
taskstring执行另一个 task,而不执行命令。 不能与 cmd 同时设置。
varsmap[string]Variable要传递给引用任务的可选附加变量。 仅在设置 task 而不是 cmd 时相关。
ignore_errorboolfalse执行命令的时候忽略错误,继续执行
deferstringcmd 的替代方法,但安排命令在此任务结束时执行,而不是立即执行。 不能与 cmd 一同使用。
platforms[]string所有平台指定应在哪些平台上运行该命令。 允许使用 有效的 GOOS 和 GOARCH 值。 否则将跳过命令。
set[]string内置 set 指定选项。
shopt[]string内置 shopt 指定选项。
信息

如果以字符串形式给出,该值将分配给 cmd

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

Dependency

属性类型默认描述
taskstring要作为依赖项执行的任务。
varsmap[string]Variable要传递给此任务的可选附加变量。
提示

如果你不想设置额外的变量,将依赖关系声明为一个字符串列表就足够了(它们将被分配给 task)。

tasks:
foo:
deps: [foo, bar]

Precondition

属性类型默认描述
shstring要执行的命令。 如果返回非零退出码,任务将在不执行其命令的情况下出错。
msgstring如果不满足先决条件,则打印可选消息。
提示

如果你不想设置不同的消息,你可以像这样声明一个前提条件,值将被分配给 sh

tasks:
foo:
precondition: test -f Taskfile.yml
- + \ No newline at end of file diff --git a/zh-Hans/assets/js/01713e21.3f827c94.js b/zh-Hans/assets/js/01713e21.3f827c94.js new file mode 100644 index 00000000..d71fb6f4 --- /dev/null +++ b/zh-Hans/assets/js/01713e21.3f827c94.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunktaskfile_dev=self.webpackChunktaskfile_dev||[]).push([[701],{3905:function(e,n,t){t.d(n,{Zo:function(){return d},kt:function(){return c}});var a=t(7294);function l(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(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||(l[t]=e[t]);return l}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(l[t]=e[t])}return l}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)},k="mdxType",m={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},u=a.forwardRef((function(e,n){var t=e.components,l=e.mdxType,i=e.originalType,r=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),k=p(t),u=l,c=k["".concat(r,".").concat(u)]||k[u]||m[u]||i;return t?a.createElement(c,s(s({ref:n},d),{},{components:t})):a.createElement(c,s({ref:n},d))}));function c(e,n){var t=arguments,l=n&&n.mdxType;if("string"==typeof e||l){var i=t.length,s=new Array(i);s[0]=u;var o={};for(var r in n)hasOwnProperty.call(n,r)&&(o[r]=n[r]);o.originalType=e,o[k]="string"==typeof e?e:l,s[1]=o;for(var p=2;pdefer \u505a task \u6e05\u7406",id:"\u4f7f\u7528-defer-\u505a-task-\u6e05\u7406",level:2},{value:"Go \u7684\u6a21\u677f\u5f15\u64ce",id:"go-\u7684\u6a21\u677f\u5f15\u64ce",level:2},{value:"\u5e2e\u52a9",id:"\u5e2e\u52a9",level:2},{value:"\u663e\u793a\u4efb\u52a1\u6458\u8981",id:"\u663e\u793a\u4efb\u52a1\u6458\u8981",level:2},{value:"Task \u522b\u540d",id:"task-\u522b\u540d",level:2},{value:"\u91cd\u5199 Task \u540d\u79f0",id:"\u91cd\u5199-task-\u540d\u79f0",level:2},{value:"\u9759\u9ed8\u6a21\u5f0f",id:"\u9759\u9ed8\u6a21\u5f0f",level:2},{value:"\u8bd5\u8fd0\u884c\u6a21\u5f0f",id:"\u8bd5\u8fd0\u884c\u6a21\u5f0f",level:2},{value:"\u5ffd\u7565\u9519\u8bef",id:"\u5ffd\u7565\u9519\u8bef",level:2},{value:"\u8f93\u51fa\u8bed\u6cd5",id:"\u8f93\u51fa\u8bed\u6cd5",level:2},{value:"\u4ea4\u4e92\u5f0f CLI \u5e94\u7528",id:"\u4ea4\u4e92\u5f0f-cli-\u5e94\u7528",level:2},{value:"\u77ed Task \u8bed\u6cd5",id:"\u77ed-task-\u8bed\u6cd5",level:2},{value:"set \u548c shopt",id:"set-\u548c-shopt",level:2},{value:"\u89c2\u5bdf\u4efb\u52a1",id:"\u89c2\u5bdf\u4efb\u52a1",level:2}],d={toc:p};function k(e){let{components:n,...t}=e;return(0,l.kt)("wrapper",(0,a.Z)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,l.kt)("h1",{id:"\u4f7f\u7528\u6307\u5357"},"\u4f7f\u7528\u6307\u5357"),(0,l.kt)("h2",{id:"\u5feb\u901f\u5165\u95e8"},"\u5feb\u901f\u5165\u95e8"),(0,l.kt)("p",null,"\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile.yml")," \u7684\u6587\u4ef6\u3002 ",(0,l.kt)("inlineCode",{parentName:"p"},"cmds")," \u5c5e\u6027\u5e94\u5305\u542b task \u7684\u547d\u4ee4\u3002 \u4e0b\u9762\u7684\u793a\u4f8b\u5141\u8bb8\u7f16\u8bd1 Go \u5e94\u7528\u7a0b\u5e8f\u5e76\u4f7f\u7528 ",(0,l.kt)("a",{parentName:"p",href:"https://esbuild.github.io/"},"esbuild")," \u5c06\u591a\u4e2a CSS \u6587\u4ef6\u5408\u5e76\u5e76\u7f29\u5c0f\u4e3a\u4e00\u4e2a\u6587\u4ef6\u3002"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u8fd0\u884c task \u5c31\u8fd9\u6837\u7b80\u5355\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"task assets build\n")),(0,l.kt)("p",null,"Task \u4f7f\u7528 ",(0,l.kt)("a",{parentName:"p",href:"https://mvdan.cc/sh/"},"mvdan.cc/sh"),"\uff0c\u4e00\u4e2a\u539f\u751f\u7684 Go sh \u89e3\u91ca\u5668\u3002 \u56e0\u6b64\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199 sh/bash \u547d\u4ee4\uff0c\u5b83\u751a\u81f3\u53ef\u4ee5\u5728 Windows \u4e0a\u8fd0\u884c\uff0c\u800c ",(0,l.kt)("inlineCode",{parentName:"p"},"sh")," \u6216 ",(0,l.kt)("inlineCode",{parentName:"p"},"bash")," \u901a\u5e38\u4e0d\u53ef\u7528\u3002 \u8bf7\u8bb0\u4f4f\uff0c\u4efb\u4f55\u88ab\u8c03\u7528\u7684\u53ef\u6267\u884c\u6587\u4ef6\u90fd\u5fc5\u987b\u5728\u64cd\u4f5c\u7cfb\u7edf\u6216 PATH \u4e2d\u53ef\u7528\u3002"),(0,l.kt)("p",null,'\u5982\u679c\u4e0d\u4f20 task \u7684\u540d\u5b57\uff0c\u9ed8\u8ba4\u4f1a\u8c03\u7528 "default"\u3002'),(0,l.kt)("h2",{id:"\u652f\u6301\u7684\u6587\u4ef6\u540d\u79f0"},"\u652f\u6301\u7684\u6587\u4ef6\u540d\u79f0"),(0,l.kt)("p",null,"Task \u4f1a\u6309\u4ee5\u4e0b\u987a\u5e8f\u67e5\u627e\u914d\u7f6e\u6587\u4ef6:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"Taskfile.yml"),(0,l.kt)("li",{parentName:"ul"},"Taskfile.yaml"),(0,l.kt)("li",{parentName:"ul"},"Taskfile.dist.yml"),(0,l.kt)("li",{parentName:"ul"},"Taskfile.dist.yaml")),(0,l.kt)("p",null,"\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},".dist")," \u53d8\u4f53\u7684\u76ee\u7684\u662f\u5141\u8bb8\u9879\u76ee\u6709\u4e00\u4e2a\u63d0\u4ea4\u7248\u672c (",(0,l.kt)("inlineCode",{parentName:"p"},".dist"),")\uff0c\u540c\u65f6\u4ecd\u7136\u5141\u8bb8\u4e2a\u4eba\u7528\u6237\u901a\u8fc7\u6dfb\u52a0\u989d\u5916\u7684 ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile.yml"),"\uff08\u5c06\u5728 ",(0,l.kt)("inlineCode",{parentName:"p"},".gitignore")," \u4e0a\uff09\u6765\u8986\u76d6 Taskfile\u3002"),(0,l.kt)("h3",{id:"\u4ece\u5b50\u76ee\u5f55\u8fd0\u884c-taskfile"},"\u4ece\u5b50\u76ee\u5f55\u8fd0\u884c Taskfile"),(0,l.kt)("p",null,"\u5982\u679c\u5728\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4e2d\u627e\u4e0d\u5230 Taskfile\uff0c\u5b83\u5c06\u6cbf\u7740\u6587\u4ef6\u6811\u5411\u4e0a\u67e5\u627e\uff0c\u76f4\u5230\u627e\u5230\u4e00\u4e2a\uff08\u7c7b\u4f3c\u4e8e ",(0,l.kt)("inlineCode",{parentName:"p"},"git")," \u7684\u5de5\u4f5c\u65b9\u5f0f\uff09\u3002 \u5f53\u4ece\u8fd9\u6837\u7684\u5b50\u76ee\u5f55\u8fd0\u884c Task \u65f6\uff0c\u5b83\u7684\u884c\u4e3a\u5c31\u50cf\u4ece\u5305\u542b Taskfile \u7684\u76ee\u5f55\u8fd0\u884c\u5b83\u4e00\u6837\u3002"),(0,l.kt)("p",null,"\u60a8\u53ef\u4ee5\u5c06\u6b64\u529f\u80fd\u4e0e\u7279\u6b8a\u7684 ",(0,l.kt)("inlineCode",{parentName:"p"},"{{.USER_WORKING_DIR}}")," \u53d8\u91cf\u4e00\u8d77\u4f7f\u7528\u6765\u521b\u5efa\u4e00\u4e9b\u975e\u5e38\u6709\u7528\u7684\u53ef\u91cd\u7528 task\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5305\u542b\u6bcf\u4e2a\u5fae\u670d\u52a1\u76ee\u5f55\u7684 monorepo\uff0c\u4f60\u53ef\u4ee5 ",(0,l.kt)("inlineCode",{parentName:"p"},"cd")," \u8fdb\u5165\u4e00\u4e2a\u5fae\u670d\u52a1\u76ee\u5f55\u5e76\u8fd0\u884c\u4e00\u4e2a task \u547d\u4ee4\u6765\u542f\u52a8\u5b83\uff0c\u800c\u4e0d\u5fc5\u521b\u5efa\u591a\u4e2a task \u6216\u5177\u6709\u76f8\u540c\u5185\u5bb9\u7684 Taskfile\u3002 \u4f8b\u5982\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"cd ")," \u548c ",(0,l.kt)("inlineCode",{parentName:"p"},"task up"),"\uff0c\u53ea\u8981 ",(0,l.kt)("inlineCode",{parentName:"p"},"")," \u76ee\u5f55\u5305\u542b ",(0,l.kt)("inlineCode",{parentName:"p"},"docker-compose.yml"),"\uff0c\u5c31\u4f1a\u542f\u52a8 Docker Compose\u3002"),(0,l.kt)("h3",{id:"\u8fd0\u884c\u5168\u5c40-taskfile"},"\u8fd0\u884c\u5168\u5c40 Taskfile"),(0,l.kt)("p",null,"If you call Task with the ",(0,l.kt)("inlineCode",{parentName:"p"},"--global")," (alias ",(0,l.kt)("inlineCode",{parentName:"p"},"-g"),") flag, it will look for your home directory instead of your working directory. In short, Task will look for a Taskfile on either ",(0,l.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yml")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yaml")," paths."),(0,l.kt)("p",null,"\u8fd9\u5bf9\u4e8e\u60a8\u53ef\u4ee5\u5728\u7cfb\u7edf\u7684\u4efb\u4f55\u5730\u65b9\u8fd0\u884c\u7684\u81ea\u52a8\u5316\u5f88\u6709\u7528\uff01"),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"When running your global Taskfile with ",(0,l.kt)("inlineCode",{parentName:"p"},"-g"),", tasks will run on ",(0,l.kt)("inlineCode",{parentName:"p"},"$HOME")," by default, and not on your working directory!"),(0,l.kt)("p",{parentName:"admonition"},"As mentioned in the previous section, the ",(0,l.kt)("inlineCode",{parentName:"p"},"{{.USER_WORKING_DIR}}")," special variable can be very handy here to run stuff on the directory you're calling ",(0,l.kt)("inlineCode",{parentName:"p"},"task -g")," from."),(0,l.kt)("pre",{parentName:"admonition"},(0,l.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,l.kt)("h2",{id:"\u73af\u5883\u53d8\u91cf"},"\u73af\u5883\u53d8\u91cf"),(0,l.kt)("h3",{id:"task"},"Task"),(0,l.kt)("p",null,"\u4f60\u53ef\u4ee5\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"env")," \u7ed9\u6bcf\u4e2a task \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u73af\u5883\u53d8\u91cf:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u6b64\u5916\uff0c\u60a8\u53ef\u4ee5\u8bbe\u7f6e\u53ef\u7528\u4e8e\u6240\u6709 task \u7684\u5168\u5c40\u73af\u5883\u53d8\u91cf\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},(0,l.kt)("inlineCode",{parentName:"p"},"env")," \u652f\u6301\u6269\u5c55\u548c\u68c0\u7d22 shell \u547d\u4ee4\u7684\u8f93\u51fa\uff0c\u5c31\u50cf\u53d8\u91cf\u4e00\u6837\uff0c\u5982\u60a8\u5728 ",(0,l.kt)("a",{parentName:"p",href:"#%E5%8F%98%E9%87%8F"},"\u53d8\u91cf")," \u90e8\u5206\u4e2d\u770b\u5230\u7684\u90a3\u6837\u3002")),(0,l.kt)("h3",{id:"env-\u6587\u4ef6"},".env \u6587\u4ef6"),(0,l.kt)("p",null,"\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"dotenv:")," \u8bbe\u7f6e\u8981\u6c42 tasks \u5305\u542b ",(0,l.kt)("inlineCode",{parentName:"p"},".env")," \u4e4b\u7c7b\u7684\u6587\u4ef6"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash",metastring:'title=".env"',title:'".env"'},"KEYNAME=VALUE\n")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash",metastring:'title="testing/.env"',title:'"testing/.env"'},"ENDPOINT=testing.com\n")),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u4e5f\u53ef\u4ee5\u5728 task \u7ea7\u522b\u6307\u5b9a .env \u6587\u4ef6\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u5728 task \u7ea7\u522b\u660e\u786e\u6307\u5b9a\u7684\u73af\u5883\u53d8\u91cf\u5c06\u8986\u76d6\u70b9\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"\u8bf7\u6ce8\u610f\uff0c\u60a8\u76ee\u524d\u65e0\u6cd5\u5728\u5305\u542b\u7684 Taskfile \u4e2d\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"dotenv")," \u952e\u3002")),(0,l.kt)("h2",{id:"\u5305\u542b\u5176\u4ed6-taskfile"},"\u5305\u542b\u5176\u4ed6 Taskfile"),(0,l.kt)("p",null,"\u5982\u679c\u8981\u5728\u4e0d\u540c\u9879\u76ee\uff08Taskfile\uff09\u4e4b\u95f4\u5171\u4eab\u4efb\u52a1\uff0c\u53ef\u4ee5\u4f7f\u7528\u5bfc\u5165\u673a\u5236\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"includes")," \u5173\u952e\u5b57\u5305\u542b\u5176\u4ed6\u4efb\u52a1\u6587\u4ef6\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"The tasks described in the given Taskfiles will be available with the informed namespace. So, you'd call ",(0,l.kt)("inlineCode",{parentName:"p"},"task docs:serve")," to run the ",(0,l.kt)("inlineCode",{parentName:"p"},"serve")," task from ",(0,l.kt)("inlineCode",{parentName:"p"},"documentation/Taskfile.yml")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"task docker:build")," to run the ",(0,l.kt)("inlineCode",{parentName:"p"},"build")," task from the ",(0,l.kt)("inlineCode",{parentName:"p"},"DockerTasks.yml")," file."),(0,l.kt)("p",null,"\u76f8\u5bf9\u8def\u5f84\u662f\u76f8\u5bf9\u4e8e\u5305\u542b\u5305\u542b Taskfile \u7684\u76ee\u5f55\u89e3\u6790\u7684\u3002"),(0,l.kt)("h3",{id:"\u64cd\u4f5c\u7cfb\u7edf\u7279\u5b9a-taskfile"},"\u64cd\u4f5c\u7cfb\u7edf\u7279\u5b9a Taskfile"),(0,l.kt)("p",null,"With ",(0,l.kt)("inlineCode",{parentName:"p"},"version: '2'"),", task automatically includes any ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_{{OS}}.yml")," if it exists (for example: ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_windows.yml"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_linux.yml")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_darwin.yml"),"). Since this behavior was a bit too implicit, it was removed on version 3, but you still can have a similar behavior by explicitly importing these files:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n build: ./Taskfile_{{OS}}.yml\n")),(0,l.kt)("h3",{id:"\u5305\u542b-taskfile-\u7684\u76ee\u5f55"},"\u5305\u542b Taskfile \u7684\u76ee\u5f55"),(0,l.kt)("p",null,"\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5305\u542b\u7684 Taskfile \u7684 task \u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u8fd0\u884c\uff0c\u5373\u4f7f Taskfile \u5728\u53e6\u4e00\u4e2a\u76ee\u5f55\u4e2d\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u66ff\u4ee3\u8bed\u6cd5\u5f3a\u5236\u5176 task \u5728\u53e6\u4e00\u4e2a\u76ee\u5f55\u4e2d\u8fd0\u884c\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n docs:\n taskfile: ./docs/Taskfile.yml\n dir: ./docs\n")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"\u5305\u542b\u7684 Taskfile \u5fc5\u987b\u4f7f\u7528\u4e0e\u4e3b Taskfile \u4f7f\u7528\u7684\u76f8\u540c\u89c4\u5219\u7248\u672c\u3002")),(0,l.kt)("h3",{id:"\u53ef\u9009-includes"},"\u53ef\u9009 includes"),(0,l.kt)("p",null,"\u5982\u679c\u5305\u542b\u6587\u4ef6\u4e22\u5931\uff0c\u6807\u8bb0\u4e3a\u53ef\u9009\u7684\u5305\u542b\u5c06\u5141\u8bb8 task \u7ee7\u7eed\u6b63\u5e38\u6267\u884c\u3002"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"\u5185\u90e8-includes"},"\u5185\u90e8 includes"),(0,l.kt)("p",null,"Includes marked as internal will set all the tasks of the included file to be internal as well (see the ",(0,l.kt)("a",{parentName:"p",href:"#internal-tasks"},"Internal tasks")," section below). This is useful when including utility tasks that are not intended to be used directly by the user."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n tests:\n taskfile: ./taskfiles/Utils.yml\n internal: true\n")),(0,l.kt)("h3",{id:"\u5305\u542b\u7684-taskfile-\u7684\u53d8\u91cf"},"\u5305\u542b\u7684 Taskfile \u7684\u53d8\u91cf"),(0,l.kt)("p",null,"\u60a8\u8fd8\u53ef\u4ee5\u5728\u5305\u542b Taskfile \u65f6\u6307\u5b9a\u53d8\u91cf\u3002 \u8fd9\u5bf9\u4e8e\u62e5\u6709\u53ef\u4ee5\u8c03\u6574\u751a\u81f3\u591a\u6b21\u5305\u542b\u7684\u53ef\u91cd\u7528 Taskfile \u53ef\u80fd\u5f88\u6709\u7528\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"\u547d\u540d\u7a7a\u95f4\u522b\u540d"},"\u547d\u540d\u7a7a\u95f4\u522b\u540d"),(0,l.kt)("p",null,"When including a Taskfile, you can give the namespace a list of ",(0,l.kt)("inlineCode",{parentName:"p"},"aliases"),". This works in the same way as ",(0,l.kt)("a",{parentName:"p",href:"#task-aliases"},"task aliases")," and can be used together to create shorter and easier-to-type commands."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nincludes:\n generate:\n taskfile: ./taskfiles/Generate.yml\n aliases: [gen]\n")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"Vars declared in the included Taskfile have preference over the variables in the including Taskfile! If you want a variable in an included Taskfile to be overridable, use the ",(0,l.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/defaults.html"},"default function"),": ",(0,l.kt)("inlineCode",{parentName:"p"},"MY_VAR: '{{.MY_VAR | default \"my-default-value\"}}'"),".")),(0,l.kt)("h2",{id:"\u5185\u90e8-tasks"},"\u5185\u90e8 tasks"),(0,l.kt)("p",null,"Internal tasks are tasks that cannot be called directly by the user. They will not appear in the output when running ",(0,l.kt)("inlineCode",{parentName:"p"},"task --list|--list-all"),". Other tasks may call internal tasks in the usual way. This is useful for creating reusable, function-like tasks that have no useful purpose on the command line."),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"task-\u76ee\u5f55"},"Task \u76ee\u5f55"),(0,l.kt)("p",null,"By default, tasks will be executed in the directory where the Taskfile is located. But you can easily make the task run in another folder, informing ",(0,l.kt)("inlineCode",{parentName:"p"},"dir"),":"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u5982\u679c\u8be5\u76ee\u5f55\u4e0d\u5b58\u5728\uff0c",(0,l.kt)("inlineCode",{parentName:"p"},"task")," \u4f1a\u521b\u5efa\u5b83\u3002"),(0,l.kt)("h2",{id:"task-\u4f9d\u8d56"},"Task \u4f9d\u8d56"),(0,l.kt)("blockquote",null,(0,l.kt)("p",{parentName:"blockquote"},"Dependencies run in parallel, so dependencies of a task should not depend one another. If you want to force tasks to run serially, take a look at the ",(0,l.kt)("a",{parentName:"p",href:"#calling-another-task"},"Calling Another Task")," section below.")),(0,l.kt)("p",null,"You may have tasks that depend on others. Just pointing them on ",(0,l.kt)("inlineCode",{parentName:"p"},"deps")," will make them run automatically before running the parent task:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"In the above example, ",(0,l.kt)("inlineCode",{parentName:"p"},"assets")," will always run right before ",(0,l.kt)("inlineCode",{parentName:"p"},"build")," if you run ",(0,l.kt)("inlineCode",{parentName:"p"},"task build"),"."),(0,l.kt)("p",null,"\u4e00\u4e2a\u4efb\u52a1\u53ea\u80fd\u6709\u4f9d\u8d56\u5173\u7cfb\uff0c\u6ca1\u6709\u547d\u4ee4\u6765\u5c06\u4efb\u52a1\u7ec4\u5408\u5728\u4e00\u8d77\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u5982\u679c\u6709\u591a\u4e2a\u4f9d\u8d56\u9879\uff0c\u5b83\u4eec\u603b\u662f\u5e76\u884c\u8fd0\u884c\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u3002"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"You can also make the tasks given by the command line run in parallel by using the ",(0,l.kt)("inlineCode",{parentName:"p"},"--parallel")," flag (alias ",(0,l.kt)("inlineCode",{parentName:"p"},"-p"),"). Example: ",(0,l.kt)("inlineCode",{parentName:"p"},"task --parallel js css"),".")),(0,l.kt)("p",null,"\u5982\u679c\u4f60\u60f3\u5c06\u4fe1\u606f\u4f20\u9012\u7ed9\u4f9d\u8d56\u9879\uff0c\u4f60\u53ef\u4ee5\u50cf ",(0,l.kt)("a",{parentName:"p",href:"#%E8%B0%83%E7%94%A8%E5%8F%A6%E4%B8%80%E4%B8%AA-task"},"\u8c03\u7528\u53e6\u4e00\u4e2a\u4efb\u52a1")," \u4e00\u6837\u4ee5\u76f8\u540c\u7684\u65b9\u5f0f\u8fdb\u884c\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"\u5e73\u53f0\u7279\u5b9a\u7684-tasks-\u548c-cmds"},"\u5e73\u53f0\u7279\u5b9a\u7684 tasks \u548c cmds"),(0,l.kt)("p",null,"If you want to restrict the running of tasks to explicit platforms, this can be achieved using the ",(0,l.kt)("inlineCode",{parentName:"p"},"platforms:")," key. Tasks can be restricted to a specific OS, architecture or a combination of both. On a mismatch, the task or command will be skipped, and no error will be thrown."),(0,l.kt)("p",null,"The values allowed as OS or Arch are valid ",(0,l.kt)("inlineCode",{parentName:"p"},"GOOS")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"GOARCH")," values, as defined by the Go language ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/golang/go/blob/master/src/go/build/syslist.go"},"here"),"."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"build-windows")," task below will run only on Windows, and on any architecture:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"This can be restricted to a specific architecture as follows:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"It is also possible to restrict the task to specific architectures:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"Multiple platforms can be specified as follows:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"Individual commands can also be restricted to specific platforms:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"\u8c03\u7528\u53e6\u4e00\u4e2a-task"},"\u8c03\u7528\u53e6\u4e00\u4e2a task"),(0,l.kt)("p",null,"\u5f53\u4e00\u4e2a task \u6709\u5f88\u591a\u4f9d\u8d56\u65f6\uff0c\u5b83\u4eec\u662f\u5e76\u53d1\u6267\u884c\u7684\u3002 \u8fd9\u901a\u5e38\u4f1a\u5bfc\u81f4\u66f4\u5feb\u7684\u6784\u5efa\u7ba1\u9053\u3002 \u4f46\u662f\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u4e32\u884c\u8c03\u7528\u5176\u4ed6 task\u3002 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"\u5728\u88ab\u8c03\u7528 task \u4e2d\u8986\u76d6\u53d8\u91cf\u5c31\u50cf\u901a\u77e5 ",(0,l.kt)("inlineCode",{parentName:"p"},"vars")," \u5c5e\u6027\u4e00\u6837\u7b80\u5355\uff1a"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"deps")," \u4e5f\u652f\u6301\u4e0a\u8ff0\u8bed\u6cd5\u3002"),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"NOTE: If you want to call a task declared in the root Taskfile from within an ",(0,l.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"included Taskfile"),", add a leading ",(0,l.kt)("inlineCode",{parentName:"p"},":")," like this: ",(0,l.kt)("inlineCode",{parentName:"p"},"task: :task-name"),".")),(0,l.kt)("h2",{id:"\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5de5\u4f5c"},"\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5de5\u4f5c"),(0,l.kt)("h3",{id:"\u901a\u8fc7\u6307\u7eb9\u8bc6\u522b\u672c\u5730\u751f\u6210\u7684\u6587\u4ef6\u53ca\u5176\u6765\u6e90"},"\u901a\u8fc7\u6307\u7eb9\u8bc6\u522b\u672c\u5730\u751f\u6210\u7684\u6587\u4ef6\u53ca\u5176\u6765\u6e90"),(0,l.kt)("p",null,"\u5982\u679c\u4e00\u4e2a task \u751f\u6210\u4e86\u4e00\u4e9b\u4e1c\u897f\uff0c\u4f60\u53ef\u4ee5\u901a\u77e5 task \u6e90\u548c\u751f\u6210\u7684\u6587\u4ef6\uff0c\u8fd9\u6837 task \u5c31\u4f1a\u5728\u4e0d\u9700\u8981\u7684\u65f6\u5019\u963b\u6b62\u8fd0\u884c\u5b83\u4eec\u3002"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"sources")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"generates")," can be files or file patterns. When given, Task will compare the checksum of the source files to determine if it's necessary to run the task. If not, it will just print a message like ",(0,l.kt)("inlineCode",{parentName:"p"},'Task "js" is up to date'),"."),(0,l.kt)("p",null,"If you prefer this check to be made by the modification timestamp of the files, instead of its checksum (content), just set the ",(0,l.kt)("inlineCode",{parentName:"p"},"method")," property to ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamp"),"."),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"In situations where you need more flexibility the ",(0,l.kt)("inlineCode",{parentName:"p"},"status")," keyword can be used. You can even combine the two. See the documentation for ",(0,l.kt)("a",{parentName:"p",href:"#using-programmatic-checks-to-indicate-a-task-is-up-to-date"},"status")," for an example."),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"By default, task stores checksums on a local ",(0,l.kt)("inlineCode",{parentName:"p"},".task")," directory in the project's directory. Most of the time, you'll want to have this directory on ",(0,l.kt)("inlineCode",{parentName:"p"},".gitignore")," (or equivalent) so it isn't committed. (If you have a task for code generation that is committed it may make sense to commit the checksum of that task as well, though)."),(0,l.kt)("p",{parentName:"admonition"},"If you want these files to be stored in another directory, you can set a ",(0,l.kt)("inlineCode",{parentName:"p"},"TASK_TEMP_DIR")," environment variable in your machine. It can contain a relative path like ",(0,l.kt)("inlineCode",{parentName:"p"},"tmp/task")," that will be interpreted as relative to the project directory, or an absolute or home path like ",(0,l.kt)("inlineCode",{parentName:"p"},"/tmp/.task")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"~/.task")," (subdirectories will be created for each project)."),(0,l.kt)("pre",{parentName:"admonition"},(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"export TASK_TEMP_DIR='~/.task'\n"))),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"Each task has only one checksum stored for its ",(0,l.kt)("inlineCode",{parentName:"p"},"sources"),". If you want to distinguish a task by any of its input variables, you can add those variables as part of the task's label, and it will be considered a different task."),(0,l.kt)("p",{parentName:"admonition"},"This is useful if you want to run a task once for each distinct set of inputs until the sources actually change. For example, if the sources depend on the value of a variable, or you if you want the task to rerun if some arguments change even if the source has not.")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The method ",(0,l.kt)("inlineCode",{parentName:"p"},"none")," skips any validation and always run the task.")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"For the ",(0,l.kt)("inlineCode",{parentName:"p"},"checksum")," (default) or ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamp")," method to work, it is only necessary to inform the source files. When the ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamp")," method is used, the last time of the running the task is considered as a generate.")),(0,l.kt)("h3",{id:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u6765\u8868\u793a\u4efb\u52a1\u662f\u6700\u65b0\u7684"},"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u6765\u8868\u793a\u4efb\u52a1\u662f\u6700\u65b0\u7684\u3002"),(0,l.kt)("p",null,"Alternatively, you can inform a sequence of tests as ",(0,l.kt)("inlineCode",{parentName:"p"},"status"),". If no error is returned (exit status 0), the task is considered up-to-date:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"Normally, you would use ",(0,l.kt)("inlineCode",{parentName:"p"},"sources")," in combination with ",(0,l.kt)("inlineCode",{parentName:"p"},"generates")," - but for tasks that generate remote artifacts (Docker images, deploys, CD releases) the checksum source and timestamps require either access to the artifact or for an out-of-band refresh of the ",(0,l.kt)("inlineCode",{parentName:"p"},".checksum")," fingerprint file."),(0,l.kt)("p",null,"Two special variables ",(0,l.kt)("inlineCode",{parentName:"p"},"{{.CHECKSUM}}")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"{{.TIMESTAMP}}")," are available for interpolation within ",(0,l.kt)("inlineCode",{parentName:"p"},"status")," commands, depending on the method assigned to fingerprint the sources. Only ",(0,l.kt)("inlineCode",{parentName:"p"},"source")," globs are fingerprinted."),(0,l.kt)("p",null,"Note that the ",(0,l.kt)("inlineCode",{parentName:"p"},"{{.TIMESTAMP}}"),' variable is a "live" Go ',(0,l.kt)("inlineCode",{parentName:"p"},"time.Time")," struct, and can be formatted using any of the methods that ",(0,l.kt)("inlineCode",{parentName:"p"},"time.Time")," responds to."),(0,l.kt)("p",null,"\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 ",(0,l.kt)("a",{parentName:"p",href:"https://golang.org/pkg/time/"},"Go Time \u6587\u6863"),"\u3002"),(0,l.kt)("p",null,"You can use ",(0,l.kt)("inlineCode",{parentName:"p"},"--force")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"-f")," if you want to force a task to run even when up-to-date."),(0,l.kt)("p",null,"Also, ",(0,l.kt)("inlineCode",{parentName:"p"},"task --status [tasks]...")," will exit with a non-zero exit code if any of the tasks are not up-to-date."),(0,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"status")," can be combined with the ",(0,l.kt)("a",{parentName:"p",href:"#by-fingerprinting-locally-generated-files-and-their-sources"},"fingerprinting")," to have a task run if either the the source/generated artifacts changes, or the programmatic check fails:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u53d6\u6d88\u4efb\u52a1\u53ca\u5176\u4f9d\u8d56\u9879\u7684\u6267\u884c"},"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u53d6\u6d88\u4efb\u52a1\u53ca\u5176\u4f9d\u8d56\u9879\u7684\u6267\u884c"),(0,l.kt)("p",null,"In addition to ",(0,l.kt)("inlineCode",{parentName:"p"},"status")," checks, ",(0,l.kt)("inlineCode",{parentName:"p"},"preconditions")," checks are the logical inverse of ",(0,l.kt)("inlineCode",{parentName:"p"},"status")," checks. That is, if you need a certain set of conditions to be ",(0,l.kt)("em",{parentName:"p"},"true")," you can use the ",(0,l.kt)("inlineCode",{parentName:"p"},"preconditions")," stanza. ",(0,l.kt)("inlineCode",{parentName:"p"},"preconditions")," are similar to ",(0,l.kt)("inlineCode",{parentName:"p"},"status")," lines, except they support ",(0,l.kt)("inlineCode",{parentName:"p"},"sh")," expansion, and they SHOULD all return 0."),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"Preconditions can set specific failure messages that can tell a user what steps to take using the ",(0,l.kt)("inlineCode",{parentName:"p"},"msg")," field."),(0,l.kt)("p",null,"If a task has a dependency on a sub-task with a precondition, and that precondition is not met - the calling task will fail. Note that a task executed with a failing precondition will not run unless ",(0,l.kt)("inlineCode",{parentName:"p"},"--force")," is given."),(0,l.kt)("p",null,"Unlike ",(0,l.kt)("inlineCode",{parentName:"p"},"status"),", which will skip a task if it is up to date and continue executing tasks that depend on it, a ",(0,l.kt)("inlineCode",{parentName:"p"},"precondition")," will fail a task, along with any other tasks that depend on it."),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"\u5728\u4efb\u52a1\u8fd0\u884c\u65f6\u9650\u5236"},"\u5728\u4efb\u52a1\u8fd0\u884c\u65f6\u9650\u5236"),(0,l.kt)("p",null,"If a task executed by multiple ",(0,l.kt)("inlineCode",{parentName:"p"},"cmds")," or multiple ",(0,l.kt)("inlineCode",{parentName:"p"},"deps")," you can control when it is executed using ",(0,l.kt)("inlineCode",{parentName:"p"},"run"),". ",(0,l.kt)("inlineCode",{parentName:"p"},"run")," can also be set at the root of the Taskfile to change the behavior of all the tasks unless explicitly overridden."),(0,l.kt)("p",null,"Supported values for ",(0,l.kt)("inlineCode",{parentName:"p"},"run"),":"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"always")," (default) always attempt to invoke the task regardless of the number of previous executions"),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"once")," only invoke this task once regardless of the number of references"),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"when_changed")," only invokes the task once for each unique set of variables passed into the task")),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"\u53d8\u91cf"},"\u53d8\u91cf"),(0,l.kt)("p",null,"When doing interpolation of variables, Task will look for the below. They are listed below in order of importance (i.e. most important first):"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"Variables declared in the task definition"),(0,l.kt)("li",{parentName:"ul"},"Variables given while calling a task from another (See ",(0,l.kt)("a",{parentName:"li",href:"#calling-another-task"},"Calling another task")," above)"),(0,l.kt)("li",{parentName:"ul"},"Variables of the ",(0,l.kt)("a",{parentName:"li",href:"#including-other-taskfiles"},"included Taskfile")," (when the task is included)"),(0,l.kt)("li",{parentName:"ul"},"Variables of the ",(0,l.kt)("a",{parentName:"li",href:"#vars-of-included-taskfiles"},"inclusion of the Taskfile")," (when the task is included)"),(0,l.kt)("li",{parentName:"ul"},"Global variables (those declared in the ",(0,l.kt)("inlineCode",{parentName:"li"},"vars:")," option in the Taskfile)"),(0,l.kt)("li",{parentName:"ul"},"Environment variables")),(0,l.kt)("p",null,"Example of sending parameters with environment variables:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"$ TASK_VARIABLE=a-value task do-something\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"A special variable ",(0,l.kt)("inlineCode",{parentName:"p"},".TASK")," is always available containing the task name.")),(0,l.kt)("p",null,"Since some shells do not support the above syntax to set environment variables (Windows) tasks also accept a similar style when not at the beginning of the command."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},'$ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!"\n')),(0,l.kt)("p",null,"Example of locally declared vars:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"Example of global vars in a ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile.yml"),":"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"\u52a8\u6001\u53d8\u91cf"},"\u52a8\u6001\u53d8\u91cf"),(0,l.kt)("p",null,"The below syntax (",(0,l.kt)("inlineCode",{parentName:"p"},"sh:")," prop in a variable) is considered a dynamic variable. The value will be treated as a command and the output assigned. If there are one or more trailing newlines, the last newline will be trimmed."),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"This works for all types of variables."),(0,l.kt)("h2",{id:"\u5c06-cli-\u53c2\u6570\u8f6c\u53d1\u5230-cmds"},"\u5c06 CLI \u53c2\u6570\u8f6c\u53d1\u5230 cmds"),(0,l.kt)("p",null,"If ",(0,l.kt)("inlineCode",{parentName:"p"},"--")," is given in the CLI, all following parameters are added to a special ",(0,l.kt)("inlineCode",{parentName:"p"},".CLI_ARGS")," variable. This is useful to forward arguments to another command."),(0,l.kt)("p",null,"The below example will run ",(0,l.kt)("inlineCode",{parentName:"p"},"yarn install"),"."),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"$ task yarn -- install\n")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n yarn:\n cmds:\n - yarn {{.CLI_ARGS}}\n")),(0,l.kt)("h2",{id:"\u4f7f\u7528-defer-\u505a-task-\u6e05\u7406"},"\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"h2"},"defer")," \u505a task \u6e05\u7406"),(0,l.kt)("p",null,"With the ",(0,l.kt)("inlineCode",{parentName:"p"},"defer")," keyword, it's possible to schedule cleanup to be run once the task finishes. The difference with just putting it as the last command is that this command will run even when the task fails."),(0,l.kt)("p",null,"In the example below, ",(0,l.kt)("inlineCode",{parentName:"p"},"rm -rf tmpdir/")," will run even if the third command fails:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"If you want to move the cleanup command into another task, that is possible as well:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"Due to the nature of how the ",(0,l.kt)("a",{parentName:"p",href:"https://go.dev/tour/flowcontrol/13"},"Go's own ",(0,l.kt)("inlineCode",{parentName:"a"},"defer")," work"),", the deferred commands are executed in the reverse order if you schedule multiple of them.")),(0,l.kt)("h2",{id:"go-\u7684\u6a21\u677f\u5f15\u64ce"},"Go \u7684\u6a21\u677f\u5f15\u64ce"),(0,l.kt)("p",null,"Task parse commands as ",(0,l.kt)("a",{parentName:"p",href:"https://golang.org/pkg/text/template/"},"Go's template engine")," before executing them. Variables are accessible through dot syntax (",(0,l.kt)("inlineCode",{parentName:"p"},".VARNAME"),")."),(0,l.kt)("p",null,"All functions by the Go's ",(0,l.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/"},"slim-sprig lib")," are available. The following example gets the current date in a given format:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"Task also adds the following functions:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"OS"),': Returns the operating system. Possible values are "windows", "linux", "darwin" (macOS) and "freebsd".'),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"ARCH"),': return the architecture Task was compiled to: "386", "amd64", "arm" or "s390x".'),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"splitLines"),": Splits Unix (\\n) and Windows (\\r\\n) styled newlines."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"catLines"),": Replaces Unix (\\n) and Windows (\\r\\n) styled newlines with a space."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"toSlash"),": Does nothing on Unix, but on Windows converts a string from ",(0,l.kt)("inlineCode",{parentName:"li"},"\\")," path format to ",(0,l.kt)("inlineCode",{parentName:"li"},"/"),"."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"fromSlash"),": Opposite of ",(0,l.kt)("inlineCode",{parentName:"li"},"toSlash"),". Does nothing on Unix, but on Windows converts a string from ",(0,l.kt)("inlineCode",{parentName:"li"},"/")," path format to ",(0,l.kt)("inlineCode",{parentName:"li"},"\\"),"."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"exeExt"),": Returns the right executable extension for the current OS (",(0,l.kt)("inlineCode",{parentName:"li"},'".exe"')," for Windows, ",(0,l.kt)("inlineCode",{parentName:"li"},'""')," for others)."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"shellQuote"),": Quotes a string to make it safe for use in shell scripts. Task uses ",(0,l.kt)("a",{parentName:"li",href:"https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/syntax#Quote"},"this Go function")," for this. The Bash dialect is assumed."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"splitArgs"),": Splits a string as if it were a command's arguments. Task uses ",(0,l.kt)("a",{parentName:"li",href:"https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/shell#Fields"},"this Go function"))),(0,l.kt)("p",null,"Example:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"\u5e2e\u52a9"},"\u5e2e\u52a9"),(0,l.kt)("p",null,"Running ",(0,l.kt)("inlineCode",{parentName:"p"},"task --list")," (or ",(0,l.kt)("inlineCode",{parentName:"p"},"task -l"),") lists all tasks with a description. The following Taskfile:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"would print the following output:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"* build: Build the go binary.\n* test: Run all the go tests.\n")),(0,l.kt)("p",null,"If you want to see all tasks, there's a ",(0,l.kt)("inlineCode",{parentName:"p"},"--list-all")," (alias ",(0,l.kt)("inlineCode",{parentName:"p"},"-a"),") flag as well."),(0,l.kt)("h2",{id:"\u663e\u793a\u4efb\u52a1\u6458\u8981"},"\u663e\u793a\u4efb\u52a1\u6458\u8981"),(0,l.kt)("p",null,"Running ",(0,l.kt)("inlineCode",{parentName:"p"},"task --summary task-name")," will show a summary of a task. The following Taskfile:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"with running ",(0,l.kt)("inlineCode",{parentName:"p"},"task --summary release")," would print the following output:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"If a summary is missing, the description will be printed. If the task does not have a summary or a description, a warning is printed."),(0,l.kt)("p",null,"Please note: ",(0,l.kt)("em",{parentName:"p"},"showing the summary will not execute the command"),"."),(0,l.kt)("h2",{id:"task-\u522b\u540d"},"Task \u522b\u540d"),(0,l.kt)("p",null,"Aliases are alternative names for tasks. They can be used to make it easier and quicker to run tasks with long or hard-to-type names. You can use them on the command line, when ",(0,l.kt)("a",{parentName:"p",href:"#calling-another-task"},"calling sub-tasks")," in your Taskfile and when ",(0,l.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"including tasks")," with aliases from another Taskfile. They can also be used together with ",(0,l.kt)("a",{parentName:"p",href:"#namespace-aliases"},"namespace aliases"),"."),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"\u91cd\u5199-task-\u540d\u79f0"},"\u91cd\u5199 Task \u540d\u79f0"),(0,l.kt)("p",null,"Sometimes you may want to override the task name printed on the summary, up-to-date messages to STDOUT, etc. In this case, you can just set ",(0,l.kt)("inlineCode",{parentName:"p"},"label:"),", which can also be interpolated with variables:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"\u9759\u9ed8\u6a21\u5f0f"},"\u9759\u9ed8\u6a21\u5f0f"),(0,l.kt)("p",null,"Silent mode disables the echoing of commands before Task runs it. For the following Taskfile:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n")),(0,l.kt)("p",null,"Normally this will be printed:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-sh"},'echo "Print something"\nPrint something\n')),(0,l.kt)("p",null,"With silent mode on, the below will be printed instead:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-sh"},"Print something\n")),(0,l.kt)("p",null,"There are four ways to enable silent mode:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"At command level:")),(0,l.kt)("pre",null,(0,l.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,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"At task level:")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n silent: true\n")),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"Globally at Taskfile level:")),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\nsilent: true\n\ntasks:\n echo:\n cmds:\n - echo \"Print something\"\n")),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"Or globally with ",(0,l.kt)("inlineCode",{parentName:"li"},"--silent")," or ",(0,l.kt)("inlineCode",{parentName:"li"},"-s")," flag")),(0,l.kt)("p",null,"If you want to suppress STDOUT instead, just redirect a command to ",(0,l.kt)("inlineCode",{parentName:"p"},"/dev/null"),":"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"\u8bd5\u8fd0\u884c\u6a21\u5f0f"},"\u8bd5\u8fd0\u884c\u6a21\u5f0f"),(0,l.kt)("p",null,"Dry run mode (",(0,l.kt)("inlineCode",{parentName:"p"},"--dry"),") compiles and steps through each task, printing the commands that would be run without executing them. This is useful for debugging your Taskfiles."),(0,l.kt)("h2",{id:"\u5ffd\u7565\u9519\u8bef"},"\u5ffd\u7565\u9519\u8bef"),(0,l.kt)("p",null,"You have the option to ignore errors during command execution. Given the following Taskfile:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\ntasks:\n echo:\n cmds:\n - exit 1\n - echo \"Hello World\"\n")),(0,l.kt)("p",null,"Task will abort the execution after running ",(0,l.kt)("inlineCode",{parentName:"p"},"exit 1")," because the status code ",(0,l.kt)("inlineCode",{parentName:"p"},"1")," stands for ",(0,l.kt)("inlineCode",{parentName:"p"},"EXIT_FAILURE"),". However, it is possible to continue with execution using ",(0,l.kt)("inlineCode",{parentName:"p"},"ignore_error"),":"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,(0,l.kt)("inlineCode",{parentName:"p"},"ignore_error")," can also be set for a task, which means errors will be suppressed for all commands. Nevertheless, keep in mind that this option will not propagate to other tasks called either by ",(0,l.kt)("inlineCode",{parentName:"p"},"deps")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"cmds"),"!"),(0,l.kt)("h2",{id:"\u8f93\u51fa\u8bed\u6cd5"},"\u8f93\u51fa\u8bed\u6cd5"),(0,l.kt)("p",null,"By default, Task just redirects the STDOUT and STDERR of the running commands to the shell in real-time. This is good for having live feedback for logging printed by commands, but the output can become messy if you have multiple commands running simultaneously and printing lots of stuff."),(0,l.kt)("p",null,"To make this more customizable, there are currently three different output options you can choose:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"interleaved")," (default)"),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"group")),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"prefixed"))),(0,l.kt)("p",null,"To choose another one, just set it to root in the Taskfile:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-yaml"},"version: '3'\n\noutput: 'group'\n\ntasks:\n # ...\n")),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"group")," output will print the entire output of a command once after it finishes, so you will not have live feedback for commands that take a long time to run."),(0,l.kt)("p",null,"When using the ",(0,l.kt)("inlineCode",{parentName:"p"},"group")," output, you can optionally provide a templated message to print at the start and end of the group. This can be useful for instructing CI systems to group all of the output for a given task, such as with ",(0,l.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,l.kt)("inlineCode",{parentName:"a"},"::group::")," command")," or ",(0,l.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,l.kt)("pre",null,(0,l.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,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"$ task default\n::group::default\nHello, World!\n::endgroup::\n")),(0,l.kt)("p",null,"When using the ",(0,l.kt)("inlineCode",{parentName:"p"},"group")," output, you may swallow the output of the executed command on standard output and standard error if it does not fail (zero exit code)."),(0,l.kt)("pre",null,(0,l.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,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"prefix")," output will prefix every line printed by a command with ",(0,l.kt)("inlineCode",{parentName:"p"},"[task-name]")," as the prefix, but you can customize the prefix for a command with the ",(0,l.kt)("inlineCode",{parentName:"p"},"prefix:")," attribute:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"$ task default\n[print-foo] foo\n[print-bar] bar\n[print-baz] baz\n")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"The ",(0,l.kt)("inlineCode",{parentName:"p"},"output")," option can also be specified by the ",(0,l.kt)("inlineCode",{parentName:"p"},"--output")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"-o")," flags.")),(0,l.kt)("h2",{id:"\u4ea4\u4e92\u5f0f-cli-\u5e94\u7528"},"\u4ea4\u4e92\u5f0f CLI \u5e94\u7528"),(0,l.kt)("p",null,"When running interactive CLI applications inside Task they can sometimes behave weirdly, especially when the ",(0,l.kt)("a",{parentName:"p",href:"#output-syntax"},"output mode")," is set to something other than ",(0,l.kt)("inlineCode",{parentName:"p"},"interleaved")," (the default), or when interactive apps are run in parallel with other tasks."),(0,l.kt)("p",null,"The ",(0,l.kt)("inlineCode",{parentName:"p"},"interactive: true")," tells Task this is an interactive application and Task will try to optimize for it:"),(0,l.kt)("pre",null,(0,l.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,l.kt)("p",null,"If you still have problems running an interactive app through Task, please open an issue about it."),(0,l.kt)("h2",{id:"\u77ed-task-\u8bed\u6cd5"},"\u77ed Task \u8bed\u6cd5"),(0,l.kt)("p",null,"Starting on Task v3, you can now write tasks with a shorter syntax if they have the default settings (e.g. no custom ",(0,l.kt)("inlineCode",{parentName:"p"},"env:"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"vars:"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"desc:"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"silent:")," , etc):"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h2",{id:"set-\u548c-shopt"},(0,l.kt)("inlineCode",{parentName:"h2"},"set")," \u548c ",(0,l.kt)("inlineCode",{parentName:"h2"},"shopt")),(0,l.kt)("p",null,"It's possible to specify options to the ",(0,l.kt)("a",{parentName:"p",href:"https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html"},(0,l.kt)("inlineCode",{parentName:"a"},"set"))," and ",(0,l.kt)("a",{parentName:"p",href:"https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html"},(0,l.kt)("inlineCode",{parentName:"a"},"shopt"))," builtins. This can be added at global, task or command level."),(0,l.kt)("pre",null,(0,l.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,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"Keep in mind that not all options are available in the ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/mvdan/sh"},"shell interpreter library")," that Task uses.")),(0,l.kt)("h2",{id:"\u89c2\u5bdf\u4efb\u52a1"},"\u89c2\u5bdf\u4efb\u52a1"),(0,l.kt)("p",null,"With the flags ",(0,l.kt)("inlineCode",{parentName:"p"},"--watch")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"-w")," task will watch for file changes and run the task again. This requires the ",(0,l.kt)("inlineCode",{parentName:"p"},"sources")," attribute to be given, so task knows which files to watch."),(0,l.kt)("p",null,"The default watch interval is 5 seconds, but it's possible to change it by either setting ",(0,l.kt)("inlineCode",{parentName:"p"},"interval: '500ms'")," in the root of the Taskfile passing it as an argument like ",(0,l.kt)("inlineCode",{parentName:"p"},"--interval=500ms"),"."))}k.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/zh-Hans/assets/js/01713e21.7d5231e5.js b/zh-Hans/assets/js/01713e21.7d5231e5.js deleted file mode 100644 index e60223a7..00000000 --- a/zh-Hans/assets/js/01713e21.7d5231e5.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktaskfile_dev=self.webpackChunktaskfile_dev||[]).push([[701],{3905:function(e,n,t){t.d(n,{Zo:function(){return d},kt:function(){return c}});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)}},k=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),k=i,c=u["".concat(r,".").concat(k)]||u[k]||m[k]||l;return t?a.createElement(c,s(s({ref:n},d),{},{components:t})):a.createElement(c,s({ref:n},d))}));function c(e,n){var t=arguments,i=n&&n.mdxType;if("string"==typeof e||i){var l=t.length,s=new Array(l);s[0]=k;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 \u505a task \u6e05\u7406",id:"\u4f7f\u7528-defer-\u505a-task-\u6e05\u7406",level:2},{value:"Go \u7684\u6a21\u677f\u5f15\u64ce",id:"go-\u7684\u6a21\u677f\u5f15\u64ce",level:2},{value:"\u5e2e\u52a9",id:"\u5e2e\u52a9",level:2},{value:"\u663e\u793a\u4efb\u52a1\u6458\u8981",id:"\u663e\u793a\u4efb\u52a1\u6458\u8981",level:2},{value:"Task \u522b\u540d",id:"task-\u522b\u540d",level:2},{value:"\u91cd\u5199 Task \u540d\u79f0",id:"\u91cd\u5199-task-\u540d\u79f0",level:2},{value:"\u9759\u9ed8\u6a21\u5f0f",id:"\u9759\u9ed8\u6a21\u5f0f",level:2},{value:"\u8bd5\u8fd0\u884c\u6a21\u5f0f",id:"\u8bd5\u8fd0\u884c\u6a21\u5f0f",level:2},{value:"\u5ffd\u7565\u9519\u8bef",id:"\u5ffd\u7565\u9519\u8bef",level:2},{value:"\u8f93\u51fa\u8bed\u6cd5",id:"\u8f93\u51fa\u8bed\u6cd5",level:2},{value:"\u4ea4\u4e92\u5f0f CLI \u5e94\u7528",id:"\u4ea4\u4e92\u5f0f-cli-\u5e94\u7528",level:2},{value:"\u77ed Task \u8bed\u6cd5",id:"\u77ed-task-\u8bed\u6cd5",level:2},{value:"set \u548c shopt",id:"set-\u548c-shopt",level:2},{value:"\u89c2\u5bdf\u4efb\u52a1",id:"\u89c2\u5bdf\u4efb\u52a1",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:"\u4f7f\u7528\u6307\u5357"},"\u4f7f\u7528\u6307\u5357"),(0,i.kt)("h2",{id:"\u5feb\u901f\u5165\u95e8"},"\u5feb\u901f\u5165\u95e8"),(0,i.kt)("p",null,"\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml")," \u7684\u6587\u4ef6\u3002 ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds")," \u5c5e\u6027\u5e94\u5305\u542b task \u7684\u547d\u4ee4\u3002 \u4e0b\u9762\u7684\u793a\u4f8b\u5141\u8bb8\u7f16\u8bd1 Go \u5e94\u7528\u7a0b\u5e8f\u5e76\u4f7f\u7528 ",(0,i.kt)("a",{parentName:"p",href:"https://esbuild.github.io/"},"esbuild")," \u5c06\u591a\u4e2a CSS \u6587\u4ef6\u5408\u5e76\u5e76\u7f29\u5c0f\u4e3a\u4e00\u4e2a\u6587\u4ef6\u3002"),(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,"\u8fd0\u884c\u4efb\u52a1\u5c31\u8fd9\u6837\u7b80\u5355\uff1a"),(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 interpreter. So you can write sh/bash commands, and it will work even on Windows, where ",(0,i.kt)("inlineCode",{parentName:"p"},"sh")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"bash")," are usually not available. Just remember any executable 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:"\u652f\u6301\u7684\u6587\u4ef6\u540d\u79f0"},"\u652f\u6301\u7684\u6587\u4ef6\u540d\u79f0"),(0,i.kt)("p",null,"Task \u4f1a\u6309\u4ee5\u4e0b\u987a\u5e8f\u67e5\u627e\u914d\u7f6e\u6587\u4ef6:"),(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 committed version (",(0,i.kt)("inlineCode",{parentName:"p"},".dist"),") while still allowing individual users to override the Taskfile by adding an additional ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile.yml")," (which would be on ",(0,i.kt)("inlineCode",{parentName:"p"},".gitignore"),")."),(0,i.kt)("h3",{id:"\u4ece\u5b50\u76ee\u5f55\u8fd0\u884c-taskfile"},"\u4ece\u5b50\u76ee\u5f55\u8fd0\u884c Taskfile"),(0,i.kt)("p",null,"If a Taskfile cannot be found in the current working directory, it will walk up the file tree until it finds one (similar to how ",(0,i.kt)("inlineCode",{parentName:"p"},"git")," works). When running Task from a subdirectory like this, it will behave as if you ran it from the directory 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}}")," variable to create some very useful reusable tasks. For example, if you have a monorepo with directories for each microservice, you can ",(0,i.kt)("inlineCode",{parentName:"p"},"cd")," into a microservice directory and run a task command to bring it up without having to create 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 ",(0,i.kt)("inlineCode",{parentName:"p"},"")," directory contains a ",(0,i.kt)("inlineCode",{parentName:"p"},"docker-compose.yml"),", the Docker composition will be brought up."),(0,i.kt)("h3",{id:"\u8fd0\u884c\u5168\u5c40-taskfile"},"\u8fd0\u884c\u5168\u5c40 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 home directory instead of your working directory. In short, Task will look for a 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 system!"),(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 default, 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 variable can be very handy here to run stuff on the directory you're calling ",(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:"\u73af\u5883\u53d8\u91cf"},"\u73af\u5883\u53d8\u91cf"),(0,i.kt)("h3",{id:"task"},"Task"),(0,i.kt)("p",null,"\u4f60\u53ef\u4ee5\u4f7f\u7528 ",(0,i.kt)("inlineCode",{parentName:"p"},"env")," \u7ed9\u6bcf\u4e2a task \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u73af\u5883\u53d8\u91cf:"),(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 to 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 just like variables, as you can see in the ",(0,i.kt)("a",{parentName:"p",href:"#variables"},"Variables")," section.")),(0,i.kt)("h3",{id:"env-\u6587\u4ef6"},".env \u6587\u4ef6"),(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:")," setting:"),(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,"\u4e5f\u53ef\u4ee5\u5728\u4efb\u52a1\u7ea7\u6307\u5b9a .env \u6587\u4ef6\uff1a"),(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 variables 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"},"\u8bf7\u6ce8\u610f\uff0c\u60a8\u76ee\u524d\u65e0\u6cd5\u5728\u5305\u542b\u7684 Taskfile \u4e2d\u4f7f\u7528 ",(0,i.kt)("inlineCode",{parentName:"p"},"dotenv")," \u952e\u3002")),(0,i.kt)("h2",{id:"\u5305\u542b\u5176\u4ed6-taskfile"},"\u5305\u542b\u5176\u4ed6 Taskfile"),(0,i.kt)("p",null,"If you want to share tasks between different projects (Taskfiles), you can use the 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 namespace. 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 ",(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 from 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:"\u64cd\u4f5c\u7cfb\u7edf\u7279\u5b9a-taskfile"},"\u64cd\u4f5c\u7cfb\u7edf\u7279\u5b9a Taskfile"),(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")," if it exists (for example: ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_windows.yml"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_linux.yml")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"Taskfile_darwin.yml"),"). Since this behavior was a bit too implicit, it was removed on version 3, but you still can have a similar behavior by explicitly 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:"\u5305\u542b-taskfile-\u7684\u76ee\u5f55"},"\u5305\u542b Taskfile \u7684\u76ee\u5f55"),(0,i.kt)("p",null,"By default, included Taskfile's tasks are run in the current directory, even if the Taskfile is in another directory, but you can force its tasks to run in 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 Taskfile uses.")),(0,i.kt)("h3",{id:"\u53ef\u9009-includes"},"\u53ef\u9009 includes"),(0,i.kt)("p",null,"Includes marked as optional will allow Task to continue execution as normal if the 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:"\u5185\u90e8-includes"},"\u5185\u90e8 includes"),(0,i.kt)("p",null,"Includes marked as internal will set all the tasks of the included file to be internal as well (see the ",(0,i.kt)("a",{parentName:"p",href:"#internal-tasks"},"Internal tasks")," section below). This is useful when including utility tasks that are not intended to be used directly 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:"\u5305\u542b\u7684-taskfile-\u7684\u53d8\u91cf"},"\u5305\u542b\u7684 Taskfile \u7684\u53d8\u91cf"),(0,i.kt)("p",null,"You can also specify variables when including a Taskfile. This may be useful for 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:"\u547d\u540d\u7a7a\u95f4\u522b\u540d"},"\u547d\u540d\u7a7a\u95f4\u522b\u540d"),(0,i.kt)("p",null,"When including a Taskfile, you can give the namespace a list of ",(0,i.kt)("inlineCode",{parentName:"p"},"aliases"),". This works in the same way as ",(0,i.kt)("a",{parentName:"p",href:"#task-aliases"},"task aliases")," and can be used together 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 variables in the including Taskfile! If you want a variable in an included Taskfile to be overridable, use the ",(0,i.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/defaults.html"},"default function"),": ",(0,i.kt)("inlineCode",{parentName:"p"},"MY_VAR: '{{.MY_VAR | default \"my-default-value\"}}'"),".")),(0,i.kt)("h2",{id:"\u5185\u90e8-tasks"},"\u5185\u90e8 tasks"),(0,i.kt)("p",null,"Internal tasks are tasks that cannot be called directly by the user. They will not appear in the output when running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --list|--list-all"),". Other tasks may call internal tasks in the usual way. This is useful for creating reusable, function-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-\u76ee\u5f55"},"Task \u76ee\u5f55"),(0,i.kt)("p",null,"By default, tasks will be executed in the directory where the Taskfile is located. But you can easily make the task run in another folder, informing ",(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-\u4f9d\u8d56"},"Task \u4f9d\u8d56"),(0,i.kt)("blockquote",null,(0,i.kt)("p",{parentName:"blockquote"},"Dependencies run in parallel, so dependencies of a task should not depend one another. If you want to force tasks to run serially, take a look at the ",(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 make 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 ",(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 performance."),(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 using 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 manner 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:"\u5e73\u53f0\u7279\u5b9a\u7684-tasks-\u548c-cmds"},"\u5e73\u53f0\u7279\u5b9a\u7684 tasks \u548c cmds"),(0,i.kt)("p",null,"If you want to restrict the running of tasks to explicit platforms, this can be achieved using the ",(0,i.kt)("inlineCode",{parentName:"p"},"platforms:")," key. Tasks can be restricted to a specific OS, architecture or a combination of both. On 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 defined by the Go language ",(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:"\u8c03\u7528\u53e6\u4e00\u4e2a-task"},"\u8c03\u7528\u53e6\u4e00\u4e2a task"),(0,i.kt)("p",null,"When a task has many dependencies, they are executed concurrently. This will often result in a faster build pipeline. However, in some situations, you may need to 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")," attribute:"),(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 ",(0,i.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"included Taskfile"),", add a leading ",(0,i.kt)("inlineCode",{parentName:"p"},":")," like this: ",(0,i.kt)("inlineCode",{parentName:"p"},"task: :task-name"),".")),(0,i.kt)("h2",{id:"\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5de5\u4f5c"},"\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5de5\u4f5c"),(0,i.kt)("h3",{id:"\u901a\u8fc7\u6307\u7eb9\u8bc6\u522b\u672c\u5730\u751f\u6210\u7684\u6587\u4ef6\u53ca\u5176\u6765\u6e90"},"\u901a\u8fc7\u6307\u7eb9\u8bc6\u522b\u672c\u5730\u751f\u6210\u7684\u6587\u4ef6\u53ca\u5176\u6765\u6e90"),(0,i.kt)("p",null,"If a task generates something, you can inform Task the source and generated files, 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, Task will compare the checksum of the source files to determine if it's necessary to run the task. If not, it will just print a message like ",(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, instead 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. You can even combine the two. See the documentation for ",(0,i.kt)("a",{parentName:"p",href:"#using-programmatic-checks-to-indicate-a-task-is-up-to-date"},"status")," for an example."),(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 directory. Most of the time, you'll want to have this directory on ",(0,i.kt)("inlineCode",{parentName:"p"},".gitignore")," (or equivalent) so it isn't committed. (If you have a task for code generation that is committed it may make sense to commit the checksum of that task as well, though)."),(0,i.kt)("p",{parentName:"admonition"},"If you want these files to be stored in another directory, you can set a ",(0,i.kt)("inlineCode",{parentName:"p"},"TASK_TEMP_DIR")," environment variable in your machine. It can contain a relative path like ",(0,i.kt)("inlineCode",{parentName:"p"},"tmp/task")," that will be interpreted as relative to the project directory, or an absolute or home path like ",(0,i.kt)("inlineCode",{parentName:"p"},"/tmp/.task")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"~/.task")," (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 to distinguish a task by any of its input variables, you can add those variables as part of the task's label, and it will be considered a different task."),(0,i.kt)("p",{parentName:"admonition"},"This is useful if you want to run a task once for each distinct set of inputs until the sources actually change. For example, if the sources depend on the value of a variable, or you if you want the task to rerun if some arguments change 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 inform the source files. When 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:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u6765\u8868\u793a\u4efb\u52a1\u662f\u6700\u65b0\u7684"},"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u6765\u8868\u793a\u4efb\u52a1\u662f\u6700\u65b0\u7684\u3002"),(0,i.kt)("p",null,"Alternatively, you can inform a sequence of tests as ",(0,i.kt)("inlineCode",{parentName:"p"},"status"),". If no error is 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 ",(0,i.kt)("inlineCode",{parentName:"p"},"generates")," - but for tasks that generate remote artifacts (Docker images, deploys, CD releases) the checksum source and timestamps require either access to the artifact or for an out-of-band refresh of the ",(0,i.kt)("inlineCode",{parentName:"p"},".checksum")," fingerprint 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 for interpolation within ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," commands, depending on the method assigned to 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 can 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 up-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 the 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")," to have a task run if either the the source/generated artifacts changes, or the programmatic 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:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u53d6\u6d88\u4efb\u52a1\u53ca\u5176\u4f9d\u8d56\u9879\u7684\u6267\u884c"},"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u53d6\u6d88\u4efb\u52a1\u53ca\u5176\u4f9d\u8d56\u9879\u7684\u6267\u884c"),(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 the logical inverse of ",(0,i.kt)("inlineCode",{parentName:"p"},"status")," checks. That is, if you need a certain set of conditions to be ",(0,i.kt)("em",{parentName:"p"},"true")," you can use the ",(0,i.kt)("inlineCode",{parentName:"p"},"preconditions")," stanza. ",(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")," expansion, 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 a 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 precondition is not met - the calling task will fail. Note that a task executed with a failing precondition will not run unless ",(0,i.kt)("inlineCode",{parentName:"p"},"--force")," is given."),(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 executing tasks that depend on it, a ",(0,i.kt)("inlineCode",{parentName:"p"},"precondition")," will fail a task, along with 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:"\u5728\u4efb\u52a1\u8fd0\u884c\u65f6\u9650\u5236"},"\u5728\u4efb\u52a1\u8fd0\u884c\u65f6\u9650\u5236"),(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 when 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 of the Taskfile to change the behavior of all the tasks unless explicitly overridden."),(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 number 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 passed 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:"\u53d8\u91cf"},"\u53d8\u91cf"),(0,i.kt)("p",null,"When doing interpolation of variables, Task will look for the below. They 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 (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 (Windows) tasks also accept a similar style when not at the beginning of the 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:"\u52a8\u6001\u53d8\u91cf"},"\u52a8\u6001\u53d8\u91cf"),(0,i.kt)("p",null,"The below syntax (",(0,i.kt)("inlineCode",{parentName:"p"},"sh:")," prop in a variable) is considered a dynamic variable. The value will be treated as a command and the output assigned. If there are one or 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:"\u5c06-cli-\u53c2\u6570\u8f6c\u53d1\u5230-cmds"},"\u5c06 CLI \u53c2\u6570\u8f6c\u53d1\u5230 cmds"),(0,i.kt)("p",null,"If ",(0,i.kt)("inlineCode",{parentName:"p"},"--")," is given in the CLI, all following parameters are added to a special ",(0,i.kt)("inlineCode",{parentName:"p"},".CLI_ARGS")," variable. This is useful to forward arguments to another command."),(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:"\u4f7f\u7528-defer-\u505a-task-\u6e05\u7406"},"\u4f7f\u7528 ",(0,i.kt)("inlineCode",{parentName:"h2"},"defer")," \u505a task \u6e05\u7406"),(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 the task finishes. The difference with just putting it as the last command is that 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 well:"),(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 ",(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 commands are executed in the reverse order if you schedule multiple of them.")),(0,i.kt)("h2",{id:"go-\u7684\u6a21\u677f\u5f15\u64ce"},"Go \u7684\u6a21\u677f\u5f15\u64ce"),(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 them. 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")," are 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", "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" or "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"},"\\")," path 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 converts 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 (",(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. Task uses ",(0,i.kt)("a",{parentName:"li",href:"https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/syntax#Quote"},"this Go function")," for 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. Task 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:"\u5e2e\u52a9"},"\u5e2e\u52a9"),(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. The 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:"\u663e\u793a\u4efb\u52a1\u6458\u8981"},"\u663e\u793a\u4efb\u52a1\u6458\u8981"),(0,i.kt)("p",null,"Running ",(0,i.kt)("inlineCode",{parentName:"p"},"task --summary task-name")," will show a summary of a task. The 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. If 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-\u522b\u540d"},"Task \u522b\u540d"),(0,i.kt)("p",null,"Aliases are alternative names for tasks. They can be used to make it easier and quicker to run tasks with long or hard-to-type names. You can use them on the command line, when ",(0,i.kt)("a",{parentName:"p",href:"#calling-another-task"},"calling sub-tasks")," in your Taskfile and when ",(0,i.kt)("a",{parentName:"p",href:"#including-other-taskfiles"},"including tasks")," with aliases from another Taskfile. They can also be used together with ",(0,i.kt)("a",{parentName:"p",href:"#namespace-aliases"},"namespace aliases"),"."),(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:"\u91cd\u5199-task-\u540d\u79f0"},"\u91cd\u5199 Task \u540d\u79f0"),(0,i.kt)("p",null,"Sometimes you may want to override the task name printed on the summary, up-to-date messages to STDOUT, etc. In this case, you can just set ",(0,i.kt)("inlineCode",{parentName:"p"},"label:"),", which can also be 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:"\u9759\u9ed8\u6a21\u5f0f"},"\u9759\u9ed8\u6a21\u5f0f"),(0,i.kt)("p",null,"Silent mode disables the echoing of commands before Task runs it. For 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:"\u8bd5\u8fd0\u884c\u6a21\u5f0f"},"\u8bd5\u8fd0\u884c\u6a21\u5f0f"),(0,i.kt)("p",null,"Dry run mode (",(0,i.kt)("inlineCode",{parentName:"p"},"--dry"),") compiles and steps through each task, printing the commands that would be run without executing them. This is useful for debugging your Taskfiles."),(0,i.kt)("h2",{id:"\u5ffd\u7565\u9519\u8bef"},"\u5ffd\u7565\u9519\u8bef"),(0,i.kt)("p",null,"You have the option to ignore errors during command execution. Given 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"),". However, 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 for all commands. Nevertheless, keep in mind that this option will not propagate to other tasks called either by ",(0,i.kt)("inlineCode",{parentName:"p"},"deps")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"cmds"),"!"),(0,i.kt)("h2",{id:"\u8f93\u51fa\u8bed\u6cd5"},"\u8f93\u51fa\u8bed\u6cd5"),(0,i.kt)("p",null,"By default, Task just redirects the STDOUT and STDERR of the running commands to the shell in real-time. This is good for having live feedback for logging printed by commands, but the output can become messy if you have multiple commands running simultaneously and printing lots of stuff."),(0,i.kt)("p",null,"To make this more customizable, there are currently three different output options 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 finishes, so you will not have live feedback for commands that take a long time to run."),(0,i.kt)("p",null,"When using the ",(0,i.kt)("inlineCode",{parentName:"p"},"group")," output, you can optionally provide a templated message to print at the start and end of the group. This can be useful for instructing CI systems to group all of the output for a given task, such as with ",(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")," or ",(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 on 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 ",(0,i.kt)("inlineCode",{parentName:"p"},"[task-name]")," as the prefix, but you can customize the prefix for a command with 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:"\u4ea4\u4e92\u5f0f-cli-\u5e94\u7528"},"\u4ea4\u4e92\u5f0f CLI \u5e94\u7528"),(0,i.kt)("p",null,"When running interactive CLI applications inside Task they can sometimes behave weirdly, especially when the ",(0,i.kt)("a",{parentName:"p",href:"#output-syntax"},"output mode")," is set to something other than ",(0,i.kt)("inlineCode",{parentName:"p"},"interleaved")," (the default), or when interactive apps are run in parallel 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 will 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 an issue about it."),(0,i.kt)("h2",{id:"\u77ed-task-\u8bed\u6cd5"},"\u77ed Task \u8bed\u6cd5"),(0,i.kt)("p",null,"Starting on Task v3, you can now write tasks with a shorter syntax if they have 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-\u548c-shopt"},(0,i.kt)("inlineCode",{parentName:"h2"},"set")," \u548c ",(0,i.kt)("inlineCode",{parentName:"h2"},"shopt")),(0,i.kt)("p",null,"It's possible to specify options to the ",(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"))," and ",(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"))," builtins. 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 ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/mvdan/sh"},"shell interpreter library")," that Task uses.")),(0,i.kt)("h2",{id:"\u89c2\u5bdf\u4efb\u52a1"},"\u89c2\u5bdf\u4efb\u52a1"),(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 and run the task again. This requires the ",(0,i.kt)("inlineCode",{parentName:"p"},"sources")," attribute to be given, so 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 either setting ",(0,i.kt)("inlineCode",{parentName:"p"},"interval: '500ms'")," in the root of the Taskfile passing it as an argument like ",(0,i.kt)("inlineCode",{parentName:"p"},"--interval=500ms"),"."))}u.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/zh-Hans/assets/js/5b2a233e.7942fbc5.js b/zh-Hans/assets/js/5b2a233e.7942fbc5.js deleted file mode 100644 index a9bb3a7b..00000000 --- a/zh-Hans/assets/js/5b2a233e.7942fbc5.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunktaskfile_dev=self.webpackChunktaskfile_dev||[]).push([[863],{3905:function(M,N,D){D.d(N,{Zo:function(){return O},kt:function(){return x}});var j=D(7294);function T(M,N,D){return N in M?Object.defineProperty(M,N,{value:D,enumerable:!0,configurable:!0,writable:!0}):M[N]=D,M}function z(M,N){var D=Object.keys(M);if(Object.getOwnPropertySymbols){var j=Object.getOwnPropertySymbols(M);N&&(j=j.filter((function(N){return Object.getOwnPropertyDescriptor(M,N).enumerable}))),D.push.apply(D,j)}return D}function I(M){for(var N=1;N=0||(T[D]=M[D]);return T}(M,N);if(Object.getOwnPropertySymbols){var z=Object.getOwnPropertySymbols(M);for(j=0;j=0||Object.prototype.propertyIsEnumerable.call(M,D)&&(T[D]=M[D])}return T}var u=j.createContext({}),A=function(M){var N=j.useContext(u),D=N;return M&&(D="function"==typeof M?M(N):I(I({},N),M)),D},O=function(M){var N=A(M.components);return j.createElement(u.Provider,{value:N},M.children)},y="mdxType",E={inlineCode:"code",wrapper:function(M){var N=M.children;return j.createElement(j.Fragment,{},N)}},e=j.forwardRef((function(M,N){var D=M.components,T=M.mdxType,z=M.originalType,u=M.parentName,O=g(M,["components","mdxType","originalType","parentName"]),y=A(D),e=T,x=y["".concat(u,".").concat(e)]||y[e]||E[e]||z;return D?j.createElement(x,I(I({ref:N},O),{},{components:D})):j.createElement(x,I({ref:N},O))}));function x(M,N){var D=arguments,T=N&&N.mdxType;if("string"==typeof M||T){var z=D.length,I=new Array(z);I[0]=e;var g={};for(var u in N)hasOwnProperty.call(N,u)&&(g[u]=N[u]);g.originalType=M,g[y]="string"==typeof M?M:T,I[1]=g;for(var A=2;A=0||(T[D]=M[D]);return T}(M,N);if(Object.getOwnPropertySymbols){var z=Object.getOwnPropertySymbols(M);for(j=0;j=0||Object.prototype.propertyIsEnumerable.call(M,D)&&(T[D]=M[D])}return T}var u=j.createContext({}),A=function(M){var N=j.useContext(u),D=N;return M&&(D="function"==typeof M?M(N):I(I({},N),M)),D},E=function(M){var N=A(M.components);return j.createElement(u.Provider,{value:N},M.children)},O="mdxType",y={inlineCode:"code",wrapper:function(M){var N=M.children;return j.createElement(j.Fragment,{},N)}},e=j.forwardRef((function(M,N){var D=M.components,T=M.mdxType,z=M.originalType,u=M.parentName,E=g(M,["components","mdxType","originalType","parentName"]),O=A(D),e=T,t=O["".concat(u,".").concat(e)]||O[e]||y[e]||z;return D?j.createElement(t,I(I({ref:N},E),{},{components:D})):j.createElement(t,I({ref:N},E))}));function t(M,N){var D=arguments,T=N&&N.mdxType;if("string"==typeof M||T){var z=D.length,I=new Array(z);I[0]=e;var g={};for(var u in N)hasOwnProperty.call(N,u)&&(g[u]=N[u]);g.originalType=M,g[O]="string"==typeof M?M:T,I[1]=g;for(var A=2;A=0||(l[a]=t[a]);return l}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(t,a)&&(l[a]=t[a])}return l}var o=i.createContext({}),p=function(t){var e=i.useContext(o),a=e;return t&&(a="function"==typeof t?t(e):s(s({},e),t)),a},k=function(t){var e=p(t.components);return i.createElement(o.Provider,{value:e},t.children)},m="mdxType",u={inlineCode:"code",wrapper:function(t){var e=t.children;return i.createElement(i.Fragment,{},e)}},h=i.forwardRef((function(t,e){var a=t.components,l=t.mdxType,n=t.originalType,o=t.parentName,k=r(t,["components","mdxType","originalType","parentName"]),m=p(a),h=l,d=m["".concat(o,".").concat(h)]||m[h]||u[h]||n;return a?i.createElement(d,s(s({ref:e},k),{},{components:a})):i.createElement(d,s({ref:e},k))}));function d(t,e){var a=arguments,l=e&&e.mdxType;if("string"==typeof t||l){var n=a.length,s=new Array(n);s[0]=h;var r={};for(var o in e)hasOwnProperty.call(e,o)&&(r[o]=e[o]);r.originalType=t,r[m]="string"==typeof t?t:l,s[1]=r;for(var p=2;p=0||(s[a]=t[a]);return s}(t,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(t,a)&&(s[a]=t[a])}return s}var o=i.createContext({}),k=function(t){var e=i.useContext(o),a=e;return t&&(a="function"==typeof t?t(e):l(l({},e),t)),a},h=function(t){var e=k(t.components);return i.createElement(o.Provider,{value:e},t.children)},m="mdxType",p={inlineCode:"code",wrapper:function(t){var e=t.children;return i.createElement(i.Fragment,{},e)}},u=i.forwardRef((function(t,e){var a=t.components,s=t.mdxType,n=t.originalType,o=t.parentName,h=r(t,["components","mdxType","originalType","parentName"]),m=k(a),u=s,d=m["".concat(o,".").concat(u)]||m[u]||p[u]||n;return a?i.createElement(d,l(l({ref:e},h),{},{components:a})):i.createElement(d,l({ref:e},h))}));function d(t,e){var a=arguments,s=e&&e.mdxType;if("string"==typeof t||s){var n=a.length,l=new Array(n);l[0]=u;var r={};for(var o in e)hasOwnProperty.call(e,o)&&(r[o]=e[o]);r.originalType=t,r[m]="string"==typeof t?t:s,l[1]=r;for(var k=2;k=o)&&Object.keys(u.O).every((function(e){return u.O[e](n[i])}))?n.splice(i--,1):(a=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[n,r,o]},u.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(t,{a:t}),t},n=Object.getPrototypeOf?function(e){return Object.getPrototypeOf(e)}:function(e){return e.__proto__},u.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);u.r(o);var f={};t=t||[null,n({}),n([]),n(n)];for(var a=2&r&&e;"object"==typeof a&&!~t.indexOf(a);a=n(a))Object.getOwnPropertyNames(a).forEach((function(t){f[t]=function(){return e[t]}}));return f.default=function(){return e},u.d(o,f),o},u.d=function(e,t){for(var n in t)u.o(t,n)&&!u.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},u.f={},u.e=function(e){return Promise.all(Object.keys(u.f).reduce((function(t,n){return u.f[n](e,t),t}),[]))},u.u=function(e){return"assets/js/"+({2:"4fc1c6af",31:"51de5da2",38:"14b2bd35",53:"935f2afb",97:"835b845c",133:"f1d66b0d",188:"dd4fb81f",425:"87f30f6b",514:"1be78505",595:"d0766b26",597:"8152bf4e",634:"1fd60438",701:"01713e21",825:"0f29a59d",863:"5b2a233e",868:"8faba80b",889:"49514f56",918:"17896441",920:"1a4e3797"}[e]||e)+"."+{2:"6c073004",31:"ae755056",38:"0e400898",53:"069a353d",97:"8b44cfc3",133:"6862b446",188:"c0f13317",425:"11888b5d",514:"9062895a",595:"c5627647",597:"24dd0f67",634:"5f0b27aa",701:"7d5231e5",780:"b979b06f",825:"74edccf0",863:"7942fbc5",868:"eb9006a5",889:"75ba2656",894:"4bf7d380",918:"e75765f6",920:"a9132d06",945:"3694633c",972:"01a5a892"}[e]+".js"},u.miniCssF=function(e){},u.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),u.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r={},o="taskfile-dev:",u.l=function(e,t,n,f){if(r[e])r[e].push(t);else{var a,i;if(void 0!==n)for(var c=document.getElementsByTagName("script"),d=0;d=o)&&Object.keys(u.O).every((function(e){return u.O[e](n[i])}))?n.splice(i--,1):(a=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[n,r,o]},u.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(t,{a:t}),t},n=Object.getPrototypeOf?function(e){return Object.getPrototypeOf(e)}:function(e){return e.__proto__},u.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);u.r(o);var f={};t=t||[null,n({}),n([]),n(n)];for(var a=2&r&&e;"object"==typeof a&&!~t.indexOf(a);a=n(a))Object.getOwnPropertyNames(a).forEach((function(t){f[t]=function(){return e[t]}}));return f.default=function(){return e},u.d(o,f),o},u.d=function(e,t){for(var n in t)u.o(t,n)&&!u.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},u.f={},u.e=function(e){return Promise.all(Object.keys(u.f).reduce((function(t,n){return u.f[n](e,t),t}),[]))},u.u=function(e){return"assets/js/"+({2:"4fc1c6af",31:"51de5da2",38:"14b2bd35",53:"935f2afb",97:"835b845c",133:"f1d66b0d",188:"dd4fb81f",425:"87f30f6b",514:"1be78505",595:"d0766b26",597:"8152bf4e",634:"1fd60438",701:"01713e21",825:"0f29a59d",863:"5b2a233e",868:"8faba80b",889:"49514f56",918:"17896441",920:"1a4e3797"}[e]||e)+"."+{2:"6c073004",31:"ae755056",38:"0e400898",53:"6c08fc98",97:"8b44cfc3",133:"6862b446",188:"c0f13317",425:"4227404d",514:"9062895a",595:"c5627647",597:"24dd0f67",634:"5f0b27aa",701:"3f827c94",780:"b979b06f",825:"74edccf0",863:"d9ce1ba9",868:"eb9006a5",889:"75ba2656",894:"4bf7d380",918:"e75765f6",920:"a9132d06",945:"3694633c",972:"01a5a892"}[e]+".js"},u.miniCssF=function(e){},u.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),u.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r={},o="taskfile-dev:",u.l=function(e,t,n,f){if(r[e])r[e].push(t);else{var a,i;if(void 0!==n)for(var c=document.getElementsByTagName("script"),d=0;d -更新日志 | Task +更新日志 | Task - +
-

更新日志

v3.22.0 - 2023-03-10

  • Add a brand new --global (-g) flag that will run a Taskfile from your $HOME directory. This is useful to have automation that you can run from anywhere in your system! (Documentation, #1029 by @andreynering).
  • Add ability to set error_only: true on the group output mode. This will instruct Task to only print a command output if it returned with a non-zero exit code (#664, #1022 by @jaedle).
  • Fixed bug where .task/checksum file was sometimes not being created when task also declares a status: (#840, #1035 by @harelwa, #1037 by @pd93).
  • Refactored and decoupled fingerprinting from the main Task executor (#1039 by @pd93).
  • Fixed deadlock issue when using run: once (#715, #1025 by @theunrepentantgeek).

v3.21.0 - 2023-02-22

  • Added new TASK_VERSION special variable (#990, #1014 by @ja1code).
  • Fixed a bug where tasks were sometimes incorrectly marked as internal (#1007 by @pd93).
  • Update to Go 1.20 (bump minimum version to 1.19) (#1010 by @pd93)
  • Added environment variable FORCE_COLOR support to force color output. Usefull for environments without TTY (#1003 by @automation-stack)

v3.20.0 - 2023-01-14

  • Improve behavior and performance of status checking when using the timestamp mode (#976, #977 by @aminya).
  • Performance optimizations were made for large Taskfiles (#982 by @pd93).
  • Add ability to configure options for the set and shopt builtins (#908, #929 by @pd93, Documentation).
  • Add new platforms: attribute to task and cmd, so it's now possible to choose in which platforms that given task or command will be run on. Possible values are operating system (GOOS), architecture (GOARCH) or a combination of the two. Example: platforms: [linux], platforms: [amd64] or platforms: [linux/amd64]. Other platforms will be skipped (#978, #980 by @leaanthony).

v3.19.1 - 2022-12-31

  • Small bug fix: closing Taskfile.yml once we're done reading it (#963, #964 by @HeCorr).
  • Fixes a bug in v2 that caused a panic when using a Taskfile_{{OS}}.yml file (#961, #971 by @pd93).
  • Fixed a bug where watch intervals set in the Taskfile were not being respected (#969, #970 by @pd93)
  • Add --json flag (alias -j) with the intent to improve support for code editors and add room to other possible integrations. This is basic for now, but we plan to add more info in the near future (#936 by @davidalpert, #764).

v3.19.0 - 2022-12-05

v3.18.0 - 2022-11-12

  • Show aliases on task --list --silent (task --ls). This means that aliases will be completed by the completion scripts (#919).
  • Tasks in the root Taskfile will now be displayed first in --list/--list-all output (#806, #890).
  • It's now possible to call a default task in an included Taskfile by using just the namespace. For example: docs:default is now automatically aliased to docs (#661, #815).

v3.17.0 - 2022-10-14

  • Add a "Did you mean ...?" suggestion when a task does not exits another one with a similar name is found (#867, #880).
  • Now YAML parse errors will print which Taskfile failed to parse (#885, #887).
  • Add ability to set aliases for tasks and namespaces (#268, #340, #879).
  • Improvements to Fish shell completion (#897).
  • Added ability to set a different watch interval by setting interval: '500ms' or using the --interval=500ms flag (#813, #865).
  • Add colored output to --list, --list-all and --summary flags (#845, #874).
  • Fix unexpected behavior where label: was being shown instead of the task name on --list (#603, #877).

v3.16.0 - 2022-09-29

  • Add npm as new installation method: npm i -g @go-task/cli (#870, #871, npm package).
  • Add support to marking tasks and includes as internal, which will hide them from --list and --list-all (#818).

v3.15.2 - 2022-09-08

  • Fix error when using variable in env: introduced in the previous release (#858, #866).
  • Fix handling of CLI_ARGS (--) in Bash completion (#863).
  • On zsh completion, add ability to replace --list-all with --list as already possible on the Bash completion (#861).

v3.15.0 - 2022-09-03

  • Add new special variables ROOT_DIR and TASKFILE_DIR. This was a highly requested feature (#215, #857, Documentation).
  • Follow symlinks on sources (#826, #831).
  • Improvements and fixes to Bash completion (#835, #844).

v3.14.1 - 2022-08-03

  • Always resolve relative include paths relative to the including Taskfile (#822, #823).
  • Fix ZSH and PowerShell completions to consider all tasks instead of just the public ones (those with descriptions) (#803).

v3.14.0 - 2022-07-08

  • Add ability to override the .task directory location with the TASK_TEMP_DIR environment variable.
  • Allow to override Task colors using environment variables: TASK_COLOR_RESET, TASK_COLOR_BLUE, TASK_COLOR_GREEN, TASK_COLOR_CYAN, TASK_COLOR_YELLOW, TASK_COLOR_MAGENTA and TASK_COLOR_RED (#568, #792).
  • Fixed bug when using the output: group mode where STDOUT and STDERR were being print in separated blocks instead of in the right order (#779).
  • Starting on this release, ARM architecture binaries are been released to Snap as well (#795).
  • i386 binaries won't be available anymore on Snap because Ubuntu removed the support for this architecture.
  • Upgrade mvdan.cc/sh, which fixes a bug with associative arrays (#785, mvdan/sh#884, mvdan/sh#893).

v3.13.0 - 2022-06-13

  • Added -n as an alias to --dry (#776, #777).
  • Fix behavior of interrupt (SIGINT, SIGTERM) signals. Task will now give time for the processes running to do cleanup work (#458, #479, #728, #769).
  • Add new --exit-code (-x) flag that will pass-through the exit form the command being ran (#755).

v3.12.1 - 2022-05-10

  • Fixed bug where, on Windows, variables were ending with \r because we were only removing the final \n but not \r\n (#717).

v3.12.0 - 2022-03-31

  • The --list and --list-all flags can now be combined with the --silent flag to print the task names only, without their description (#691).
  • Added support for multi-level inclusion of Taskfiles. This means that included Taskfiles can also include other Taskfiles. Before this was limited to one level (#390, #623, #656).
  • Add ability to specify vars when including a Taskfile. Check out the documentation for more information. (#677).

v3.11.0 - 2022-02-19

v3.10.0 - 2022-01-04

  • A new --list-all (alias -a) flag is now available. It's similar to the exiting --list (-l) but prints all tasks, even those without a description (#383, #401).
  • It's now possible to schedule cleanup commands to run once a task finishes with the defer: keyword (Documentation, #475, #626).
  • Remove long deprecated and undocumented $ variable prefix and ^ command prefix (#642, #644, #645).
  • Add support for .yaml extension (as an alternative to .yml). This was requested multiple times throughout the years. Enjoy! (#183, #184, #369, #584, #621).
  • Fixed error when computing a variable when the task directory do not exist yet (#481, #579).

v3.9.2 - 2021-12-02

v3.9.1 - 2021-11-28

  • Add logging in verbose mode for when a task starts and finishes (#533, #588).
  • Fix an issue with preconditions and context errors (#597, #598).
  • Quote each {{.CLI_ARGS}} argument to prevent one with spaces to become many (#613).
  • Fix nil pointer when cmd: was left empty (#612, #614).
  • Upgrade mvdan/sh which contains two relevant fixes:
    • Fix quote of empty strings in shellQuote (#609, mvdan/sh#763).
    • Fix issue of wrong environment variable being picked when there's another very similar one (#586, mvdan/sh#745).
  • Install shell completions automatically when installing via Homebrew (#264, #592, go-task/homebrew-tap#2).

v3.9.0 - 2021-10-02

v3.8.0 - 2021-09-26

  • Add interactive: true setting to improve support for interactive CLI apps (#217, #563).
  • Fix some nil errors (#534, #573).
  • Add ability to declare an included Taskfile as optional (#519, #552).
  • Add support for including Taskfiles in the home directory by using ~ (#539, #557).

v3.7.3 - 2021-09-04

v3.7.0 - 2021-07-31

  • Add run: setting to control if tasks should run multiple times or not. Available options are always (the default), when_changed (if a variable modified the task) and once (run only once no matter what). This is a long time requested feature. Enjoy! (#53, #359).

v3.6.0 - 2021-07-10

  • Allow using both sources: and status: in the same task (#411, #427, #477).
  • Small optimization and bug fix: don't compute variables if not needed for dotenv: (#517).

v3.5.0 - 2021-07-04

  • Add support for interpolation in dotenv: (#433, #434, #453).

v3.4.3 - 2021-05-30

  • Add support for the NO_COLOR environment variable. (#459, fatih/color#137).
  • Fix bug where sources were not considering the right directory in --watch mode (#484, #485).

v3.4.2 - 2021-04-23

  • On watch, report which file failed to read (#472).
  • Do not try to catch SIGKILL signal, which are not actually possible (#476).
  • Improve version reporting when building Task from source using Go Modules (#462, #473).

v3.4.1 - 2021-04-17

  • Improve error reporting when parsing YAML: in some situations where you would just see an generic error, you'll now see the actual error with more detail: the YAML line the failed to parse, for example (#467).
  • A JSON Schema was published here and is automatically being used by some editors like Visual Studio Code (#135).
  • Print task name before the command in the log output (#398).

v3.3.0 - 2021-03-20

  • Add support for delegating CLI arguments to commands with -- and a special CLI_ARGS variable (#327).
  • Add a --concurrency (alias -C) flag, to limit the number of tasks that run concurrently. This is useful for heavy workloads. (#345).

v3.2.2 - 2021-01-12

  • Improve performance of --list and --summary by skipping running shell variables for these flags (#332).
  • Fixed a bug where an environment in a Taskfile was not always overridable by the system environment (#425).
  • Fixed environment from .env files not being available as variables (#379).
  • The install script is now working for ARM platforms (#428).

v3.2.1 - 2021-01-09

  • Fixed some bugs and regressions regarding dynamic variables and directories (#426).
  • The slim-sprig package was updated with the upstream sprig.

v3.2.0 - 2021-01-07

  • Fix the .task directory being created in the task directory instead of the Taskfile directory (#247).
  • Fix a bug where dynamic variables (those declared with sh:) were not running in the task directory when the task has a custom dir or it was in an included Taskfile (#384).
  • The watch feature (via the --watch flag) got a few different bug fixes and should be more stable now (#423, #365).

v3.1.0 - 2021-01-03

  • Fix a bug when the checksum up-to-date resolution is used by a task with a custom label: attribute (#412).
  • Starting from this release, we're releasing official ARMv6 and ARM64 binaries for Linux (#375, #418).
  • Task now respects the order of declaration of included Taskfiles when evaluating variables declaring by them (#393).
  • set -e is now automatically set on every command. This was done to fix an issue where multiline string commands wouldn't really fail unless the sentence was in the last line (#403).

v3.0.1 - 2020-12-26

  • Allow use as a library by moving the required packages out of the internal directory (#358).
  • Do not error if a specified dotenv file does not exist (#378, #385).
  • Fix panic when you have empty tasks in your Taskfile (#338, #362).

v3.0.0 - 2020-08-16

  • On v3, all CLI variables will be considered global variables (#336, #341)
  • Add support to .env like files (#324, #356).
  • Add label: to task so you can override the task name in the logs (#321, #337).
  • Refactor how variables work on version 3 (#311).
  • Disallow expansions on v3 since it has no effect.
  • Taskvars.yml is not automatically included anymore.
  • Taskfile_{{OS}}.yml is not automatically included anymore.
  • Allow interpolation on includes, so you can manually include a Taskfile based on operation system, for example.
  • Expose .TASK variable in templates with the task name (#252).
  • Implement short task syntax (#194, #240).
  • Added option to make included Taskfile run commands on its own directory (#260, #144)
  • Taskfiles in version 1 are not supported anymore (#237).
  • Added global method: option. With this option, you can set a default method to all tasks in a Taskfile (#246).
  • Changed default method from timestamp to checksum (#246).
  • New magic variables are now available when using status:: .TIMESTAMP which contains the greatest modification date from the files listed in sources:, and .CHECKSUM, which contains a checksum of all files listed in status:. This is useful for manual checking when using external, or even remote, artifacts when using status: (#216).
  • We're now using slim-sprig instead of sprig, which allowed a file size reduction of about 22% (#219).
  • We now use some colors on Task output to better distinguish message types - commands are green, errors are red, etc (#207).

v2.8.1 - 2020-05-20

  • Fix error code for the --help flag (#300, #330).
  • Print version to stdout instead of stderr (#299, #329).
  • Supress context errors when using the --watch flag (#313, #317).
  • Support templating on description (#276, #283).

v2.8.0 - 2019-12-07

  • Add --parallel flag (alias -p) to run tasks given by the command line in parallel (#266).
  • Fixed bug where calling the task CLI only informing global vars would not execute the default task.
  • Add hability to silent all tasks by adding silent: true a the root of the Taskfile.

v2.7.1 - 2019-11-10

  • Fix error being raised when exit 0 was called (#251).

v2.7.0 - 2019-09-22

  • Fixed panic bug when assigning a global variable (#229, #243).
  • A task with method: checksum will now re-run if generated files are deleted (#228, #238).

v2.6.0 - 2019-07-21

  • Fixed some bugs regarding minor version checks on version:.
  • Add preconditions: to task (#205).
  • Create directory informed on dir: if it doesn't exist (#209, #211).
  • We now have a --taskfile flag (alias -t), which can be used to run another Taskfile (other than the default Taskfile.yml) (#221).
  • It's now possible to install Task using Homebrew on Linux (go-task/homebrew-tap#1).

v2.5.2 - 2019-05-11

  • Reverted YAML upgrade due issues with CRLF on Windows (#201, go-yaml/yaml#450).
  • Allow setting global variables through the CLI (#192).

2.5.1 - 2019-04-27

  • Fixed some issues with interactive command line tools, where sometimes the output were not being shown, and similar issues (#114, #190, #200).
  • Upgraded go-yaml/yaml from v2 to v3.

v2.5.0 - 2019-03-16

v2.4.0 - 2019-02-21

  • Allow calling a task of the root Taskfile from an included Taskfile by prefixing it with : (#161, #172),
  • Add flag to override the output option (#173);
  • Fix bug where Task was persisting the new checksum on the disk when the Dry Mode is enabled (#166);
  • Fix file timestamp issue when the file name has spaces (#176);
  • Mitigating path expanding issues on Windows (#170).

v2.3.0 - 2019-01-02

  • On Windows, Task can now be installed using Scoop (#152);
  • Fixed issue with file/directory globing (#153);
  • Added ability to globally set environment variables ( #138, #159 ).

v2.2.1 - 2018-12-09

  • This repository now uses Go Modules (#143). We'll still keep the vendor directory in sync for some time, though;
  • Fixing a bug when the Taskfile has no tasks but includes another Taskfile (#150);
  • Fix a bug when calling another task or a dependency in an included Taskfile (#151).

v2.2.0 - 2018-10-25

  • Added support for including other Taskfiles (#98)
    • This should be considered experimental. For now, only including local files is supported, but support for including remote Taskfiles is being discussed. If you have any feedback, please comment on #98.
  • Task now have a dedicated documentation site: https://taskfile.org
    • Thanks to Docsify for making this pretty easy. To check the source code, just take a look at the docs directory of this repository. Contributions to the documentation is really appreciated.

v2.1.1 - 2018-09-17

  • Fix suggestion to use task --init not being shown anymore (when a Taskfile.yml is not found)
  • Fix error when using checksum method and no file exists for a source glob (#131)
  • Fix signal handling when the --watch flag is given (#132)

v2.1.0 - 2018-08-19

  • Add a ignore_error option to task and command (#123)
  • Add a dry run mode (--dry flag) (#126)

v2.0.3 - 2018-06-24

  • Expand environment variables on "dir", "sources" and "generates" (#116)
  • Fix YAML merging syntax (#112)
  • Add ZSH completion (#111)
  • Implement new output option. Please check out the documentation

v2.0.2 - 2018-05-01

  • Fix merging of YAML anchors (#112)

v2.0.1 - 2018-03-11

  • Fixes panic on task --list

v2.0.0 - 2018-03-08

Version 2.0.0 is here, with a new Taskfile format.

Please, make sure to read the Taskfile versions document, since it describes in depth what changed for this version.

v1.4.4 - 2017-11-19

  • Handle SIGINT and SIGTERM (#75);
  • List: print message with there's no task with description;
  • Expand home dir ("~" symbol) on paths (#74);
  • Add Snap as an installation method;
  • Move examples to its own repo;
  • Watch: also walk on tasks called on on "cmds", and not only on "deps";
  • Print logs to stderr instead of stdout (#68);
  • Remove deprecated set keyword;
  • Add checksum based status check, alternative to timestamp based.

v1.4.3 - 2017-09-07

  • Allow assigning variables to tasks at run time via CLI (#33)
  • Added suport for multiline variables from sh (#64)
  • Fixes env: remove square braces and evaluate shell (#62)
  • Watch: change watch library and few fixes and improvements
  • When use watching, cancel and restart long running process on file change (#59 and #60)

v1.4.2 - 2017-07-30

  • Flag to set directory of execution
  • Always echo command if is verbose mode
  • Add silent mode to disable echoing of commands
  • Fixes and improvements of variables (#56)

v1.4.1 - 2017-07-15

  • Allow use of YAML for dynamic variables instead of $ prefix
    • VAR: {sh: echo Hello} instead of VAR: $echo Hello
  • Add --list (or -l) flag to print existing tasks
  • OS specific Taskvars file (e.g. Taskvars_windows.yml, Taskvars_linux.yml, etc)
  • Consider task up-to-date on equal timestamps (#49)
  • Allow absolute path in generates section (#48)
  • Bugfix: allow templating when calling deps (#42)
  • Fix panic for invalid task in cyclic dep detection
  • Better error output for dynamic variables in Taskvars.yml (#41)
  • Allow template evaluation in parameters

v1.4.0 - 2017-07-06

  • Cache dynamic variables
  • Add verbose mode (-v flag)
  • Support to task parameters (overriding vars) (#31) (#32)
  • Print command, also when "set:" is specified (#35)
  • Improve task command help text (#35)

v1.3.1 - 2017-06-14

  • Fix glob not working on commands (#28)
  • Add ExeExt template function
  • Add --init flag to create a new Taskfile
  • Add status option to prevent task from running (#27)
  • Allow interpolation on generates and sources attributes (#26)

v1.3.0 - 2017-04-24

  • Migrate from os/exec.Cmd to a native Go sh/bash interpreter
    • This is a potentially breaking change if you use Windows.
    • Now, cmd is not used anymore on Windows. Always use Bash-like syntax for your commands, even on Windows.
  • Add "ToSlash" and "FromSlash" to template functions
  • Use functions defined on github.com/Masterminds/sprig
  • Do not redirect stdin while running variables commands
  • Using context and errgroup packages (this will make other tasks to be cancelled, if one returned an error)

v1.2.0 - 2017-04-02

  • More tests and Travis integration
  • Watch a task (experimental)
  • Possibility to call another task
  • Fix "=" not being reconized in variables/environment variables
  • Tasks can now have a description, and help will print them (#10)
  • Task dependencies now run concurrently
  • Support for a default task (#16)

v1.1.0 - 2017-03-08

  • Support for YAML, TOML and JSON (#1)
  • Support running command in another directory (#4)
  • --force or -f flag to force execution of task even when it's up-to-date
  • Detection of cyclic dependencies (#5)
  • Support for variables (#6, #9, #14)
  • Operation System specific commands and variables (#13)

v1.0.0 - 2017-02-28

  • Add LICENSE file
- +

更新日志

v3.23.0 - 2023-03-26

Task now has an official extension for Visual Studio Code contributed by @pd93! 🎉 The extension is maintained in a new repository under the go-task organization. We're looking to gather feedback from the community so please give it a go and let us know what you think via a discussion, issue or on our Discord!

注意: 扩展 需要安装 v3.23.0 才能正常工作。

  • The website was integrated with Crowdin to allow the community to contribute with translations! Chinese is the first language available (#1057, #1058 by @misitebao).
  • Added task location data to the --json flag output (#1056 by @pd93)
  • Change the name of the file generated by task --init from Taskfile.yaml to Taskfile.yml (#1062 by @misitebao).
  • Added new splitArgs template function ({{splitArgs "foo bar 'foo bar +baz'"}}) to ensure string is split as arguments (#1040, #1059 by @dhanusaputra).
  • Fix the value of {{.CHECKSUM}} variable in status (#1076, #1080 by @pd93).
  • Fixed deep copy implementation (#1072 by @pd93)
  • Created a tool to assist with releases (#1086 by @pd93).

v3.22.0 - 2023-03-10

  • Add a brand new --global (-g) flag that will run a Taskfile from your $HOME directory. This is useful to have automation that you can run from anywhere in your system! (Documentation, #1029 by @andreynering).
  • Add ability to set error_only: true on the group output mode. This will instruct Task to only print a command output if it returned with a non-zero exit code (#664, #1022 by @jaedle).
  • Fixed bug where .task/checksum file was sometimes not being created when task also declares a status: (#840, #1035 by @harelwa, #1037 by @pd93).
  • Refactored and decoupled fingerprinting from the main Task executor (#1039 by @pd93).
  • Fixed deadlock issue when using run: once (#715, #1025 by @theunrepentantgeek).

v3.21.0 - 2023-02-22

  • Added new TASK_VERSION special variable (#990, #1014 by @ja1code).
  • Fixed a bug where tasks were sometimes incorrectly marked as internal (#1007 by @pd93).
  • Update to Go 1.20 (bump minimum version to 1.19) (#1010 by @pd93)
  • Added environment variable FORCE_COLOR support to force color output. Usefull for environments without TTY (#1003 by @automation-stack)

v3.20.0 - 2023-01-14

  • Improve behavior and performance of status checking when using the timestamp mode (#976, #977 by @aminya).
  • Performance optimizations were made for large Taskfiles (#982 by @pd93).
  • Add ability to configure options for the set and shopt builtins (#908, #929 by @pd93, Documentation).
  • Add new platforms: attribute to task and cmd, so it's now possible to choose in which platforms that given task or command will be run on. Possible values are operating system (GOOS), architecture (GOARCH) or a combination of the two. Example: platforms: [linux], platforms: [amd64] or platforms: +[linux/amd64]. Other platforms will be skipped (#978, #980 by @leaanthony).

v3.19.1 - 2022-12-31

  • Small bug fix: closing Taskfile.yml once we're done reading it (#963, #964 by @HeCorr).
  • Fixes a bug in v2 that caused a panic when using a Taskfile_{{OS}}.yml file (#961, #971 by @pd93).
  • Fixed a bug where watch intervals set in the Taskfile were not being respected (#969, #970 by @pd93)
  • Add --json flag (alias -j) with the intent to improve support for code editors and add room to other possible integrations. This is basic for now, but we plan to add more info in the near future (#936 by @davidalpert, #764).

v3.19.0 - 2022-12-05

v3.18.0 - 2022-11-12

  • Show aliases on task --list --silent (task --ls). This means that aliases will be completed by the completion scripts (#919).
  • Tasks in the root Taskfile will now be displayed first in --list/--list-all output (#806, #890).
  • It's now possible to call a default task in an included Taskfile by using just the namespace. For example: docs:default is now automatically aliased to docs (#661, #815).

v3.17.0 - 2022-10-14

  • Add a "Did you mean ...?" suggestion when a task does not exits another one with a similar name is found (#867, #880).
  • Now YAML parse errors will print which Taskfile failed to parse (#885, #887).
  • Add ability to set aliases for tasks and namespaces (#268, #340, #879).
  • Improvements to Fish shell completion (#897).
  • Added ability to set a different watch interval by setting interval: '500ms' or using the --interval=500ms flag (#813, #865).
  • Add colored output to --list, --list-all and --summary flags (#845, #874).
  • Fix unexpected behavior where label: was being shown instead of the task name on --list (#603, #877).

v3.16.0 - 2022-09-29

  • Add npm as new installation method: npm i -g [@go](https://github.com/go)-task/cli (#870, #871, npm package).
  • Add support to marking tasks and includes as internal, which will hide them from --list and --list-all (#818).

v3.15.2 - 2022-09-08

  • Fix error when using variable in env: introduced in the previous release (#858, #866).
  • Fix handling of CLI_ARGS (--) in Bash completion (#863).
  • On zsh completion, add ability to replace --list-all with --list as already possible on the Bash completion (#861).

v3.15.0 - 2022-09-03

  • Add new special variables ROOT_DIR and TASKFILE_DIR. This was a highly requested feature (#215, #857, Documentation).
  • Follow symlinks on sources (#826, #831).
  • Improvements and fixes to Bash completion (#835, #844).

v3.14.1 - 2022-08-03

  • Always resolve relative include paths relative to the including Taskfile (#822, #823).
  • Fix ZSH and PowerShell completions to consider all tasks instead of just the public ones (those with descriptions) (#803).

v3.14.0 - 2022-07-08

  • Add ability to override the .task directory location with the TASK_TEMP_DIR environment variable.
  • Allow to override Task colors using environment variables: TASK_COLOR_RESET, TASK_COLOR_BLUE, TASK_COLOR_GREEN, TASK_COLOR_CYAN, TASK_COLOR_YELLOW, TASK_COLOR_MAGENTA and TASK_COLOR_RED (#568, #792).
  • Fixed bug when using the output: group mode where STDOUT and STDERR were being print in separated blocks instead of in the right order (#779).
  • Starting on this release, ARM architecture binaries are been released to Snap as well (#795).
  • i386 binaries won't be available anymore on Snap because Ubuntu removed the support for this architecture.
  • Upgrade mvdan.cc/sh, which fixes a bug with associative arrays (#785, mvdan/sh[#884](https://github.com/go-task/task/issues/884), mvdan/sh[#893](https://github.com/go-task/task/issues/893)).

v3.13.0 - 2022-06-13

  • Added -n as an alias to --dry (#776, #777).
  • Fix behavior of interrupt (SIGINT, SIGTERM) signals. Task will now give time for the processes running to do cleanup work (#458, #479, #728, #769).
  • Add new --exit-code (-x) flag that will pass-through the exit form the command being ran (#755).

v3.12.1 - 2022-05-10

  • Fixed bug where, on Windows, variables were ending with \r because we were only removing the final \n but not \r\n (#717).

v3.12.0 - 2022-03-31

  • The --list and --list-all flags can now be combined with the --silent flag to print the task names only, without their description (#691).
  • Added support for multi-level inclusion of Taskfiles. This means that included Taskfiles can also include other Taskfiles. Before this was limited to one level (#390, #623, #656).
  • Add ability to specify vars when including a Taskfile. Check out the documentation for more information (#677).

v3.11.0 - 2022-02-19

v3.10.0 - 2022-01-04

  • A new --list-all (alias -a) flag is now available. It's similar to the exiting --list (-l) but prints all tasks, even those without a description (#383, #401).
  • It's now possible to schedule cleanup commands to run once a task finishes with the defer: keyword (Documentation, #475, #626).
  • Remove long deprecated and undocumented $ variable prefix and ^ command prefix (#642, #644, #645).
  • Add support for .yaml extension (as an alternative to .yml). This was requested multiple times throughout the years. Enjoy! (#183, #184, #369, #584, #621).
  • Fixed error when computing a variable when the task directory do not exist yet (#481, #579).

v3.9.2 - 2021-12-02

v3.9.1 - 2021-11-28

v3.9.0 - 2021-10-02

v3.8.0 - 2021-09-26

  • Add interactive: true setting to improve support for interactive CLI apps (#217, #563).
  • Fix some nil errors (#534, #573).
  • Add ability to declare an included Taskfile as optional (#519, #552).
  • Add support for including Taskfiles in the home directory by using ~ (#539, #557).

v3.7.3 - 2021-09-04

v3.7.0 - 2021-07-31

  • Add run: setting to control if tasks should run multiple times or not. Available options are always (the default), when_changed (if a variable modified the task) and once (run only once no matter what). This is a long time requested feature. Enjoy! (#53, #359).

v3.6.0 - 2021-07-10

  • Allow using both sources: and status: in the same task (#411, #427, #477).
  • Small optimization and bug fix: don't compute variables if not needed for dotenv: (#517).

v3.5.0 - 2021-07-04

  • Add support for interpolation in dotenv: (#433, #434, #453).

v3.4.3 - 2021-05-30

v3.4.2 - 2021-04-23

  • On watch, report which file failed to read (#472).
  • Do not try to catch SIGKILL signal, which are not actually possible (#476).
  • Improve version reporting when building Task from source using Go Modules (#462, #473).

v3.4.1 - 2021-04-17

  • Improve error reporting when parsing YAML: in some situations where you would just see an generic error, you'll now see the actual error with more detail: the YAML line the failed to parse, for example (#467).
  • A JSON Schema was published here and is automatically being used by some editors like Visual Studio Code (#135).
  • Print task name before the command in the log output (#398).

v3.3.0 - 2021-03-20

  • Add support for delegating CLI arguments to commands with -- and a special CLI_ARGS variable (#327).
  • Add a --concurrency (alias -C) flag, to limit the number of tasks that run concurrently. This is useful for heavy workloads. (#345).

v3.2.2 - 2021-01-12

  • Improve performance of --list and --summary by skipping running shell variables for these flags (#332).
  • Fixed a bug where an environment in a Taskfile was not always overridable by the system environment (#425).
  • Fixed environment from .env files not being available as variables (#379).
  • The install script is now working for ARM platforms (#428).

v3.2.1 - 2021-01-09

  • Fixed some bugs and regressions regarding dynamic variables and directories (#426).
  • The slim-sprig package was updated with the upstream sprig.

v3.2.0 - 2021-01-07

  • Fix the .task directory being created in the task directory instead of the Taskfile directory (#247).
  • Fix a bug where dynamic variables (those declared with sh:) were not running in the task directory when the task has a custom dir or it was in an included Taskfile (#384).
  • The watch feature (via the --watch flag) got a few different bug fixes and should be more stable now (#423, #365).

v3.1.0 - 2021-01-03

  • Fix a bug when the checksum up-to-date resolution is used by a task with a custom label: attribute (#412).
  • Starting from this release, we're releasing official ARMv6 and ARM64 binaries for Linux (#375, #418).
  • Task now respects the order of declaration of included Taskfiles when evaluating variables declaring by them (#393).
  • set -e is now automatically set on every command. This was done to fix an issue where multiline string commands wouldn't really fail unless the sentence was in the last line (#403).

v3.0.1 - 2020-12-26

  • Allow use as a library by moving the required packages out of the internal directory (#358).
  • Do not error if a specified dotenv file does not exist (#378, #385).
  • Fix panic when you have empty tasks in your Taskfile (#338, #362).

v3.0.0 - 2020-08-16

  • On v3, all CLI variables will be considered global variables (#336, #341)
  • Add support to .env like files (#324, #356).
  • Add label: to task so you can override the task name in the logs ([#321](https://github.com/go-task/task/issues/321), #337).
  • Refactor how variables work on version 3 (#311).
  • Disallow expansions on v3 since it has no effect.
  • Taskvars.yml is not automatically included anymore.
  • Taskfile_{{OS}}.yml is not automatically included anymore.
  • Allow interpolation on includes, so you can manually include a Taskfile based on operation system, for example.
  • Expose .TASK variable in templates with the task name (#252).
  • Implement short task syntax (#194, #240).
  • Added option to make included Taskfile run commands on its own directory (#260, #144)
  • Taskfiles in version 1 are not supported anymore (#237).
  • Added global method: option. With this option, you can set a default method to all tasks in a Taskfile (#246).
  • Changed default method from timestamp to checksum (#246).
  • New magic variables are now available when using status:: .TIMESTAMP which contains the greatest modification date from the files listed in sources:, and .CHECKSUM, which contains a checksum of all files listed in status:. This is useful for manual checking when using external, or even remote, artifacts when using status: (#216).
  • We're now using slim-sprig instead of sprig, which allowed a file size reduction of about 22% (#219).
  • We now use some colors on Task output to better distinguish message types - commands are green, errors are red, etc (#207).

v2.8.1 - 2020-05-20

  • Fix error code for the --help flag (#300, #330).
  • Print version to stdout instead of stderr (#299, #329).
  • Supress context errors when using the --watch flag (#313, #317).
  • Support templating on description (#276, #283).

v2.8.0 - 2019-12-07

  • Add --parallel flag (alias -p) to run tasks given by the command line in parallel (#266).
  • Fixed bug where calling the task CLI only informing global vars would not execute the default task.
  • Add hability to silent all tasks by adding silent: true a the root of the Taskfile.

v2.7.1 - 2019-11-10

  • Fix error being raised when exit 0 was called (#251).

v2.7.0 - 2019-09-22

  • Fixed panic bug when assigning a global variable (#229, #243).
  • A task with method: checksum will now re-run if generated files are deleted (#228, #238).

v2.6.0 - 2019-07-21

  • Fixed some bugs regarding minor version checks on version:.
  • Add preconditions: to task (#205).
  • Create directory informed on dir: if it doesn't exist (#209, #211).
  • We now have a --taskfile flag (alias -t), which can be used to run another Taskfile (other than the default Taskfile.yml) (#221).
  • It's now possible to install Task using Homebrew on Linux (go-task/homebrew-tap[#1](https://github.com/go-task/task/issues/1)).

v2.5.2 - 2019-05-11

2.5.1 - 2019-04-27

  • Fixed some issues with interactive command line tools, where sometimes the output were not being shown, and similar issues (#114, #190, #200).
  • Upgraded go-yaml/yaml from v2 to v3.

v2.5.0 - 2019-03-16

v2.4.0 - 2019-02-21

  • Allow calling a task of the root Taskfile from an included Taskfile by prefixing it with : (#161, #172).
  • Add flag to override the output option (#173).
  • Fix bug where Task was persisting the new checksum on the disk when the Dry Mode is enabled (#166).
  • Fix file timestamp issue when the file name has spaces (#176).
  • Mitigating path expanding issues on Windows (#170).

v2.3.0 - 2019-01-02

  • On Windows, Task can now be installed using Scoop (#152).
  • Fixed issue with file/directory globing (#153).
  • Added ability to globally set environment variables (#138, #159).

v2.2.1 - 2018-12-09

  • This repository now uses Go Modules (#143). We'll still keep the vendor directory in sync for some time, though;
  • Fixing a bug when the Taskfile has no tasks but includes another Taskfile (#150);
  • Fix a bug when calling another task or a dependency in an included Taskfile (#151).

v2.2.0 - 2018-10-25

  • Added support for including other Taskfiles (#98)
    • This should be considered experimental. For now, only including local files is supported, but support for including remote Taskfiles is being discussed. If you have any feedback, please comment on #98.
  • Task now have a dedicated documentation site: https://taskfile.org
    • Thanks to Docsify for making this pretty easy. To check the source code, just take a look at the docs directory of this repository. Contributions to the documentation is really appreciated.

v2.1.1 - 2018-09-17

  • Fix suggestion to use task --init not being shown anymore (when a Taskfile.yml is not found)
  • Fix error when using checksum method and no file exists for a source glob (#131)
  • Fix signal handling when the --watch flag is given (#132)

v2.1.0 - 2018-08-19

  • Add a ignore_error option to task and command (#123)
  • Add a dry run mode (--dry flag) (#126)

v2.0.3 - 2018-06-24

  • Expand environment variables on "dir", "sources" and "generates" (#116)
  • Fix YAML merging syntax (#112)
  • Add ZSH completion (#111)
  • Implement new output option. Please check out the documentation

v2.0.2 - 2018-05-01

  • Fix merging of YAML anchors (#112)

v2.0.1 - 2018-03-11

  • Fixes panic on task --list

v2.0.0 - 2018-03-08

Version 2.0.0 is here, with a new Taskfile format.

Please, make sure to read the Taskfile versions document, since it describes in depth what changed for this version.

  • New Taskfile version 2 (#77)
  • Possibility to have global variables in the Taskfile.yml instead of Taskvars.yml (#66)
  • Small improvements and fixes

v1.4.4 - 2017-11-19

  • Handle SIGINT and SIGTERM (#75);
  • List: print message with there's no task with description;
  • Expand home dir ("~" symbol) on paths (#74);
  • Add Snap as an installation method;
  • Move examples to its own repo;
  • Watch: also walk on tasks called on on "cmds", and not only on "deps";
  • Print logs to stderr instead of stdout (#68);
  • Remove deprecated set keyword;
  • Add checksum based status check, alternative to timestamp based.

v1.4.3 - 2017-09-07

  • Allow assigning variables to tasks at run time via CLI (#33)
  • Added suport for multiline variables from sh (#64)
  • Fixes env: remove square braces and evaluate shell (#62)
  • Watch: change watch library and few fixes and improvements
  • When use watching, cancel and restart long running process on file change (#59 and #60)

v1.4.2 - 2017-07-30

  • Flag to set directory of execution
  • Always echo command if is verbose mode
  • Add silent mode to disable echoing of commands
  • Fixes and improvements of variables (#56)

v1.4.1 - 2017-07-15

  • Allow use of YAML for dynamic variables instead of $ prefix
    • VAR: {sh: echo Hello} instead of VAR: $echo Hello
  • Add --list (or -l) flag to print existing tasks
  • OS specific Taskvars file (e.g. Taskvars_windows.yml, Taskvars_linux.yml, etc)
  • Consider task up-to-date on equal timestamps (#49)
  • Allow absolute path in generates section (#48)
  • Bugfix: allow templating when calling deps (#42)
  • Fix panic for invalid task in cyclic dep detection
  • Better error output for dynamic variables in Taskvars.yml (#41)
  • Allow template evaluation in parameters

v1.4.0 - 2017-07-06

  • Cache dynamic variables
  • Add verbose mode (-v flag)
  • Support to task parameters (overriding vars) (#31) (#32)
  • Print command, also when "set:" is specified (#35)
  • Improve task command help text (#35)

v1.3.1 - 2017-06-14

  • Fix glob not working on commands (#28)
  • Add ExeExt template function
  • Add --init flag to create a new Taskfile
  • Add status option to prevent task from running (#27)
  • Allow interpolation on generates and sources attributes (#26)

v1.3.0 - 2017-04-24

  • Migrate from os/exec.Cmd to a native Go sh/bash interpreter
    • This is a potentially breaking change if you use Windows.
    • Now, cmd is not used anymore on Windows. Always use Bash-like syntax for your commands, even on Windows.
  • Add "ToSlash" and "FromSlash" to template functions
  • Use functions defined on github.com/Masterminds/sprig
  • Do not redirect stdin while running variables commands
  • Using context and errgroup packages (this will make other tasks to be cancelled, if one returned an error)

v1.2.0 - 2017-04-02

  • More tests and Travis integration
  • Watch a task (experimental)
  • Possibility to call another task
  • Fix "=" not being reconized in variables/environment variables
  • Tasks can now have a description, and help will print them (#10)
  • Task dependencies now run concurrently
  • Support for a default task (#16)

v1.1.0 - 2017-03-08

  • Support for YAML, TOML and JSON (#1)
  • Support running command in another directory (#4)
  • --force or -f flag to force execution of task even when it's up-to-date
  • Detection of cyclic dependencies (#5)
  • Support for variables (#6, #9, #14)
  • Operation System specific commands and variables (#13)

v1.0.0 - 2017-02-28

  • Add LICENSE file
+ \ No newline at end of file diff --git a/zh-Hans/community/index.html b/zh-Hans/community/index.html index eaaa725a..71e0f290 100644 --- a/zh-Hans/community/index.html +++ b/zh-Hans/community/index.html @@ -10,13 +10,13 @@ - +

社区

一些改善 Task 生态的工作是由社区完成,包括安装方法或代码编辑器集成。 我(指作者)非常感谢所有帮助提升整体体验的人们。

翻译

@DeronW此存储库 中维护网站的 中文翻译

编辑器集成

JSON Schema

Schema 的初步工作是由 @KROSF 在此 Gist 上完成的。 这个 Schema 目前在 https://taskfile.dev/schema.json 上可用,并在 https://json.schemastore.org/taskfile.json 上添加了链接,因此它可以自动在许多代码编辑器使用,例如 VSCode。 可以通过编辑 此文件 来完成贡献。

Visual Studio Code 扩展

另外,在开发 Visual Studio Code 扩展过程中, 还有一些工作由 @paulvarache 完成, 代码在 这里 并发布到了 这里

Sublime Text 4 包

通过 Sublime Text 的命令面板有一个简便的安装运行方法。 这个包是由 @biozz 开发的, 源代码在 这里 并且发布到了包管理 这里

IntelliJ 插件

JetBrains IntelliJ 插件由 @lechuckroh 完成, 代码在 这里 并且发布到了 这里

其他集成

  • mk 命令行工具可以原生识别任务文件。

安装方法

有些安装方式是通过第三方维护的:

更多

同时,感谢所有 代码贡献者资金赞助,以及 提交问题解答问题 的人。

如果你发现文档有哪些遗漏信息,欢迎提交 pull request。

- + \ No newline at end of file diff --git a/zh-Hans/contributing/index.html b/zh-Hans/contributing/index.html index f7013e15..5ccdde8b 100644 --- a/zh-Hans/contributing/index.html +++ b/zh-Hans/contributing/index.html @@ -10,14 +10,14 @@ - +

贡献

非常欢迎对 Task 的贡献,但我们要求您在提交 PR 之前阅读本文档。

开始之前

  • 检查已有工作 - 是否已经存在 PR? 是否存在 Issue 正在讨论您要进行的功能/更改? 请确保你的工作中确实考虑了这些相关的讨论内容。
  • 向后兼容 - 你的变更是否破坏了已经存在的 Taskfile? 向后兼容的变更会更容易被合并进去。 您是否可以采取一种方法来保持这种兼容性? 如果没有,请考虑先提出一个 Issue,以便在您投入时间进行 PR 之前讨论 API 的更改。

1. 设置

  • Go - Task 使用 Go 编写。 我们始终支持最新的两个主要 Go 版本,因此请确保您的版本足够新。
  • Node.js - Node.js 用于托管 Task 的文档服务器,如果您想在本地运行此服务器,则需要它。
  • Yarn - Yarn 是 Task 使用的 Node.js 包管理器。

2. 进行变更

  • 代码风格 - 尽量保持现有的代码风格,并确保代码采用 gofmt。 我们在我们的 CI 中使用 golangci-lint 来强制执行一致的风格和最佳实践。 Taskfile 中有一个 lint 命令可以在本地运行。
  • 文档 - 确保添加/更新了相关文档。 请参阅下面的 更新文档 部分。
  • 测试 - 确保添加/更新了相关测试,并且在提交 PR 前已通过所有测试。 请参阅下面的 编写测试 部分。

运行您的变更

要运行带有工作变更的任务,您可以使用 go run ./cmd/task。 要针对 testdata 中的测试任务文件运行任务的开发构建,您可以使用 go run ./cmd/task --dir ./testdata/<my_test_dir> <task_name>

更新文档

Task 用 Docusaurus 托管文档服务。 这可以通过使用 task docs(需要 nodejsyarn)在本地设置和运行。 所有内容均使用 Markdown 编写,位于 docs/docs 目录中。 所有 Markdown 文档都应有 80 个字符的换行限制。

进行变更时,请考虑是否有必要更改 使用指南。 本文档包含有关如何使用任务功能的说明和示例。 如果您要添加新功能,请尝试找到合适的位置来添加新部分。 如果您要更新现有功能,请确保文档和所有示例都是最新的。 确保任何示例都遵循 Taskfile 风格指南

如果您添加了新字段、命令或标志,请确保将其添加到 API 参考 中。 还需要将新字段添加到 JSON Schema 中。 API 参考和 schema 中的字段描述应该匹配。

编写测试

Task 的大部分测试都保存在项目根目录的 task_test.go 文件中并且这是您最有可能想要添加新测试的地方。 这些测试中的大多数在目录中还有一个 testdata 子目录,其中存储了运行测试所需的 Taskfiles/数据。

进行更改时,请考虑是否需要添加新的测试。 这些测试应确保您添加的功能在未来持续工作。 如果您更改了任务的行为,现有测试可能也需要更新。

3. 提交代码

编写有意义的提交信息,避免一个 PR 上有太多提交。 大多数PR应该有一个提交(尽管对于较大的PR来说,把它分成几个提交可能是合理的)。 Git squash和rebase是你的好朋友!

4. 提交 PR

  • 描述变更 - 确保您提供对更改的全面描述。
  • Issue/PR 链接 - 链接到之前相关的 Issue 或 PR。 请描述当前工作与之前的不同之处。
  • 示例 - 添加您认为有助于展示变更效果的示例。
  • PR 草案 - 如果变更还未完成,但您想讨论它们,请将 PR 作为草稿打开并添加评论以开始讨论。 使用评论而不是 PR 描述允许稍后更新描述,同时保留讨论。

常见问题

我想贡献,我从哪里开始?

查看 未解决 Issue 的列表。 我们有一个 good first issue 标签,用于更简单的 Issue,非常适合首次贡献。

欢迎各种贡献,无论是拼写错误修复还是很小的新功能。 您还可以通过对 Issue 进行投票/评论、帮助回答问题或帮助 其他社区项目 来做出贡献。

我被困住了,我在哪里可以获得帮助?

如果您有任何疑问,请随时在我们的 Discord 服务器 上的 #help 论坛频道中提问,或在 GitHub 上打开 讨论


- + \ No newline at end of file diff --git a/zh-Hans/donate/index.html b/zh-Hans/donate/index.html index 8a17f8b2..14ed68c1 100644 --- a/zh-Hans/donate/index.html +++ b/zh-Hans/donate/index.html @@ -10,13 +10,13 @@ - +

赞助

如果您觉得这个项目有用,您可以考虑使用下面列出的渠道之一进行捐赠。

这只是一种表达“感谢”的方式,它不会给你任何好处,比如在 Issue 上的更高优先级或类似的东西。

每月捐赠至少 50 美元的公司将在网站主页和 GitHub 存储库 README 中被标为“金牌赞助商”。 请与 @andreynering 联系,说明你希望显示的标志。 不过,可疑的企业(赌博、赌场等)将不被允许。

GitHub Sponsors

捐赠给维护者的首选方式是通过 GitHub Sponsors。 只需使用以下链接就可以进行捐赠:

Open Collective

如果你喜欢 Open Collective,你可以通过这些链接进行捐赠:

PayPal

你也可以通过 PayPal 向 @andreynering 捐款。

PIX (仅巴西)

如果你是巴西人,你也可以通过 PIX 使用这个QR码@andreynering 捐款。

- + \ No newline at end of file diff --git a/zh-Hans/faq/index.html b/zh-Hans/faq/index.html index 378e69c3..432d6064 100644 --- a/zh-Hans/faq/index.html +++ b/zh-Hans/faq/index.html @@ -10,13 +10,13 @@ - +

常见问题

此页面包含有关 Task 的常见问题列表。

为什么我的 task 不会更新我的 shell 环境?

这是 shell 工作方式的限制。 任务作为当前 shell 的子进程运行,因此它不能更改启动它的 shell 的环境。 其他任务运行器和构建工具也有此限制。

解决此问题的一种常见方法是创建一个 task,该任务将生成可由您的 shell 解析的输出。 例如,要在 shell 上设置环境变量,您可以编写如下任务:

my-shell-env:
cmds:
- echo "export FOO=foo"
- echo "export BAR=bar"

现在运行 eval $(task my-shell-env) 变量 $FOO$BAR 将在您的 shell 中可用。

内置的 'x' 命令在 Windows 上不起作用

Windows 上的默认 shell(cmdpowershell)没有像 rmcp 这样的内置命令。 这意味着这些命令将不起作用。 如果你想让你的 Taskfile 完全跨平台,你需要使用以下方法之一来解决这个限制:

  • 使用 {{OS}} 函数运行特定于操作系统的脚本。
  • 使用 {{if eq OS "windows"}}powershell {{end}}<my_cmd> 之类的东西来检测 windows 并直接在 Powershell 中运行命令。
  • 在 Windows 上使用支持这些命令的 shell 作为内置命令,例如 Git BashWSL

我们希望对 Task 的这一部分进行改进,下面的 Issue 会跟踪这项工作。 非常欢迎建设性的意见和贡献!

- + \ No newline at end of file diff --git a/zh-Hans/index.html b/zh-Hans/index.html index f85b8d51..9401bb14 100644 --- a/zh-Hans/index.html +++ b/zh-Hans/index.html @@ -10,13 +10,13 @@ - +
-

Task

Task 是一个任务运行器/构建工具,旨在比 GNU Make 等更简单易用。

由于它是用 Go 编写的,Task 只是一个二进制文件,没有其他依赖项,这意味着您不需要为了使用构建工具而烦恼任何复杂的安装设置。

安装 后,您只需在名为 Taskfile.yml 的文件中使用简单的 YAML 规则描述您的构建任务:

Taskfile.yml
version: '3'

tasks:
hello:
cmds:
- echo 'Hello World from Task!'
silent: true

然后通过从您的终端运行 task hello 来调用它。

上面的示例只是一个开始,您可以查看 使用指南 以检查完整的模式文档和任务功能。

特性

  • 易于安装:只需要下载一个二进制文件,添加到 $PATH 即可! 或者,您也可以根据需要使用 HomebrewSnapcraftScoop 进行安装。
  • 可以在 CI 中使用:只要添加 这个命令 到 CI 安装脚本中,然后就可以把 Task 当做 CI 的一个功能来使用了。
  • 真正的跨平台:虽然大多数构建工具只能在 Linux 或 macOS 上运行良好,但由于 这个用于 Go 的 shell 解释器,Task 也支持 Windows。
  • 非常适合代码生成:如果给定的一组文件自上次运行以来没有更改(基于其时间戳或内容),您可以轻松地阻止任务运行。

金牌赞助商

[Appwrite][appwrite]
[Appwrite][appwrite]
- +

Task

Task 是一个任务运行器/构建工具,旨在比 GNU Make 等更简单易用。

由于它是用 Go 编写的,Task 只是一个二进制文件,没有其他依赖项,这意味着您不需要为了使用构建工具而烦恼任何复杂的安装设置。

安装 后,您只需在名为 Taskfile.yml 的文件中使用简单的 YAML 规则描述您的构建任务:

Taskfile.yml
version: '3'

tasks:
hello:
cmds:
- echo 'Hello World from Task!'
silent: true

然后通过从您的终端运行 task hello 来调用它。

上面的示例只是一个开始,您可以查看 使用指南 以检查完整的模式文档和任务功能。

特性

  • 易于安装:只需要下载一个二进制文件,添加到 $PATH 即可! 或者,您也可以根据需要使用 HomebrewSnapcraftScoop 进行安装。
  • 可以在 CI 中使用:只要添加 这个命令 到 CI 安装脚本中,然后就可以把 Task 当做 CI 的一个功能来使用了。
  • 真正的跨平台:虽然大多数构建工具只能在 Linux 或 macOS 上运行良好,但由于 这个用于 Go 的 shell 解释器,Task 也支持 Windows。
  • 非常适合代码生成:如果给定的一组文件自上次运行以来没有更改(基于其时间戳或内容),您可以轻松地 阻止任务运行

金牌赞助商

+ \ No newline at end of file diff --git a/zh-Hans/installation/index.html b/zh-Hans/installation/index.html index ad6f5d69..98e28aeb 100644 --- a/zh-Hans/installation/index.html +++ b/zh-Hans/installation/index.html @@ -10,13 +10,13 @@ - +

安装

Task 提供以下多种安装方式。 查看以下可用方法。

包管理工具

Homebrew

如果您使用的是 macOS 或 Linux 并安装了 Homebrew,获取 Task 就像运行以下命令一样简单:

brew install go-task/tap/go-task

上面的公式是 我们自己维护 的。

最近,官方 Homebrew 存储库 中也提供了 Task,因此如果您愿意,也可以使用该选项:

brew install go-task

Snap

Task 在 Snapcraft 中可用,但请记住,您的 Linux 发行版应该符合 Snaps 的基本要求才能正确安装:

sudo snap install task --classic

Chocolatey

如果 Windows 上安装了 Chocolatey,再安装 Task 只要这样:

choco install go-task

这种安装方式是社区维护的。

Scoop

如果 Windows 上安装了 Scoop,再安装 Task 只要这样:

scoop install task

这种安装方式是社区维护的。 新版 Task 发布后,需要过一段时间才能通过 Scoop 安装。

AUR

如果你使用的是 Arch Linux,你可以使用你最喜欢的包管理器(例如 yaypacauryaourt)从 AUR 安装 Task:

yay -S go-task-bin

或者,有一个从源代码安装的 软件包,而不是从 发布页面 下载二进制文件:

yay -S go-task

这种安装方式是社区维护的。

Fedora

如果您使用的是 Fedora Linux,则可以使用 dnf官方 Fedora 存储库 安装 Task:

sudo dnf install go-task

这种安装方式是社区维护的。 新版 Task 发布后,需要一段时间才能通过 Fedora 安装。

Nix

如果您使用的是 NixOS 或安装了 Nix,则可以从 nixpkgs 安装 Task:

nix-env -iA nixpkgs.go-task

这种安装方式是社区维护的。 新版本的 Task 发布后,可能需要一些时间才能在 nixpkgs 中可用。

npm

您也可以通过使用 Node 和 npm 安装 此包 来安装 Task。

npm install -g @go-task/cli

获取二进制文件

二进制文件

您可以从 GitHub 上的发布页面 下载二进制文件并添加到您的 $PATH 中。

还支持 DEB 和 RPM 包。

task_checksums.txt 文件包含每个文件的 SHA-256 checksum。

安装脚本

我们还有一个 安装脚本,它在 CI 等场景中非常有用。 非常感谢 GoDownloader 使这个脚本的生成变得容易。

默认情况下,它安装在相对于工作目录的 ./bin 目录中:

sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d

可以使用 -b 参数覆盖安装目录。 通过 -b 参数可以自定义安装目录,在 Linux 中当前用户安装一般会选择 ~/.local/bin~/bin, 全局用户安装会选择 /usr/local/bin

sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
警告

在 macOS 和 Windows 上,~/.local/bin~/bin 默认情况下不会添加到 $PATH

GitHub Actions

如果你想在 GitHub Actions 中安装 Task,你可以尝试使用 Arduino 团队的 这个 action

- name: Install Task
uses: arduino/setup-task@v1

这种安装方式是社区维护的。

从源码构建

Go Modules

确保您已正确安装和设置受支持的 Go 版本。 您可以在 go.mod 文件中找到最低要求的 Go 版本。

然后,您可以通过运行以下命令全局安装最新版本:

go install github.com/go-task/task/v3/cmd/task@latest

或者你可以安装到另一个目录:

env GOBIN=/bin go install github.com/go-task/task/v3/cmd/task@latest
提示

对于 CI 环境,我们建议改用 安装脚本,它更快更稳定,因为它只会下载最新发布的二进制文件。

自动完成

下载与您的 shell 对应的自动完成文件。

所有自动完成都在任务存储库中可用

Bash

首先,确认你通过包管理安装了 bash-completion。

使完成文件可执行:

chmod +x path/to/task.bash

然后在 ~/.bash_profile 文件中添加:

source path/to/task.bash

ZSH

_task 文件放到你的 $FPATH 中:

mv path/to/_task /usr/local/share/zsh/site-functions/_task

~/.zshrc 文件中添加:

autoload -U compinit
compinit -i

建议使用 ZSH 5.7 或更高版本。

Fish

移动 task.fish 完成脚本:

mv path/to/task.fish ~/.config/fish/completions/task.fish

PowerShell

使用以下命令打开您的配置文件脚本:

mkdir -Path (Split-Path -Parent $profile) -ErrorAction SilentlyContinue
notepad $profile

添加这行并保存文件:

Invoke-Expression -Command path/to/task.ps1
- + \ No newline at end of file diff --git a/zh-Hans/releasing/index.html b/zh-Hans/releasing/index.html index 18757b71..caf32b23 100644 --- a/zh-Hans/releasing/index.html +++ b/zh-Hans/releasing/index.html @@ -10,13 +10,13 @@ - +

发布

Task 的发布流程是在 GoReleaser 的帮助下完成的。 本地调用 Taskfile 的 test-release 任务可以测试发布流程。

GitHub Actions 会在新 tag 推送到 master 分支的时候,自动发布产出物(原生的可执行文件、DEB 和 RPM 包)。

从 v3.15.0 开始,原始可执行文件也可以通过检查特定的标签并调用 goreleaser build,使用上述 GitHub Actions 中定义的 Go 版本,在本地进行复制和验证。

Homebrew

Goreleaser 会自动向 Homebrew tap 仓库中的 Formula/go-task.rb 文件推送一个新的提交,以发布新的版本。

npm

要发布到 npm ,请更新 package.json 文件中的版本,然后运行 task npm:publish 来推送它。

Snapcraft

snap package 发布新版本需要手动执行下面步骤:

Scoop

Scoop 是一个 Windows 系统的命令行包管理工具。 Scoop 的包清单由社区维护。 Scoop 的维护人通常会在 这个文件 里维护版本。 如果发现 Task 版本是旧的,请提交一个 Issue 通知我们。

Nix

Nix 安装由社区维护。 Nix 包的维护人员通常会在 这个文件 里维护版本。 如果发现 Task 版本是旧的,请提交一个 Issue 通知我们。

- + \ No newline at end of file diff --git a/zh-Hans/search/index.html b/zh-Hans/search/index.html index e768322f..833a341a 100644 --- a/zh-Hans/search/index.html +++ b/zh-Hans/search/index.html @@ -10,13 +10,13 @@ - + - + \ No newline at end of file diff --git a/zh-Hans/styleguide/index.html b/zh-Hans/styleguide/index.html index d0a952ec..2b0c0b75 100644 --- a/zh-Hans/styleguide/index.html +++ b/zh-Hans/styleguide/index.html @@ -10,13 +10,13 @@ - +

风格指南

这是对 Taskfile.yml 文件的官方风格指南。 本指南包含一些基本说明,可让您的任务文件保持简洁易用。

这包含一般准则,但不一定需要严格遵守。 如果你需要或想要,请随时提出不同意见,并在某些时候以不同方式进行。 此外,请随时打开 Issue 或 PR,对本指南进行改进。

使用 Taskfile.yml 而不是 taskfile.yml

# bad
taskfile.yml


# good
Taskfile.yml

这对于 Linux 用户尤其重要。 Windows 和 macOS 的文件系统不区分大小写,因此 taskfile.yml 最终会正常工作,即使它不受官方支持。 不过,在 Linux 上,只有 Taskfile.yml 可以工作。

使用正确的关键字顺序

  • version:
  • includes:
  • 可选配置命令,比如 output:silent:method:run:
  • vars:
  • env:dotenv:
  • tasks:

使用2 个空格缩进

这是 YAML 文件最常见的约定,Task 同样也遵循它。

# bad
tasks:
foo:
cmds:
- echo 'foo'


# good
tasks:
foo:
cmds:
- echo 'foo'

用空行分隔主要部分

# bad
version: '3'
includes:
docker: ./docker/Taskfile.yml
output: prefixed
vars:
FOO: bar
env:
BAR: baz
tasks:
# ...


# good
version: '3'

includes:
docker: ./docker/Taskfile.yml

output: prefixed

vars:
FOO: bar

env:
BAR: baz

tasks:
# ...

用空行分隔 task

# bad
version: '3'

tasks:
foo:
cmds:
- echo 'foo'
bar:
cmds:
- echo 'bar'
baz:
cmds:
- echo 'baz'


# good
version: '3'

tasks:
foo:
cmds:
- echo 'foo'

bar:
cmds:
- echo 'bar'

baz:
cmds:
- echo 'baz'

使用大写变量名称

# bad
version: '3'

vars:
binary_name: myapp

tasks:
build:
cmds:
- go build -o {{.binary_name}} .


# good
version: '3'

vars:
BINARY_NAME: myapp

tasks:
build:
cmds:
- go build -o {{.BINARY_NAME}} .

模板中不要用空格包住变量

# bad
version: '3'

tasks:
greet:
cmds:
- echo '{{ .MESSAGE }}'


# good
version: '3'

tasks:
greet:
cmds:
- echo '{{.MESSAGE}}'

这个约定也被大多数人用于 Go 模板。

用破折号分隔任务名称单词

# bad
version: '3'

tasks:
do_something_fancy:
cmds:
- echo 'Do something'


# good
version: '3'

tasks:
do-something-fancy:
cmds:
- echo 'Do something'

使用冒号作为任务命名空间

# good
version: '3'

tasks:
docker:build:
cmds:
- docker ...

docker:run:
cmds:
- docker-compose ...

这在使用包含的任务文件时也会自动完成。

- + \ No newline at end of file diff --git a/zh-Hans/taskfile-versions/index.html b/zh-Hans/taskfile-versions/index.html index f9ae2d06..b91b4132 100644 --- a/zh-Hans/taskfile-versions/index.html +++ b/zh-Hans/taskfile-versions/index.html @@ -10,13 +10,13 @@ - +

Taskfile 版本

Taskfile 语法和功能随着时间的推移而改变。 本文档解释了每个版本的变化以及如何升级您的任务文件。

Taskfile 版本的含义

Taskfile 版本遵循 Task 版本。 例如, taskfile version 2 意味着应该切换为 Task v2.0.0 以支持它。

Taskfile 文件的 version: 关键字接受语义化字符串, 所以 2, 2.02.0.0 都可以。 如果使用版本号 2.0,那么 Task 就不会使用 2.1 的功能, 但如果使用版本号 2, 那么任意 2.x.x 版本中的功能都是可用的, 但 3.0.0+ 的功能不可用。

版本 1

注意:Task v3.0.0 以后就不再支持 Taskfiles 的 1 版本了。

最初的 Taskfile 并不支持 version: 关键字,因为 YAML 文档中的根属性都是 task。 就像这样:

echo:
cmds:
- echo "Hello, World!"

变量的优先级也不同:

  1. 调用变量
  2. 环境变量
  3. Task 变量
  4. Taskvars.yml 定义变量

版本 2.0

到了 2.0 版本,我们引入了 version: 字段, 在不破坏已存在的 Taskfiles 的前提下,在 Task 中引入新功能。 新语法如下:

version: '2'

tasks:
echo:
cmds:
- echo "Hello, World!"

如果您不想创建 Taskvars.yml,版本 2 允许您直接在任务文件中写入全局变量:

version: '2'

vars:
GREETING: Hello, World!

tasks:
greet:
cmds:
- echo "{{.GREETING}}"

变量的优先级调整为:

  1. Task 变量
  2. 调用变量
  3. Taskfile 定义变量
  4. Taskvars 文件定义变量
  5. 环境变量

添加了一个新的全局配置项来配置变量扩展的数量(默认为 2):

version: '2'

expansions: 3

vars:
FOO: foo
BAR: bar
BAZ: baz
FOOBAR: "{{.FOO}}{{.BAR}}"
FOOBARBAZ: "{{.FOOBAR}}{{.BAZ}}"

tasks:
default:
cmds:
- echo "{{.FOOBARBAZ}}"

版本 2.1

2.1 版包括一个全局 output 选项,以允许更好地控制如何将命令输出打印到控制台(有关更多信息,请参阅 文档):

version: '2'

output: prefixed

tasks:
server:
cmds:
- go run main.go
prefix: server

从这个版本开始,也可以忽略命令或 task 的错误(在 此处 查看文档):

version: '2'

tasks:
example-1:
cmds:
- cmd: exit 1
ignore_error: true
- echo "This will be print"

example-2:
cmds:
- exit 1
- echo "This will be print"
ignore_error: true

版本 2.2

2.2 版带有全局 includes 选项来包含其他 Taskfiles:

version: '2'

includes:
docs: ./documentation # will look for ./documentation/Taskfile.yml
docker: ./DockerTasks.yml

版本 2.6

2.6 版本增加任务的先决条件字段 preconditions

version: '2'

tasks:
upload_environment:
preconditions:
- test -f .env
cmds:
- aws s3 cp .env s3://myenvironment

请检查 文档

版本 3

以下是 v3 所做的一些主要变更:

  • Task 的日志使用彩色输出
  • 支持类 .env 文件
  • 添加 label: 设置后可以覆盖任务名称在日志中的显示方式
  • 添加了全局 method: 允许设置默认方法,Task 的默认值更改为 checksum
  • 使用 status:: CHECKSUMTIMESTAMP 时新增了两个魔术变量,分别包含 sources: 列出的文件的 md5 checksum 和最大修改时间戳
  • 另外,TASK 变量总是可以使用当前的任务名称
  • CLI 变量始终被视为全局变量
  • includes 添加了 dir: 选项,以允许选择包含的任务文件将在哪个目录上运行:
includes:
docs:
taskfile: ./docs
dir: ./docs
  • 实现短任务语法。 以下所有语法都是等效的:
version: '3'

tasks:
print:
cmds:
- echo "Hello, World!"
version: '3'

tasks:
print:
- echo "Hello, World!"
version: '3'

tasks:
print: echo "Hello, World!"
  • 对变量的处理方式进行了重大重构。 现在它们更容易理解了。 expansions: 设置被删除了,因为它变得不必要。 这是 Task 处理变量的顺序,每一层都可以看到前一层设置的变量并覆盖这些变量。
    • 环境变量
    • 全局或 CLI 变量
    • 调用变量
    • Task 内的变量
- + \ No newline at end of file diff --git a/zh-Hans/translate/index.html b/zh-Hans/translate/index.html index 79c5d613..bbce5f7d 100644 --- a/zh-Hans/translate/index.html +++ b/zh-Hans/translate/index.html @@ -10,13 +10,13 @@ - +

翻译

想帮助我们翻译此文档吗? 在本文档中,我们解释了如何解决这一问题。

不要直接在 GitHub 存储库上编辑翻译后的 markdown 文件! 我们使用 Crowdin 来允许贡献者进行翻译工作。 存储库会根据 Crowdin 的进展定期更新。

如果您想访问 Crowdin 项目以提供翻译建议,请在 我们的 Discord 服务器上的 #translations 频道 上申请访问权限。 如果给定的语言尚未显示给 Crowdin,请询问,我们可以对其进行配置。

- + \ No newline at end of file diff --git a/zh-Hans/usage/index.html b/zh-Hans/usage/index.html index 922ffc86..0f08bc7a 100644 --- a/zh-Hans/usage/index.html +++ b/zh-Hans/usage/index.html @@ -10,13 +10,13 @@ - +
-

使用指南

快速入门

在项目的根目录中创建一个名为 Taskfile.yml 的文件。 cmds 属性应包含 task 的命令。 下面的示例允许编译 Go 应用程序并使用 esbuild 将多个 CSS 文件合并并缩小为一个文件。

version: '3'

tasks:
build:
cmds:
- go build -v -i main.go

assets:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

运行任务就这样简单:

task assets build

Task uses mvdan.cc/sh, a native Go sh interpreter. So you can write sh/bash commands, and it will work even on Windows, where sh or bash are usually not available. Just remember any executable called must be available by the OS or in PATH.

If you omit a task name, "default" will be assumed.

支持的文件名称

Task 会按以下顺序查找配置文件:

  • Taskfile.yml
  • Taskfile.yaml
  • Taskfile.dist.yml
  • Taskfile.dist.yaml

The intention of having the .dist variants is to allow projects to have one committed version (.dist) while still allowing individual users to override the Taskfile by adding an additional Taskfile.yml (which would be on .gitignore).

从子目录运行 Taskfile

If a Taskfile cannot be found in the current working directory, it will walk up the file tree until it finds one (similar to how git works). When running Task from a subdirectory like this, it will behave as if you ran it from the directory containing the Taskfile.

You can use this functionality along with the special {{.USER_WORKING_DIR}} variable to create some very useful reusable tasks. For example, if you have a monorepo with directories for each microservice, you can cd into a microservice directory and run a task command to bring it up without having to create multiple tasks or Taskfiles with identical content. For example:

version: '3'

tasks:
up:
dir: '{{.USER_WORKING_DIR}}'
preconditions:
- test -f docker-compose.yml
cmds:
- docker-compose up -d

In this example, we can run cd <service> and task up and as long as the <service> directory contains a docker-compose.yml, the Docker composition will be brought up.

运行全局 Taskfile

If you call Task with the --global (alias -g) flag, it will look for your home directory instead of your working directory. In short, Task will look for a Taskfile on either $HOME/Taskfile.yml or $HOME/Taskfile.yaml paths.

This is useful to have automation that you can run from anywhere in your system!

信息

When running your global Taskfile with -g, tasks will run on $HOME by default, and not on your working directory!

As mentioned in the previous section, the {{.USER_WORKING_DIR}} special variable can be very handy here to run stuff on the directory you're calling task -g from.

version: '3'

tasks:
from-home:
cmds:
- pwd

from-working-directory:
dir: '{{.USER_WORKING_DIR}}'
cmds:
- pwd

环境变量

Task

你可以使用 env 给每个 task 设置自定义环境变量:

version: '3'

tasks:
greet:
cmds:
- echo $GREETING
env:
GREETING: Hey, there!

Additionally, you can set global environment variables that will be available to all tasks:

version: '3'

env:
GREETING: Hey, there!

tasks:
greet:
cmds:
- echo $GREETING
信息

env supports expansion and retrieving output from a shell command just like variables, as you can see in the Variables section.

.env 文件

You can also ask Task to include .env like files by using the dotenv: setting:

.env
KEYNAME=VALUE
testing/.env
ENDPOINT=testing.com
Taskfile.yml
version: '3'

env:
ENV: testing

dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']

tasks:
greet:
cmds:
- echo "Using $KEYNAME and endpoint $ENDPOINT"

也可以在任务级指定 .env 文件:

version: '3'

env:
ENV: testing

tasks:
greet:
dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']
cmds:
- echo "Using $KEYNAME and endpoint $ENDPOINT"

Environment variables specified explicitly at the task-level will override variables defined in dotfiles:

version: '3'

env:
ENV: testing

tasks:
greet:
dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']
env:
KEYNAME: DIFFERENT_VALUE
cmds:
- echo "Using $KEYNAME and endpoint $ENDPOINT"
信息

请注意,您目前无法在包含的 Taskfile 中使用 dotenv 键。

包含其他 Taskfile

If you want to share tasks between different projects (Taskfiles), you can use the importing mechanism to include other Taskfiles using the includes keyword:

version: '3'

includes:
docs: ./documentation # will look for ./documentation/Taskfile.yml
docker: ./DockerTasks.yml

The tasks described in the given Taskfiles will be available with the informed namespace. So, you'd call task docs:serve to run the serve task from documentation/Taskfile.yml or task docker:build to run the build task from the DockerTasks.yml file.

Relative paths are resolved relative to the directory containing the including Taskfile.

操作系统特定 Taskfile

With version: '2', task automatically includes any Taskfile_{{OS}}.yml if it exists (for example: Taskfile_windows.yml, Taskfile_linux.yml or Taskfile_darwin.yml). Since this behavior was a bit too implicit, it was removed on version 3, but you still can have a similar behavior by explicitly importing these files:

version: '3'

includes:
build: ./Taskfile_{{OS}}.yml

包含 Taskfile 的目录

By default, included Taskfile's tasks are run in the current directory, even if the Taskfile is in another directory, but you can force its tasks to run in another directory by using this alternative syntax:

version: '3'

includes:
docs:
taskfile: ./docs/Taskfile.yml
dir: ./docs
信息

The included Taskfiles must be using the same schema version as the main Taskfile uses.

可选 includes

Includes marked as optional will allow Task to continue execution as normal if the included file is missing.

version: '3'

includes:
tests:
taskfile: ./tests/Taskfile.yml
optional: true

tasks:
greet:
cmds:
- echo "This command can still be successfully executed if ./tests/Taskfile.yml does not exist"

内部 includes

Includes marked as internal will set all the tasks of the included file to be internal as well (see the Internal tasks section below). This is useful when including utility tasks that are not intended to be used directly by the user.

version: '3'

includes:
tests:
taskfile: ./taskfiles/Utils.yml
internal: true

包含的 Taskfile 的变量

You can also specify variables when including a Taskfile. This may be useful for having reusable Taskfile that can be tweaked or even included more than once:

version: '3'

includes:
backend:
taskfile: ./taskfiles/Docker.yml
vars:
DOCKER_IMAGE: backend_image

frontend:
taskfile: ./taskfiles/Docker.yml
vars:
DOCKER_IMAGE: frontend_image

命名空间别名

When including a Taskfile, you can give the namespace a list of aliases. This works in the same way as task aliases and can be used together to create shorter and easier-to-type commands.

version: '3'

includes:
generate:
taskfile: ./taskfiles/Generate.yml
aliases: [gen]
信息

Vars declared in the included Taskfile have preference over the variables in the including Taskfile! If you want a variable in an included Taskfile to be overridable, use the default function: MY_VAR: '{{.MY_VAR | default "my-default-value"}}'.

内部 tasks

Internal tasks are tasks that cannot be called directly by the user. They will not appear in the output when running task --list|--list-all. Other tasks may call internal tasks in the usual way. This is useful for creating reusable, function-like tasks that have no useful purpose on the command line.

version: '3'

tasks:
build-image-1:
cmds:
- task: build-image
vars:
DOCKER_IMAGE: image-1

build-image:
internal: true
cmds:
- docker build -t {{.DOCKER_IMAGE}} .

Task 目录

By default, tasks will be executed in the directory where the Taskfile is located. But you can easily make the task run in another folder, informing dir:

version: '3'

tasks:
serve:
dir: public/www
cmds:
# run http server
- caddy

If the directory does not exist, task creates it.

Task 依赖

Dependencies run in parallel, so dependencies of a task should not depend one another. If you want to force tasks to run serially, take a look at the Calling Another Task section below.

You may have tasks that depend on others. Just pointing them on deps will make them run automatically before running the parent task:

version: '3'

tasks:
build:
deps: [assets]
cmds:
- go build -v -i main.go

assets:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

In the above example, assets will always run right before build if you run task build.

A task can have only dependencies and no commands to group tasks together:

version: '3'

tasks:
assets:
deps: [js, css]

js:
cmds:
- esbuild --bundle --minify js/index.js > public/bundle.js

css:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

If there is more than one dependency, they always run in parallel for better performance.

提示

You can also make the tasks given by the command line run in parallel by using the --parallel flag (alias -p). Example: task --parallel js css.

If you want to pass information to dependencies, you can do that the same manner as you would to call another task:

version: '3'

tasks:
default:
deps:
- task: echo_sth
vars: {TEXT: "before 1"}
- task: echo_sth
vars: {TEXT: "before 2"}
cmds:
- echo "after"

echo_sth:
cmds:
- echo {{.TEXT}}

平台特定的 tasks 和 cmds

If you want to restrict the running of tasks to explicit platforms, this can be achieved using the platforms: key. Tasks can be restricted to a specific OS, architecture or a combination of both. On a mismatch, the task or command will be skipped, and no error will be thrown.

The values allowed as OS or Arch are valid GOOS and GOARCH values, as defined by the Go language here.

The build-windows task below will run only on Windows, and on any architecture:

version: '3'

tasks:
build-windows:
platforms: [windows]
cmds:
- echo 'Running command on Windows'

This can be restricted to a specific architecture as follows:

version: '3'

tasks:
build-windows-amd64:
platforms: [windows/amd64]
cmds:
- echo 'Running command on Windows (amd64)'

It is also possible to restrict the task to specific architectures:

version: '3'

tasks:
build-amd64:
platforms: [amd64]
cmds:
- echo 'Running command on amd64'

Multiple platforms can be specified as follows:

version: '3'

tasks:
build:
platforms: [windows/amd64, darwin]
cmds:
- echo 'Running command on Windows (amd64) and macOS'

Individual commands can also be restricted to specific platforms:

version: '3'

tasks:
build:
cmds:
- cmd: echo 'Running command on Windows (amd64) and macOS'
platforms: [windows/amd64, darwin]
- cmd: echo 'Running on all platforms'

调用另一个 task

When a task has many dependencies, they are executed concurrently. This will often result in a faster build pipeline. However, in some situations, you may need to call other tasks serially. In this case, use the following syntax:

version: '3'

tasks:
main-task:
cmds:
- task: task-to-be-called
- task: another-task
- echo "Both done"

task-to-be-called:
cmds:
- echo "Task to be called"

another-task:
cmds:
- echo "Another task"

Overriding variables in the called task is as simple as informing vars attribute:

version: '3'

tasks:
greet:
vars:
RECIPIENT: '{{default "World" .RECIPIENT}}'
cmds:
- echo "Hello, {{.RECIPIENT}}!"

greet-pessimistically:
cmds:
- task: greet
vars: {RECIPIENT: "Cruel World"}

The above syntax is also supported in deps.

提示

NOTE: If you want to call a task declared in the root Taskfile from within an included Taskfile, add a leading : like this: task: :task-name.

减少不必要的工作

通过指纹识别本地生成的文件及其来源

If a task generates something, you can inform Task the source and generated files, so Task will prevent running them if not necessary.

version: '3'

tasks:
build:
deps: [js, css]
cmds:
- go build -v -i main.go

js:
cmds:
- esbuild --bundle --minify js/index.js > public/bundle.js
sources:
- src/js/**/*.js
generates:
- public/bundle.js

css:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css
sources:
- src/css/**/*.css
generates:
- public/bundle.css

sources and generates can be files or file patterns. When given, Task will compare the checksum of the source files to determine if it's necessary to run the task. If not, it will just print a message like Task "js" is up to date.

If you prefer this check to be made by the modification timestamp of the files, instead of its checksum (content), just set the method property to timestamp.

version: '3'

tasks:
build:
cmds:
- go build .
sources:
- ./*.go
generates:
- app{{exeExt}}
method: timestamp

In situations where you need more flexibility the status keyword can be used. You can even combine the two. See the documentation for status for an example.

信息

By default, task stores checksums on a local .task directory in the project's directory. Most of the time, you'll want to have this directory on .gitignore (or equivalent) so it isn't committed. (If you have a task for code generation that is committed it may make sense to commit the checksum of that task as well, though).

If you want these files to be stored in another directory, you can set a TASK_TEMP_DIR environment variable in your machine. It can contain a relative path like tmp/task that will be interpreted as relative to the project directory, or an absolute or home path like /tmp/.task or ~/.task (subdirectories will be created for each project).

export TASK_TEMP_DIR='~/.task'
信息

Each task has only one checksum stored for its sources. If you want to distinguish a task by any of its input variables, you can add those variables as part of the task's label, and it will be considered a different task.

This is useful if you want to run a task once for each distinct set of inputs until the sources actually change. For example, if the sources depend on the value of a variable, or you if you want the task to rerun if some arguments change even if the source has not.

提示

The method none skips any validation and always run the task.

信息

For the checksum (default) or timestamp method to work, it is only necessary to inform the source files. When the timestamp method is used, the last time of the running the task is considered as a generate.

使用程序检查来表示任务是最新的。

Alternatively, you can inform a sequence of tests as status. If no error is returned (exit status 0), the task is considered up-to-date:

version: '3'

tasks:
generate-files:
cmds:
- mkdir directory
- touch directory/file1.txt
- touch directory/file2.txt
# test existence of files
status:
- test -d directory
- test -f directory/file1.txt
- test -f directory/file2.txt

Normally, you would use sources in combination with generates - but for tasks that generate remote artifacts (Docker images, deploys, CD releases) the checksum source and timestamps require either access to the artifact or for an out-of-band refresh of the .checksum fingerprint file.

Two special variables {{.CHECKSUM}} and {{.TIMESTAMP}} are available for interpolation within status commands, depending on the method assigned to fingerprint the sources. Only source globs are fingerprinted.

Note that the {{.TIMESTAMP}} variable is a "live" Go time.Time struct, and can be formatted using any of the methods that time.Time responds to.

See the Go Time documentation for more information.

You can use --force or -f if you want to force a task to run even when up-to-date.

Also, task --status [tasks]... will exit with a non-zero exit code if any of the tasks are not up-to-date.

status can be combined with the fingerprinting to have a task run if either the the source/generated artifacts changes, or the programmatic check fails:

version: '3'

tasks:
build:prod:
desc: Build for production usage.
cmds:
- composer install
# Run this task if source files changes.
sources:
- composer.json
- composer.lock
generates:
- ./vendor/composer/installed.json
- ./vendor/autoload.php
# But also run the task if the last build was not a production build.
status:
- grep -q '"dev": false' ./vendor/composer/installed.json

使用程序检查取消任务及其依赖项的执行

In addition to status checks, preconditions checks are the logical inverse of status checks. That is, if you need a certain set of conditions to be true you can use the preconditions stanza. preconditions are similar to status lines, except they support sh expansion, and they SHOULD all return 0.

version: '3'

tasks:
generate-files:
cmds:
- mkdir directory
- touch directory/file1.txt
- touch directory/file2.txt
# test existence of files
preconditions:
- test -f .env
- sh: "[ 1 = 0 ]"
msg: "One doesn't equal Zero, Halting"

Preconditions can set specific failure messages that can tell a user what steps to take using the msg field.

If a task has a dependency on a sub-task with a precondition, and that precondition is not met - the calling task will fail. Note that a task executed with a failing precondition will not run unless --force is given.

Unlike status, which will skip a task if it is up to date and continue executing tasks that depend on it, a precondition will fail a task, along with any other tasks that depend on it.

version: '3'

tasks:
task-will-fail:
preconditions:
- sh: "exit 1"

task-will-also-fail:
deps:
- task-will-fail

task-will-still-fail:
cmds:
- task: task-will-fail
- echo "I will not run"

在任务运行时限制

If a task executed by multiple cmds or multiple deps you can control when it is executed using run. run can also be set at the root of the Taskfile to change the behavior of all the tasks unless explicitly overridden.

Supported values for run:

  • always (default) always attempt to invoke the task regardless of the number of previous executions
  • once only invoke this task once regardless of the number of references
  • when_changed only invokes the task once for each unique set of variables passed into the task
version: '3'

tasks:
default:
cmds:
- task: generate-file
vars: { CONTENT: '1' }
- task: generate-file
vars: { CONTENT: '2' }
- task: generate-file
vars: { CONTENT: '2' }

generate-file:
run: when_changed
deps:
- install-deps
cmds:
- echo {{.CONTENT}}

install-deps:
run: once
cmds:
- sleep 5 # long operation like installing packages

变量

When doing interpolation of variables, Task will look for the below. They are listed below in order of importance (i.e. most important first):

  • Variables declared in the task definition
  • Variables given while calling a task from another (See Calling another task above)
  • Variables of the included Taskfile (when the task is included)
  • Variables of the inclusion of the Taskfile (when the task is included)
  • Global variables (those declared in the vars: option in the Taskfile)
  • Environment variables

Example of sending parameters with environment variables:

$ TASK_VARIABLE=a-value task do-something
提示

A special variable .TASK is always available containing the task name.

Since some shells do not support the above syntax to set environment variables (Windows) tasks also accept a similar style when not at the beginning of the command.

$ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!"

Example of locally declared vars:

version: '3'

tasks:
print-var:
cmds:
- echo "{{.VAR}}"
vars:
VAR: Hello!

Example of global vars in a Taskfile.yml:

version: '3'

vars:
GREETING: Hello from Taskfile!

tasks:
greet:
cmds:
- echo "{{.GREETING}}"

动态变量

The below syntax (sh: prop in a variable) is considered a dynamic variable. The value will be treated as a command and the output assigned. If there are one or more trailing newlines, the last newline will be trimmed.

version: '3'

tasks:
build:
cmds:
- go build -ldflags="-X main.Version={{.GIT_COMMIT}}" main.go
vars:
GIT_COMMIT:
sh: git log -n 1 --format=%h

This works for all types of variables.

将 CLI 参数转发到 cmds

If -- is given in the CLI, all following parameters are added to a special .CLI_ARGS variable. This is useful to forward arguments to another command.

The below example will run yarn install.

$ task yarn -- install
version: '3'

tasks:
yarn:
cmds:
- yarn {{.CLI_ARGS}}

使用 defer 做 task 清理

With the defer keyword, it's possible to schedule cleanup to be run once the task finishes. The difference with just putting it as the last command is that this command will run even when the task fails.

In the example below, rm -rf tmpdir/ will run even if the third command fails:

version: '3'

tasks:
default:
cmds:
- mkdir -p tmpdir/
- defer: rm -rf tmpdir/
- echo 'Do work on tmpdir/'

If you want to move the cleanup command into another task, that is possible as well:

version: '3'

tasks:
default:
cmds:
- mkdir -p tmpdir/
- defer: { task: cleanup }
- echo 'Do work on tmpdir/'

cleanup: rm -rf tmpdir/
信息

Due to the nature of how the Go's own defer work, the deferred commands are executed in the reverse order if you schedule multiple of them.

Go 的模板引擎

Task parse commands as Go's template engine before executing them. Variables are accessible through dot syntax (.VARNAME).

All functions by the Go's slim-sprig lib are available. The following example gets the current date in a given format:

version: '3'

tasks:
print-date:
cmds:
- echo {{now | date "2006-01-02"}}

Task also adds the following functions:

  • OS: Returns the operating system. Possible values are "windows", "linux", "darwin" (macOS) and "freebsd".
  • ARCH: return the architecture Task was compiled to: "386", "amd64", "arm" or "s390x".
  • splitLines: Splits Unix (\n) and Windows (\r\n) styled newlines.
  • catLines: Replaces Unix (\n) and Windows (\r\n) styled newlines with a space.
  • toSlash: Does nothing on Unix, but on Windows converts a string from \ path format to /.
  • fromSlash: Opposite of toSlash. Does nothing on Unix, but on Windows converts a string from / path format to \.
  • exeExt: Returns the right executable extension for the current OS (".exe" for Windows, "" for others).
  • shellQuote: Quotes a string to make it safe for use in shell scripts. Task uses this Go function for this. The Bash dialect is assumed.
  • splitArgs: Splits a string as if it were a command's arguments. Task uses this Go function

Example:

version: '3'

tasks:
print-os:
cmds:
- echo '{{OS}} {{ARCH}}'
- echo '{{if eq OS "windows"}}windows-command{{else}}unix-command{{end}}'
# This will be path/to/file on Unix but path\to\file on Windows
- echo '{{fromSlash "path/to/file"}}'
enumerated-file:
vars:
CONTENT: |
foo
bar
cmds:
- |
cat << EOF > output.txt
{{range $i, $line := .CONTENT | splitLines -}}
{{printf "%3d" $i}}: {{$line}}
{{end}}EOF

帮助

Running task --list (or task -l) lists all tasks with a description. The following Taskfile:

version: '3'

tasks:
build:
desc: Build the go binary.
cmds:
- go build -v -i main.go

test:
desc: Run all the go tests.
cmds:
- go test -race ./...

js:
cmds:
- esbuild --bundle --minify js/index.js > public/bundle.js

css:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

would print the following output:

* build:   Build the go binary.
* test: Run all the go tests.

If you want to see all tasks, there's a --list-all (alias -a) flag as well.

显示任务摘要

Running task --summary task-name will show a summary of a task. The following Taskfile:

version: '3'

tasks:
release:
deps: [build]
summary: |
Release your project to github

It will build your project before starting the release.
Please make sure that you have set GITHUB_TOKEN before starting.
cmds:
- your-release-tool

build:
cmds:
- your-build-tool

with running task --summary release would print the following output:

task: release

Release your project to github

It will build your project before starting the release.
Please make sure that you have set GITHUB_TOKEN before starting.

dependencies:
- build

commands:
- your-release-tool

If a summary is missing, the description will be printed. If the task does not have a summary or a description, a warning is printed.

Please note: showing the summary will not execute the command.

Task 别名

Aliases are alternative names for tasks. They can be used to make it easier and quicker to run tasks with long or hard-to-type names. You can use them on the command line, when calling sub-tasks in your Taskfile and when including tasks with aliases from another Taskfile. They can also be used together with namespace aliases.

version: '3'

tasks:
generate:
aliases: [gen]
cmds:
- task: gen-mocks

generate-mocks:
aliases: [gen-mocks]
cmds:
- echo "generating..."

重写 Task 名称

Sometimes you may want to override the task name printed on the summary, up-to-date messages to STDOUT, etc. In this case, you can just set label:, which can also be interpolated with variables:

version: '3'

tasks:
default:
- task: print
vars:
MESSAGE: hello
- task: print
vars:
MESSAGE: world

print:
label: 'print-{{.MESSAGE}}'
cmds:
- echo "{{.MESSAGE}}"

静默模式

Silent mode disables the echoing of commands before Task runs it. For the following Taskfile:

version: '3'

tasks:
echo:
cmds:
- echo "Print something"

Normally this will be printed:

echo "Print something"
Print something

With silent mode on, the below will be printed instead:

Print something

There are four ways to enable silent mode:

  • At command level:
version: '3'

tasks:
echo:
cmds:
- cmd: echo "Print something"
silent: true
  • At task level:
version: '3'

tasks:
echo:
cmds:
- echo "Print something"
silent: true
  • Globally at Taskfile level:
version: '3'

silent: true

tasks:
echo:
cmds:
- echo "Print something"
  • Or globally with --silent or -s flag

If you want to suppress STDOUT instead, just redirect a command to /dev/null:

version: '3'

tasks:
echo:
cmds:
- echo "This will print nothing" > /dev/null

试运行模式

Dry run mode (--dry) compiles and steps through each task, printing the commands that would be run without executing them. This is useful for debugging your Taskfiles.

忽略错误

You have the option to ignore errors during command execution. Given the following Taskfile:

version: '3'

tasks:
echo:
cmds:
- exit 1
- echo "Hello World"

Task will abort the execution after running exit 1 because the status code 1 stands for EXIT_FAILURE. However, it is possible to continue with execution using ignore_error:

version: '3'

tasks:
echo:
cmds:
- cmd: exit 1
ignore_error: true
- echo "Hello World"

ignore_error can also be set for a task, which means errors will be suppressed for all commands. Nevertheless, keep in mind that this option will not propagate to other tasks called either by deps or cmds!

输出语法

By default, Task just redirects the STDOUT and STDERR of the running commands to the shell in real-time. This is good for having live feedback for logging printed by commands, but the output can become messy if you have multiple commands running simultaneously and printing lots of stuff.

To make this more customizable, there are currently three different output options you can choose:

  • interleaved (default)
  • group
  • prefixed

To choose another one, just set it to root in the Taskfile:

version: '3'

output: 'group'

tasks:
# ...

The group output will print the entire output of a command once after it finishes, so you will not have live feedback for commands that take a long time to run.

When using the group output, you can optionally provide a templated message to print at the start and end of the group. This can be useful for instructing CI systems to group all of the output for a given task, such as with GitHub Actions' ::group:: command or Azure Pipelines.

version: '3'

output:
group:
begin: '::group::{{.TASK}}'
end: '::endgroup::'

tasks:
default:
cmds:
- echo 'Hello, World!'
silent: true
$ task default
::group::default
Hello, World!
::endgroup::

When using the group output, you may swallow the output of the executed command on standard output and standard error if it does not fail (zero exit code).

version: '3'

silent: true

output:
group:
error_only: true

tasks:
passes: echo 'output-of-passes'
errors: echo 'output-of-errors' && exit 1
$ task passes
$ task errors
output-of-errors
task: Failed to run task "errors": exit status 1

The prefix output will prefix every line printed by a command with [task-name] as the prefix, but you can customize the prefix for a command with the prefix: attribute:

version: '3'

output: prefixed

tasks:
default:
deps:
- task: print
vars: {TEXT: foo}
- task: print
vars: {TEXT: bar}
- task: print
vars: {TEXT: baz}

print:
cmds:
- echo "{{.TEXT}}"
prefix: "print-{{.TEXT}}"
silent: true
$ task default
[print-foo] foo
[print-bar] bar
[print-baz] baz
提示

The output option can also be specified by the --output or -o flags.

交互式 CLI 应用

When running interactive CLI applications inside Task they can sometimes behave weirdly, especially when the output mode is set to something other than interleaved (the default), or when interactive apps are run in parallel with other tasks.

The interactive: true tells Task this is an interactive application and Task will try to optimize for it:

version: '3'

tasks:
default:
cmds:
- vim my-file.txt
interactive: true

If you still have problems running an interactive app through Task, please open an issue about it.

短 Task 语法

Starting on Task v3, you can now write tasks with a shorter syntax if they have the default settings (e.g. no custom env:, vars:, desc:, silent: , etc):

version: '3'

tasks:
build: go build -v -o ./app{{exeExt}} .

run:
- task: build
- ./app{{exeExt}} -h localhost -p 8080

setshopt

It's possible to specify options to the set and shopt builtins. This can be added at global, task or command level.

version: '3'

set: [pipefail]
shopt: [globstar]

tasks:
# `globstar` required for double star globs to work
default: echo **/*.go
信息

Keep in mind that not all options are available in the shell interpreter library that Task uses.

观察任务

With the flags --watch or -w task will watch for file changes and run the task again. This requires the sources attribute to be given, so task knows which files to watch.

The default watch interval is 5 seconds, but it's possible to change it by either setting interval: '500ms' in the root of the Taskfile passing it as an argument like --interval=500ms.

- +

使用指南

快速入门

在项目的根目录中创建一个名为 Taskfile.yml 的文件。 cmds 属性应包含 task 的命令。 下面的示例允许编译 Go 应用程序并使用 esbuild 将多个 CSS 文件合并并缩小为一个文件。

version: '3'

tasks:
build:
cmds:
- go build -v -i main.go

assets:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

运行 task 就这样简单:

task assets build

Task 使用 mvdan.cc/sh,一个原生的 Go sh 解释器。 因此,您可以编写 sh/bash 命令,它甚至可以在 Windows 上运行,而 shbash 通常不可用。 请记住,任何被调用的可执行文件都必须在操作系统或 PATH 中可用。

如果不传 task 的名字,默认会调用 "default"。

支持的文件名称

Task 会按以下顺序查找配置文件:

  • Taskfile.yml
  • Taskfile.yaml
  • Taskfile.dist.yml
  • Taskfile.dist.yaml

使用 .dist 变体的目的是允许项目有一个提交版本 (.dist),同时仍然允许个人用户通过添加额外的 Taskfile.yml(将在 .gitignore 上)来覆盖 Taskfile。

从子目录运行 Taskfile

如果在当前工作目录中找不到 Taskfile,它将沿着文件树向上查找,直到找到一个(类似于 git 的工作方式)。 当从这样的子目录运行 Task 时,它的行为就像从包含 Taskfile 的目录运行它一样。

您可以将此功能与特殊的 {{.USER_WORKING_DIR}} 变量一起使用来创建一些非常有用的可重用 task。 例如,如果你有一个包含每个微服务目录的 monorepo,你可以 cd 进入一个微服务目录并运行一个 task 命令来启动它,而不必创建多个 task 或具有相同内容的 Taskfile。 例如:

version: '3'

tasks:
up:
dir: '{{.USER_WORKING_DIR}}'
preconditions:
- test -f docker-compose.yml
cmds:
- docker-compose up -d

在此示例中,我们可以运行 cd <service>task up,只要 <service> 目录包含 docker-compose.yml,就会启动 Docker Compose。

运行全局 Taskfile

If you call Task with the --global (alias -g) flag, it will look for your home directory instead of your working directory. In short, Task will look for a Taskfile on either $HOME/Taskfile.yml or $HOME/Taskfile.yaml paths.

这对于您可以在系统的任何地方运行的自动化很有用!

信息

When running your global Taskfile with -g, tasks will run on $HOME by default, and not on your working directory!

As mentioned in the previous section, the {{.USER_WORKING_DIR}} special variable can be very handy here to run stuff on the directory you're calling task -g from.

version: '3'

tasks:
from-home:
cmds:
- pwd

from-working-directory:
dir: '{{.USER_WORKING_DIR}}'
cmds:
- pwd

环境变量

Task

你可以使用 env 给每个 task 设置自定义环境变量:

version: '3'

tasks:
greet:
cmds:
- echo $GREETING
env:
GREETING: Hey, there!

此外,您可以设置可用于所有 task 的全局环境变量:

version: '3'

env:
GREETING: Hey, there!

tasks:
greet:
cmds:
- echo $GREETING
信息

env 支持扩展和检索 shell 命令的输出,就像变量一样,如您在 变量 部分中看到的那样。

.env 文件

您还可以使用 dotenv: 设置要求 tasks 包含 .env 之类的文件

.env
KEYNAME=VALUE
testing/.env
ENDPOINT=testing.com
Taskfile.yml
version: '3'

env:
ENV: testing

dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']

tasks:
greet:
cmds:
- echo "Using $KEYNAME and endpoint $ENDPOINT"

也可以在 task 级别指定 .env 文件:

version: '3'

env:
ENV: testing

tasks:
greet:
dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']
cmds:
- echo "Using $KEYNAME and endpoint $ENDPOINT"

在 task 级别明确指定的环境变量将覆盖点文件中定义的变量:

version: '3'

env:
ENV: testing

tasks:
greet:
dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']
env:
KEYNAME: DIFFERENT_VALUE
cmds:
- echo "Using $KEYNAME and endpoint $ENDPOINT"
信息

请注意,您目前无法在包含的 Taskfile 中使用 dotenv 键。

包含其他 Taskfile

如果要在不同项目(Taskfile)之间共享任务,可以使用导入机制使用 includes 关键字包含其他任务文件:

version: '3'

includes:
docs: ./documentation # will look for ./documentation/Taskfile.yml
docker: ./DockerTasks.yml

The tasks described in the given Taskfiles will be available with the informed namespace. So, you'd call task docs:serve to run the serve task from documentation/Taskfile.yml or task docker:build to run the build task from the DockerTasks.yml file.

相对路径是相对于包含包含 Taskfile 的目录解析的。

操作系统特定 Taskfile

With version: '2', task automatically includes any Taskfile_{{OS}}.yml if it exists (for example: Taskfile_windows.yml, Taskfile_linux.yml or Taskfile_darwin.yml). Since this behavior was a bit too implicit, it was removed on version 3, but you still can have a similar behavior by explicitly importing these files:

version: '3'

includes:
build: ./Taskfile_{{OS}}.yml

包含 Taskfile 的目录

默认情况下,包含的 Taskfile 的 task 在当前目录中运行,即使 Taskfile 在另一个目录中,但您可以使用以下替代语法强制其 task 在另一个目录中运行:

version: '3'

includes:
docs:
taskfile: ./docs/Taskfile.yml
dir: ./docs
信息

包含的 Taskfile 必须使用与主 Taskfile 使用的相同规则版本。

可选 includes

如果包含文件丢失,标记为可选的包含将允许 task 继续正常执行。

version: '3'

includes:
tests:
taskfile: ./tests/Taskfile.yml
optional: true

tasks:
greet:
cmds:
- echo "This command can still be successfully executed if ./tests/Taskfile.yml does not exist"

内部 includes

Includes marked as internal will set all the tasks of the included file to be internal as well (see the Internal tasks section below). This is useful when including utility tasks that are not intended to be used directly by the user.

version: '3'

includes:
tests:
taskfile: ./taskfiles/Utils.yml
internal: true

包含的 Taskfile 的变量

您还可以在包含 Taskfile 时指定变量。 这对于拥有可以调整甚至多次包含的可重用 Taskfile 可能很有用:

version: '3'

includes:
backend:
taskfile: ./taskfiles/Docker.yml
vars:
DOCKER_IMAGE: backend_image

frontend:
taskfile: ./taskfiles/Docker.yml
vars:
DOCKER_IMAGE: frontend_image

命名空间别名

When including a Taskfile, you can give the namespace a list of aliases. This works in the same way as task aliases and can be used together to create shorter and easier-to-type commands.

version: '3'

includes:
generate:
taskfile: ./taskfiles/Generate.yml
aliases: [gen]
信息

Vars declared in the included Taskfile have preference over the variables in the including Taskfile! If you want a variable in an included Taskfile to be overridable, use the default function: MY_VAR: '{{.MY_VAR | default "my-default-value"}}'.

内部 tasks

Internal tasks are tasks that cannot be called directly by the user. They will not appear in the output when running task --list|--list-all. Other tasks may call internal tasks in the usual way. This is useful for creating reusable, function-like tasks that have no useful purpose on the command line.

version: '3'

tasks:
build-image-1:
cmds:
- task: build-image
vars:
DOCKER_IMAGE: image-1

build-image:
internal: true
cmds:
- docker build -t {{.DOCKER_IMAGE}} .

Task 目录

By default, tasks will be executed in the directory where the Taskfile is located. But you can easily make the task run in another folder, informing dir:

version: '3'

tasks:
serve:
dir: public/www
cmds:
# run http server
- caddy

如果该目录不存在,task 会创建它。

Task 依赖

Dependencies run in parallel, so dependencies of a task should not depend one another. If you want to force tasks to run serially, take a look at the Calling Another Task section below.

You may have tasks that depend on others. Just pointing them on deps will make them run automatically before running the parent task:

version: '3'

tasks:
build:
deps: [assets]
cmds:
- go build -v -i main.go

assets:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

In the above example, assets will always run right before build if you run task build.

一个任务只能有依赖关系,没有命令来将任务组合在一起:

version: '3'

tasks:
assets:
deps: [js, css]

js:
cmds:
- esbuild --bundle --minify js/index.js > public/bundle.js

css:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

如果有多个依赖项,它们总是并行运行以获得更好的性能。

提示

You can also make the tasks given by the command line run in parallel by using the --parallel flag (alias -p). Example: task --parallel js css.

如果你想将信息传递给依赖项,你可以像 调用另一个任务 一样以相同的方式进行:

version: '3'

tasks:
default:
deps:
- task: echo_sth
vars: {TEXT: "before 1"}
- task: echo_sth
vars: {TEXT: "before 2"}
cmds:
- echo "after"

echo_sth:
cmds:
- echo {{.TEXT}}

平台特定的 tasks 和 cmds

If you want to restrict the running of tasks to explicit platforms, this can be achieved using the platforms: key. Tasks can be restricted to a specific OS, architecture or a combination of both. On a mismatch, the task or command will be skipped, and no error will be thrown.

The values allowed as OS or Arch are valid GOOS and GOARCH values, as defined by the Go language here.

The build-windows task below will run only on Windows, and on any architecture:

version: '3'

tasks:
build-windows:
platforms: [windows]
cmds:
- echo 'Running command on Windows'

This can be restricted to a specific architecture as follows:

version: '3'

tasks:
build-windows-amd64:
platforms: [windows/amd64]
cmds:
- echo 'Running command on Windows (amd64)'

It is also possible to restrict the task to specific architectures:

version: '3'

tasks:
build-amd64:
platforms: [amd64]
cmds:
- echo 'Running command on amd64'

Multiple platforms can be specified as follows:

version: '3'

tasks:
build:
platforms: [windows/amd64, darwin]
cmds:
- echo 'Running command on Windows (amd64) and macOS'

Individual commands can also be restricted to specific platforms:

version: '3'

tasks:
build:
cmds:
- cmd: echo 'Running command on Windows (amd64) and macOS'
platforms: [windows/amd64, darwin]
- cmd: echo 'Running on all platforms'

调用另一个 task

当一个 task 有很多依赖时,它们是并发执行的。 这通常会导致更快的构建管道。 但是,在某些情况下,您可能需要串行调用其他 task。 在这种情况下,请使用以下语法:

version: '3'

tasks:
main-task:
cmds:
- task: task-to-be-called
- task: another-task
- echo "Both done"

task-to-be-called:
cmds:
- echo "Task to be called"

another-task:
cmds:
- echo "Another task"

在被调用 task 中覆盖变量就像通知 vars 属性一样简单:

version: '3'

tasks:
greet:
vars:
RECIPIENT: '{{default "World" .RECIPIENT}}'
cmds:
- echo "Hello, {{.RECIPIENT}}!"

greet-pessimistically:
cmds:
- task: greet
vars: {RECIPIENT: "Cruel World"}

deps 也支持上述语法。

提示

NOTE: If you want to call a task declared in the root Taskfile from within an included Taskfile, add a leading : like this: task: :task-name.

减少不必要的工作

通过指纹识别本地生成的文件及其来源

如果一个 task 生成了一些东西,你可以通知 task 源和生成的文件,这样 task 就会在不需要的时候阻止运行它们。

version: '3'

tasks:
build:
deps: [js, css]
cmds:
- go build -v -i main.go

js:
cmds:
- esbuild --bundle --minify js/index.js > public/bundle.js
sources:
- src/js/**/*.js
generates:
- public/bundle.js

css:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css
sources:
- src/css/**/*.css
generates:
- public/bundle.css

sources and generates can be files or file patterns. When given, Task will compare the checksum of the source files to determine if it's necessary to run the task. If not, it will just print a message like Task "js" is up to date.

If you prefer this check to be made by the modification timestamp of the files, instead of its checksum (content), just set the method property to timestamp.

version: '3'

tasks:
build:
cmds:
- go build .
sources:
- ./*.go
generates:
- app{{exeExt}}
method: timestamp

In situations where you need more flexibility the status keyword can be used. You can even combine the two. See the documentation for status for an example.

信息

By default, task stores checksums on a local .task directory in the project's directory. Most of the time, you'll want to have this directory on .gitignore (or equivalent) so it isn't committed. (If you have a task for code generation that is committed it may make sense to commit the checksum of that task as well, though).

If you want these files to be stored in another directory, you can set a TASK_TEMP_DIR environment variable in your machine. It can contain a relative path like tmp/task that will be interpreted as relative to the project directory, or an absolute or home path like /tmp/.task or ~/.task (subdirectories will be created for each project).

export TASK_TEMP_DIR='~/.task'
信息

Each task has only one checksum stored for its sources. If you want to distinguish a task by any of its input variables, you can add those variables as part of the task's label, and it will be considered a different task.

This is useful if you want to run a task once for each distinct set of inputs until the sources actually change. For example, if the sources depend on the value of a variable, or you if you want the task to rerun if some arguments change even if the source has not.

提示

The method none skips any validation and always run the task.

信息

For the checksum (default) or timestamp method to work, it is only necessary to inform the source files. When the timestamp method is used, the last time of the running the task is considered as a generate.

使用程序检查来表示任务是最新的。

Alternatively, you can inform a sequence of tests as status. If no error is returned (exit status 0), the task is considered up-to-date:

version: '3'

tasks:
generate-files:
cmds:
- mkdir directory
- touch directory/file1.txt
- touch directory/file2.txt
# test existence of files
status:
- test -d directory
- test -f directory/file1.txt
- test -f directory/file2.txt

Normally, you would use sources in combination with generates - but for tasks that generate remote artifacts (Docker images, deploys, CD releases) the checksum source and timestamps require either access to the artifact or for an out-of-band refresh of the .checksum fingerprint file.

Two special variables {{.CHECKSUM}} and {{.TIMESTAMP}} are available for interpolation within status commands, depending on the method assigned to fingerprint the sources. Only source globs are fingerprinted.

Note that the {{.TIMESTAMP}} variable is a "live" Go time.Time struct, and can be formatted using any of the methods that time.Time responds to.

有关详细信息,请参阅 Go Time 文档

You can use --force or -f if you want to force a task to run even when up-to-date.

Also, task --status [tasks]... will exit with a non-zero exit code if any of the tasks are not up-to-date.

status can be combined with the fingerprinting to have a task run if either the the source/generated artifacts changes, or the programmatic check fails:

version: '3'

tasks:
build:prod:
desc: Build for production usage.
cmds:
- composer install
# Run this task if source files changes.
sources:
- composer.json
- composer.lock
generates:
- ./vendor/composer/installed.json
- ./vendor/autoload.php
# But also run the task if the last build was not a production build.
status:
- grep -q '"dev": false' ./vendor/composer/installed.json

使用程序检查取消任务及其依赖项的执行

In addition to status checks, preconditions checks are the logical inverse of status checks. That is, if you need a certain set of conditions to be true you can use the preconditions stanza. preconditions are similar to status lines, except they support sh expansion, and they SHOULD all return 0.

version: '3'

tasks:
generate-files:
cmds:
- mkdir directory
- touch directory/file1.txt
- touch directory/file2.txt
# test existence of files
preconditions:
- test -f .env
- sh: "[ 1 = 0 ]"
msg: "One doesn't equal Zero, Halting"

Preconditions can set specific failure messages that can tell a user what steps to take using the msg field.

If a task has a dependency on a sub-task with a precondition, and that precondition is not met - the calling task will fail. Note that a task executed with a failing precondition will not run unless --force is given.

Unlike status, which will skip a task if it is up to date and continue executing tasks that depend on it, a precondition will fail a task, along with any other tasks that depend on it.

version: '3'

tasks:
task-will-fail:
preconditions:
- sh: "exit 1"

task-will-also-fail:
deps:
- task-will-fail

task-will-still-fail:
cmds:
- task: task-will-fail
- echo "I will not run"

在任务运行时限制

If a task executed by multiple cmds or multiple deps you can control when it is executed using run. run can also be set at the root of the Taskfile to change the behavior of all the tasks unless explicitly overridden.

Supported values for run:

  • always (default) always attempt to invoke the task regardless of the number of previous executions
  • once only invoke this task once regardless of the number of references
  • when_changed only invokes the task once for each unique set of variables passed into the task
version: '3'

tasks:
default:
cmds:
- task: generate-file
vars: { CONTENT: '1' }
- task: generate-file
vars: { CONTENT: '2' }
- task: generate-file
vars: { CONTENT: '2' }

generate-file:
run: when_changed
deps:
- install-deps
cmds:
- echo {{.CONTENT}}

install-deps:
run: once
cmds:
- sleep 5 # long operation like installing packages

变量

When doing interpolation of variables, Task will look for the below. They are listed below in order of importance (i.e. most important first):

  • Variables declared in the task definition
  • Variables given while calling a task from another (See Calling another task above)
  • Variables of the included Taskfile (when the task is included)
  • Variables of the inclusion of the Taskfile (when the task is included)
  • Global variables (those declared in the vars: option in the Taskfile)
  • Environment variables

Example of sending parameters with environment variables:

$ TASK_VARIABLE=a-value task do-something
提示

A special variable .TASK is always available containing the task name.

Since some shells do not support the above syntax to set environment variables (Windows) tasks also accept a similar style when not at the beginning of the command.

$ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!"

Example of locally declared vars:

version: '3'

tasks:
print-var:
cmds:
- echo "{{.VAR}}"
vars:
VAR: Hello!

Example of global vars in a Taskfile.yml:

version: '3'

vars:
GREETING: Hello from Taskfile!

tasks:
greet:
cmds:
- echo "{{.GREETING}}"

动态变量

The below syntax (sh: prop in a variable) is considered a dynamic variable. The value will be treated as a command and the output assigned. If there are one or more trailing newlines, the last newline will be trimmed.

version: '3'

tasks:
build:
cmds:
- go build -ldflags="-X main.Version={{.GIT_COMMIT}}" main.go
vars:
GIT_COMMIT:
sh: git log -n 1 --format=%h

This works for all types of variables.

将 CLI 参数转发到 cmds

If -- is given in the CLI, all following parameters are added to a special .CLI_ARGS variable. This is useful to forward arguments to another command.

The below example will run yarn install.

$ task yarn -- install
version: '3'

tasks:
yarn:
cmds:
- yarn {{.CLI_ARGS}}

使用 defer 做 task 清理

With the defer keyword, it's possible to schedule cleanup to be run once the task finishes. The difference with just putting it as the last command is that this command will run even when the task fails.

In the example below, rm -rf tmpdir/ will run even if the third command fails:

version: '3'

tasks:
default:
cmds:
- mkdir -p tmpdir/
- defer: rm -rf tmpdir/
- echo 'Do work on tmpdir/'

If you want to move the cleanup command into another task, that is possible as well:

version: '3'

tasks:
default:
cmds:
- mkdir -p tmpdir/
- defer: { task: cleanup }
- echo 'Do work on tmpdir/'

cleanup: rm -rf tmpdir/
信息

Due to the nature of how the Go's own defer work, the deferred commands are executed in the reverse order if you schedule multiple of them.

Go 的模板引擎

Task parse commands as Go's template engine before executing them. Variables are accessible through dot syntax (.VARNAME).

All functions by the Go's slim-sprig lib are available. The following example gets the current date in a given format:

version: '3'

tasks:
print-date:
cmds:
- echo {{now | date "2006-01-02"}}

Task also adds the following functions:

  • OS: Returns the operating system. Possible values are "windows", "linux", "darwin" (macOS) and "freebsd".
  • ARCH: return the architecture Task was compiled to: "386", "amd64", "arm" or "s390x".
  • splitLines: Splits Unix (\n) and Windows (\r\n) styled newlines.
  • catLines: Replaces Unix (\n) and Windows (\r\n) styled newlines with a space.
  • toSlash: Does nothing on Unix, but on Windows converts a string from \ path format to /.
  • fromSlash: Opposite of toSlash. Does nothing on Unix, but on Windows converts a string from / path format to \.
  • exeExt: Returns the right executable extension for the current OS (".exe" for Windows, "" for others).
  • shellQuote: Quotes a string to make it safe for use in shell scripts. Task uses this Go function for this. The Bash dialect is assumed.
  • splitArgs: Splits a string as if it were a command's arguments. Task uses this Go function

Example:

version: '3'

tasks:
print-os:
cmds:
- echo '{{OS}} {{ARCH}}'
- echo '{{if eq OS "windows"}}windows-command{{else}}unix-command{{end}}'
# This will be path/to/file on Unix but path\to\file on Windows
- echo '{{fromSlash "path/to/file"}}'
enumerated-file:
vars:
CONTENT: |
foo
bar
cmds:
- |
cat << EOF > output.txt
{{range $i, $line := .CONTENT | splitLines -}}
{{printf "%3d" $i}}: {{$line}}
{{end}}EOF

帮助

Running task --list (or task -l) lists all tasks with a description. The following Taskfile:

version: '3'

tasks:
build:
desc: Build the go binary.
cmds:
- go build -v -i main.go

test:
desc: Run all the go tests.
cmds:
- go test -race ./...

js:
cmds:
- esbuild --bundle --minify js/index.js > public/bundle.js

css:
cmds:
- esbuild --bundle --minify css/index.css > public/bundle.css

would print the following output:

* build:   Build the go binary.
* test: Run all the go tests.

If you want to see all tasks, there's a --list-all (alias -a) flag as well.

显示任务摘要

Running task --summary task-name will show a summary of a task. The following Taskfile:

version: '3'

tasks:
release:
deps: [build]
summary: |
Release your project to github

It will build your project before starting the release.
Please make sure that you have set GITHUB_TOKEN before starting.
cmds:
- your-release-tool

build:
cmds:
- your-build-tool

with running task --summary release would print the following output:

task: release

Release your project to github

It will build your project before starting the release.
Please make sure that you have set GITHUB_TOKEN before starting.

dependencies:
- build

commands:
- your-release-tool

If a summary is missing, the description will be printed. If the task does not have a summary or a description, a warning is printed.

Please note: showing the summary will not execute the command.

Task 别名

Aliases are alternative names for tasks. They can be used to make it easier and quicker to run tasks with long or hard-to-type names. You can use them on the command line, when calling sub-tasks in your Taskfile and when including tasks with aliases from another Taskfile. They can also be used together with namespace aliases.

version: '3'

tasks:
generate:
aliases: [gen]
cmds:
- task: gen-mocks

generate-mocks:
aliases: [gen-mocks]
cmds:
- echo "generating..."

重写 Task 名称

Sometimes you may want to override the task name printed on the summary, up-to-date messages to STDOUT, etc. In this case, you can just set label:, which can also be interpolated with variables:

version: '3'

tasks:
default:
- task: print
vars:
MESSAGE: hello
- task: print
vars:
MESSAGE: world

print:
label: 'print-{{.MESSAGE}}'
cmds:
- echo "{{.MESSAGE}}"

静默模式

Silent mode disables the echoing of commands before Task runs it. For the following Taskfile:

version: '3'

tasks:
echo:
cmds:
- echo "Print something"

Normally this will be printed:

echo "Print something"
Print something

With silent mode on, the below will be printed instead:

Print something

There are four ways to enable silent mode:

  • At command level:
version: '3'

tasks:
echo:
cmds:
- cmd: echo "Print something"
silent: true
  • At task level:
version: '3'

tasks:
echo:
cmds:
- echo "Print something"
silent: true
  • Globally at Taskfile level:
version: '3'

silent: true

tasks:
echo:
cmds:
- echo "Print something"
  • Or globally with --silent or -s flag

If you want to suppress STDOUT instead, just redirect a command to /dev/null:

version: '3'

tasks:
echo:
cmds:
- echo "This will print nothing" > /dev/null

试运行模式

Dry run mode (--dry) compiles and steps through each task, printing the commands that would be run without executing them. This is useful for debugging your Taskfiles.

忽略错误

You have the option to ignore errors during command execution. Given the following Taskfile:

version: '3'

tasks:
echo:
cmds:
- exit 1
- echo "Hello World"

Task will abort the execution after running exit 1 because the status code 1 stands for EXIT_FAILURE. However, it is possible to continue with execution using ignore_error:

version: '3'

tasks:
echo:
cmds:
- cmd: exit 1
ignore_error: true
- echo "Hello World"

ignore_error can also be set for a task, which means errors will be suppressed for all commands. Nevertheless, keep in mind that this option will not propagate to other tasks called either by deps or cmds!

输出语法

By default, Task just redirects the STDOUT and STDERR of the running commands to the shell in real-time. This is good for having live feedback for logging printed by commands, but the output can become messy if you have multiple commands running simultaneously and printing lots of stuff.

To make this more customizable, there are currently three different output options you can choose:

  • interleaved (default)
  • group
  • prefixed

To choose another one, just set it to root in the Taskfile:

version: '3'

output: 'group'

tasks:
# ...

The group output will print the entire output of a command once after it finishes, so you will not have live feedback for commands that take a long time to run.

When using the group output, you can optionally provide a templated message to print at the start and end of the group. This can be useful for instructing CI systems to group all of the output for a given task, such as with GitHub Actions' ::group:: command or Azure Pipelines.

version: '3'

output:
group:
begin: '::group::{{.TASK}}'
end: '::endgroup::'

tasks:
default:
cmds:
- echo 'Hello, World!'
silent: true
$ task default
::group::default
Hello, World!
::endgroup::

When using the group output, you may swallow the output of the executed command on standard output and standard error if it does not fail (zero exit code).

version: '3'

silent: true

output:
group:
error_only: true

tasks:
passes: echo 'output-of-passes'
errors: echo 'output-of-errors' && exit 1
$ task passes
$ task errors
output-of-errors
task: Failed to run task "errors": exit status 1

The prefix output will prefix every line printed by a command with [task-name] as the prefix, but you can customize the prefix for a command with the prefix: attribute:

version: '3'

output: prefixed

tasks:
default:
deps:
- task: print
vars: {TEXT: foo}
- task: print
vars: {TEXT: bar}
- task: print
vars: {TEXT: baz}

print:
cmds:
- echo "{{.TEXT}}"
prefix: "print-{{.TEXT}}"
silent: true
$ task default
[print-foo] foo
[print-bar] bar
[print-baz] baz
提示

The output option can also be specified by the --output or -o flags.

交互式 CLI 应用

When running interactive CLI applications inside Task they can sometimes behave weirdly, especially when the output mode is set to something other than interleaved (the default), or when interactive apps are run in parallel with other tasks.

The interactive: true tells Task this is an interactive application and Task will try to optimize for it:

version: '3'

tasks:
default:
cmds:
- vim my-file.txt
interactive: true

If you still have problems running an interactive app through Task, please open an issue about it.

短 Task 语法

Starting on Task v3, you can now write tasks with a shorter syntax if they have the default settings (e.g. no custom env:, vars:, desc:, silent: , etc):

version: '3'

tasks:
build: go build -v -o ./app{{exeExt}} .

run:
- task: build
- ./app{{exeExt}} -h localhost -p 8080

setshopt

It's possible to specify options to the set and shopt builtins. This can be added at global, task or command level.

version: '3'

set: [pipefail]
shopt: [globstar]

tasks:
# `globstar` required for double star globs to work
default: echo **/*.go
信息

Keep in mind that not all options are available in the shell interpreter library that Task uses.

观察任务

With the flags --watch or -w task will watch for file changes and run the task again. This requires the sources attribute to be given, so task knows which files to watch.

The default watch interval is 5 seconds, but it's possible to change it by either setting interval: '500ms' in the root of the Taskfile passing it as an argument like --interval=500ms.

+ \ No newline at end of file