Files
go-task/zh-Hans/assets/js/01713e21.bb00eb2e.js
2023-05-06 21:57:54 +00:00

1 line
72 KiB
JavaScript

"use strict";(self.webpackChunktaskfile_dev=self.webpackChunktaskfile_dev||[]).push([[701],{3905:function(e,n,t){t.d(n,{Zo:function(){return k},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<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?i(Object(t),!0).forEach((function(n){l(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function r(e,n){if(null==e)return{};var t,a,l=function(e,n){if(null==e)return{};var t,a,l={},i=Object.keys(e);for(a=0;a<i.length;a++)t=i[a],n.indexOf(t)>=0||(l[t]=e[t]);return l}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)t=i[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(l[t]=e[t])}return l}var o=a.createContext({}),p=function(e){var n=a.useContext(o),t=n;return e&&(t="function"==typeof e?e(n):s(s({},n),e)),t},k=function(e){var n=p(e.components);return a.createElement(o.Provider,{value:n},e.children)},d="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,o=e.parentName,k=r(e,["components","mdxType","originalType","parentName"]),d=p(t),u=l,c=d["".concat(o,".").concat(u)]||d[u]||m[u]||i;return t?a.createElement(c,s(s({ref:n},k),{},{components:t})):a.createElement(c,s({ref:n},k))}));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 r={};for(var o in n)hasOwnProperty.call(n,o)&&(r[o]=n[o]);r.originalType=e,r[d]="string"==typeof e?e:l,s[1]=r;for(var p=2;p<i;p++)s[p]=t[p];return a.createElement.apply(null,s)}return a.createElement.apply(null,t)}u.displayName="MDXCreateElement"},3423:function(e,n,t){t.r(n),t.d(n,{assets:function(){return o},contentTitle:function(){return s},default:function(){return d},frontMatter:function(){return i},metadata:function(){return r},toc:function(){return p}});var a=t(3117),l=(t(7294),t(3905));const i={slug:"/usage/",sidebar_position:3},s="\u4f7f\u7528\u6307\u5357",r={unversionedId:"usage",id:"usage",title:"\u4f7f\u7528\u6307\u5357",description:"\u5feb\u901f\u5165\u95e8",source:"@site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/usage.md",sourceDirName:".",slug:"/usage/",permalink:"/zh-Hans/usage/",draft:!1,tags:[],version:"current",sidebarPosition:3,frontMatter:{slug:"/usage/",sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"\u5b89\u88c5",permalink:"/zh-Hans/installation/"},next:{title:"API \u53c2\u8003",permalink:"/zh-Hans/api/"}},o={},p=[{value:"\u5feb\u901f\u5165\u95e8",id:"\u5feb\u901f\u5165\u95e8",level:2},{value:"\u652f\u6301\u7684\u6587\u4ef6\u540d\u79f0",id:"\u652f\u6301\u7684\u6587\u4ef6\u540d\u79f0",level:2},{value:"\u4ece\u5b50\u76ee\u5f55\u8fd0\u884c Taskfile",id:"\u4ece\u5b50\u76ee\u5f55\u8fd0\u884c-taskfile",level:3},{value:"\u8fd0\u884c\u5168\u5c40 Taskfile",id:"\u8fd0\u884c\u5168\u5c40-taskfile",level:3},{value:"\u73af\u5883\u53d8\u91cf",id:"\u73af\u5883\u53d8\u91cf",level:2},{value:"Task",id:"task",level:3},{value:".env \u6587\u4ef6",id:"env-\u6587\u4ef6",level:3},{value:"\u5305\u542b\u5176\u4ed6 Taskfile",id:"\u5305\u542b\u5176\u4ed6-taskfile",level:2},{value:"\u64cd\u4f5c\u7cfb\u7edf\u7279\u5b9a Taskfile",id:"\u64cd\u4f5c\u7cfb\u7edf\u7279\u5b9a-taskfile",level:3},{value:"\u5305\u542b Taskfile \u7684\u76ee\u5f55",id:"\u5305\u542b-taskfile-\u7684\u76ee\u5f55",level:3},{value:"\u53ef\u9009 includes",id:"\u53ef\u9009-includes",level:3},{value:"\u5185\u90e8 includes",id:"\u5185\u90e8-includes",level:3},{value:"\u5305\u542b\u7684 Taskfile \u7684\u53d8\u91cf",id:"\u5305\u542b\u7684-taskfile-\u7684\u53d8\u91cf",level:3},{value:"\u547d\u540d\u7a7a\u95f4\u522b\u540d",id:"\u547d\u540d\u7a7a\u95f4\u522b\u540d",level:3},{value:"\u5185\u90e8 tasks",id:"\u5185\u90e8-tasks",level:2},{value:"Task \u76ee\u5f55",id:"task-\u76ee\u5f55",level:2},{value:"Task \u4f9d\u8d56",id:"task-\u4f9d\u8d56",level:2},{value:"\u5e73\u53f0\u7279\u5b9a\u7684 tasks \u548c cmds",id:"\u5e73\u53f0\u7279\u5b9a\u7684-tasks-\u548c-cmds",level:2},{value:"\u8c03\u7528\u53e6\u4e00\u4e2a task",id:"\u8c03\u7528\u53e6\u4e00\u4e2a-task",level:2},{value:"\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5de5\u4f5c",id:"\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5de5\u4f5c",level:2},{value:"\u901a\u8fc7\u6307\u7eb9\u8bc6\u522b\u672c\u5730\u751f\u6210\u7684\u6587\u4ef6\u53ca\u5176\u6765\u6e90",id:"\u901a\u8fc7\u6307\u7eb9\u8bc6\u522b\u672c\u5730\u751f\u6210\u7684\u6587\u4ef6\u53ca\u5176\u6765\u6e90",level:3},{value:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u6765\u8868\u793a\u4efb\u52a1\u662f\u6700\u65b0\u7684",id:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u6765\u8868\u793a\u4efb\u52a1\u662f\u6700\u65b0\u7684",level:3},{value:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u53d6\u6d88\u4efb\u52a1\u53ca\u5176\u4f9d\u8d56\u9879\u7684\u6267\u884c",id:"\u4f7f\u7528\u7a0b\u5e8f\u68c0\u67e5\u53d6\u6d88\u4efb\u52a1\u53ca\u5176\u4f9d\u8d56\u9879\u7684\u6267\u884c",level:3},{value:"\u5728\u4efb\u52a1\u8fd0\u884c\u65f6\u9650\u5236",id:"\u5728\u4efb\u52a1\u8fd0\u884c\u65f6\u9650\u5236",level:3},{value:"\u53d8\u91cf",id:"\u53d8\u91cf",level:2},{value:"\u52a8\u6001\u53d8\u91cf",id:"\u52a8\u6001\u53d8\u91cf",level:3},{value:"\u5c06 CLI \u53c2\u6570\u8f6c\u53d1\u5230 cmds",id:"\u5c06-cli-\u53c2\u6570\u8f6c\u53d1\u5230-cmds",level:2},{value:"\u4f7f\u7528 <code>defer</code> \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:"\u8986\u76d6 Task \u540d\u79f0",id:"\u8986\u76d6-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:"<code>set</code> \u548c <code>shopt</code>",id:"set-\u548c-shopt",level:2},{value:"\u89c2\u5bdf\u4efb\u52a1",id:"\u89c2\u5bdf\u4efb\u52a1",level:2}],k={toc:p};function d(e){let{components:n,...t}=e;return(0,l.kt)("wrapper",(0,a.Z)({},k,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 <service>")," \u548c ",(0,l.kt)("inlineCode",{parentName:"p"},"task up"),"\uff0c\u53ea\u8981 ",(0,l.kt)("inlineCode",{parentName:"p"},"<service>")," \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,"\u5982\u679c\u60a8\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"--global"),"\uff08\u522b\u540d ",(0,l.kt)("inlineCode",{parentName:"p"},"-g"),"\uff09\u6807\u5fd7\u8c03\u7528 Task\uff0c\u5b83\u5c06\u67e5\u627e\u60a8\u7684 home \u76ee\u5f55\u800c\u4e0d\u662f\u60a8\u7684\u5de5\u4f5c\u76ee\u5f55\u3002 \u7b80\u800c\u8a00\u4e4b\uff0cTask \u5c06\u5728 ",(0,l.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yml")," \u6216 ",(0,l.kt)("inlineCode",{parentName:"p"},"$HOME/Taskfile.yaml")," \u8def\u5f84\u4e0a\u5bfb\u627e Taskfile\u3002"),(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"},"\u5f53\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"-g")," \u8fd0\u884c\u5168\u5c40 Taskfile \u65f6\uff0ctask \u5c06\u9ed8\u8ba4\u5728 ",(0,l.kt)("inlineCode",{parentName:"p"},"$HOME")," \u4e0a\u8fd0\u884c\uff0c\u800c\u4e0d\u662f\u5728\u60a8\u7684\u5de5\u4f5c\u76ee\u5f55\u4e0a\uff01"),(0,l.kt)("p",{parentName:"admonition"},"\u5982\u524d\u4e00\u8282\u6240\u8ff0\uff0c",(0,l.kt)("inlineCode",{parentName:"p"},"{{.USER_WORKING_DIR}}")," \u7279\u6b8a\u53d8\u91cf\u5728\u8fd9\u91cc\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u5728\u60a8\u4ece\u4e2d\u8c03\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"task -g")," \u7684\u76ee\u5f55\u4e2d\u8fd0\u884c\u5185\u5bb9\u3002"),(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,"\u7ed9\u5b9a\u7684 Taskfile \u4e2d\u63cf\u8ff0\u7684\u4efb\u52a1\u5c06\u5728\u6307\u5b9a\u7684\u547d\u540d\u7a7a\u95f4\u4e2d\u63d0\u4f9b\u3002 \u56e0\u6b64\uff0c\u60a8\u53ef\u4ee5\u8c03\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"task docs:serve")," \u4ece ",(0,l.kt)("inlineCode",{parentName:"p"},"documentation/Taskfile.yml")," \u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"serve")," task\uff0c\u6216\u8005\u8c03\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"task docker:build")," \u4ece ",(0,l.kt)("inlineCode",{parentName:"p"},"DockerTasks.yml")," \u6587\u4ef6\u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"build")," task\u3002"),(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,"\u5728 ",(0,l.kt)("inlineCode",{parentName:"p"},"version: '2'")," \u4e2d\uff0ctask \u4f1a\u81ea\u52a8\u5c1d\u8bd5\u5f15\u5165 ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_{{OS}}.yml")," \u6587\u4ef6 \uff08\u4f8b\u5982",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_windows.yml"),", ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_linux.yml")," \u6216 ",(0,l.kt)("inlineCode",{parentName:"p"},"Taskfile_darwin.yml"),"\uff09\u3002 \u4f46\u662f\u56e0\u4e3a\u8fc7\u4e8e\u9690\u6666\uff0c\u5728\u7248\u672c 3 \u4e2d\u88ab\u79fb\u9664\u4e86\uff0c \u5728\u7248\u672c 3 \u53ef\u4ee5\u901a\u8fc7\u660e\u786e\u7684\u5f15\u7528\u6765\u5b9e\u73b0\u7c7b\u4f3c\u529f\u80fd:"),(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\n ./tests/Taskfile.yml does not exist\"\n")),(0,l.kt)("h3",{id:"\u5185\u90e8-includes"},"\u5185\u90e8 includes"),(0,l.kt)("p",null,"\u6807\u8bb0\u4e3a internal \u7684\u5305\u542b\u4f1a\u5c06\u5305\u542b\u6587\u4ef6\u7684\u6240\u6709 task \u4e5f\u8bbe\u7f6e\u4e3a\u5185\u90e8 task\uff08\u8bf7\u53c2\u9605\u4e0b\u9762\u7684 ",(0,l.kt)("a",{parentName:"p",href:"#%E5%86%85%E9%83%A8-tasks"},"\u5185\u90e8-tasks")," \u90e8\u5206\uff09\u3002 \u8fd9\u5728\u5305\u542b\u4e0d\u6253\u7b97\u7531\u7528\u6237\u76f4\u63a5\u4f7f\u7528\u7684\u5b9e\u7528\u7a0b\u5e8f\u4efb\u52a1\u65f6\u5f88\u6709\u7528\u3002"),(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,"\u5305\u542b Taskfile \u65f6\uff0c\u60a8\u53ef\u4ee5\u4e3a\u547d\u540d\u7a7a\u95f4\u63d0\u4f9b\u4e00\u4e2a ",(0,l.kt)("inlineCode",{parentName:"p"},"aliases")," \u5217\u8868\u3002 \u8fd9\u4e0e ",(0,l.kt)("a",{parentName:"p",href:"#task-%E5%88%AB%E5%90%8D"},"task \u522b\u540d")," \u7684\u5de5\u4f5c\u65b9\u5f0f\u76f8\u540c\uff0c\u53ef\u4ee5\u4e00\u8d77\u4f7f\u7528\u6765\u521b\u5efa\u66f4\u77ed\u4e14\u66f4\u6613\u4e8e\u952e\u5165\u7684\u547d\u4ee4\u3002"),(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"},"\u5728\u5305\u542b\u7684 Taskfile \u4e2d\u58f0\u660e\u7684\u53d8\u91cf\u4f18\u5148\u4e8e\u5305\u542b Taskfile \u4e2d\u7684\u53d8\u91cf\uff01 \u5982\u679c\u60a8\u5e0c\u671b\u5305\u542b\u7684 Taskfile \u4e2d\u7684\u53d8\u91cf\u53ef\u88ab\u8986\u76d6\uff0c\u8bf7\u4f7f\u7528 ",(0,l.kt)("a",{parentName:"p",href:"https://go-task.github.io/slim-sprig/defaults.html"},"\u9ed8\u8ba4\u65b9\u6cd5"),"\uff1a",(0,l.kt)("inlineCode",{parentName:"p"},"MY_VAR: '{{.MY_VAR | default \"my-default-value\"}}'"),"\u3002")),(0,l.kt)("h2",{id:"\u5185\u90e8-tasks"},"\u5185\u90e8 tasks"),(0,l.kt)("p",null,"\u5185\u90e8 task \u662f\u7528\u6237\u4e0d\u80fd\u76f4\u63a5\u8c03\u7528\u7684 task\u3002 \u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"task --list|--list-all")," \u65f6\uff0c\u5b83\u4eec\u4e0d\u4f1a\u51fa\u73b0\u5728\u8f93\u51fa\u4e2d\u3002 \u5176\u4ed6 task \u53ef\u4ee5\u7167\u5e38\u8c03\u7528\u5185\u90e8 task\u3002 \u8fd9\u5bf9\u4e8e\u521b\u5efa\u5728\u547d\u4ee4\u884c\u4e0a\u6ca1\u6709\u7528\u5904\u7684\u53ef\u91cd\u7528\u3001\u7c7b\u4f3c\u51fd\u6570\u7684 task \u5f88\u6709\u7528\u3002"),(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,"\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ctasks \u5c06\u5728 Taskfile \u6240\u5728\u7684\u76ee\u5f55\u4e2d\u6267\u884c\u3002 \u4f46\u662f\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u8ba9 task \u5728\u53e6\u4e00\u4e2a\u76ee\u5f55\u4e2d\u8fd0\u884c\uff0c\u6307\u5b9a ",(0,l.kt)("inlineCode",{parentName:"p"},"dir"),"\uff1a"),(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"},"\u4f9d\u8d56\u9879\u5e76\u884c\u8fd0\u884c\uff0c\u56e0\u6b64\u4e00\u9879 task \u7684\u4f9d\u8d56\u9879\u4e0d\u5e94\u76f8\u4e92\u4f9d\u8d56\u3002 \u5982\u679c\u60a8\u60f3\u5f3a\u5236\u4efb\u52a1\u987a\u5e8f\u8fd0\u884c\uff0c\u8bf7\u67e5\u770b\u4e0b\u9762\u7684 ",(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 task")," \u90e8\u5206\u3002")),(0,l.kt)("p",null,"\u60a8\u53ef\u80fd\u6709\u4f9d\u8d56\u4e8e\u5176\u5b83\u7684 task\u3002 \u5c06\u5b83\u4eec\u6307\u5411 ",(0,l.kt)("inlineCode",{parentName:"p"},"deps")," \u5c06\u4f7f\u5b83\u4eec\u5728\u8fd0\u884c\u7236 task \u4e4b\u524d\u81ea\u52a8\u8fd0\u884c\uff1a"),(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,"\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u5982\u679c\u60a8\u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"task build"),"\uff0c",(0,l.kt)("inlineCode",{parentName:"p"},"assets")," \u5c06\u59cb\u7ec8\u5728 ",(0,l.kt)("inlineCode",{parentName:"p"},"build")," \u4e4b\u524d\u8fd0\u884c\u3002"),(0,l.kt)("p",null,"\u4e00\u4e2a task \u53ea\u80fd\u6709\u4f9d\u8d56\u5173\u7cfb\uff0c\u6ca1\u6709\u547d\u4ee4\u6765\u5c06 task \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"},"\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"--parallel")," \u6807\u5fd7\uff08\u522b\u540d ",(0,l.kt)("inlineCode",{parentName:"p"},"-p"),"\uff09\u4f7f\u547d\u4ee4\u884c\u7ed9\u51fa\u7684 task \u5e76\u884c\u8fd0\u884c\u3002 \u4f8b\u5982: ",(0,l.kt)("inlineCode",{parentName:"p"},"task --parallel js css"),"\u3002")),(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 task")," \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,"\u5982\u679c\u60a8\u60f3\u5c06 task \u7684\u8fd0\u884c\u9650\u5236\u5728\u660e\u786e\u7684\u5e73\u53f0\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"platforms:")," \u952e\u6765\u5b9e\u73b0\u3002 Task \u53ef\u4ee5\u9650\u5236\u5728\u7279\u5b9a\u7684\u64cd\u4f5c\u7cfb\u7edf\u3001\u67b6\u6784\u6216\u4e24\u8005\u7684\u7ec4\u5408\u4e2d\u3002 \u5982\u679c\u4e0d\u5339\u914d\uff0c\u4efb\u52a1\u6216\u547d\u4ee4\u5c06\u88ab\u8df3\u8fc7\uff0c\u5e76\u4e14\u4e0d\u4f1a\u629b\u51fa\u4efb\u4f55\u9519\u8bef\u3002"),(0,l.kt)("p",null,"\u5141\u8bb8\u4f5c\u4e3a OS \u6216 Arch \u7684\u503c\u662f\u6709\u6548\u7684 ",(0,l.kt)("inlineCode",{parentName:"p"},"GOOS")," \u548c ",(0,l.kt)("inlineCode",{parentName:"p"},"GOARCH")," \u503c\uff0c\u6b63\u5982 ",(0,l.kt)("a",{parentName:"p",href:"https://github.com/golang/go/blob/master/src/go/build/syslist.go"},"\u6b64\u5904")," \u7684 Go \u8bed\u8a00\u6240\u5b9a\u4e49\u7684\u90a3\u6837\u3002"),(0,l.kt)("p",null,"\u4e0b\u9762\u7684 ",(0,l.kt)("inlineCode",{parentName:"p"},"build-windows")," task \u5c06\u4ec5\u5728 Windows \u6240\u6709\u67b6\u6784\u4e0a\u8fd0\u884c\uff1a"),(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,"\u8fd9\u53ef\u4ee5\u9650\u5236\u4e3a\u7279\u5b9a\u7684\u67b6\u6784\uff0c\u5982\u4e0b\u6240\u793a\uff1a"),(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,"\u4e5f\u53ef\u4ee5\u5c06 task \u9650\u5236\u5728\u7279\u5b9a\u7684\u67b6\u6784\u4e2d\uff1a"),(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,"\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\u5e73\u53f0\uff0c\u5982\u4e0b\u6240\u793a\uff1a"),(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,"\u4e2a\u522b\u547d\u4ee4\u4e5f\u53ef\u4ee5\u9650\u5236\u5728\u7279\u5b9a\u5e73\u53f0\u4e0a\uff1a"),(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"},"\u6ce8\u610f\uff1a\u5982\u679c\u60a8\u60f3\u4ece ",(0,l.kt)("a",{parentName:"p",href:"#%E5%8C%85%E5%90%AB%E5%85%B6%E4%BB%96-taskfile"},"\u5305\u542b\u7684 Taskfile")," \u4e2d\u8c03\u7528\u5728\u6839 Taskfile \u4e2d\u58f0\u660e\u7684 task\uff0c\u8bf7\u50cf\u8fd9\u6837\u6dfb\u52a0 ",(0,l.kt)("inlineCode",{parentName:"p"},":")," \u524d\u7f00\uff1a",(0,l.kt)("inlineCode",{parentName:"p"},"task: :task-name"),"\u3002")),(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")," \u548c ",(0,l.kt)("inlineCode",{parentName:"p"},"generates")," \u53ef\u4ee5\u914d\u7f6e\u5177\u4f53\u6587\u4ef6\u6216\u8005\u4f7f\u7528\u5339\u914d\u6a21\u5f0f\u3002 \u8bbe\u7f6e\u540e\uff0c Task \u4f1a\u6839\u636e\u6e90\u6587\u4ef6\u7684 checksum \u6765\u786e\u5b9a\u662f\u5426\u9700\u8981\u6267\u884c\u5f53\u524d\u4efb\u52a1\u3002 \u5982\u679c\u4e0d\u9700\u8981\u6267\u884c\uff0c \u5219\u4f1a\u8f93\u51fa\u50cf ",(0,l.kt)("inlineCode",{parentName:"p"},'Task "js" is up to date')," \u8fd9\u6837\u7684\u4fe1\u606f\u3002"),(0,l.kt)("p",null,"\u5982\u679c\u60a8\u5e0c\u671b\u901a\u8fc7\u6587\u4ef6\u7684\u4fee\u6539 timestamp \u800c\u4e0d\u662f\u5176 checksum\uff08\u5185\u5bb9\uff09\u6765\u8fdb\u884c\u6b64\u68c0\u67e5\uff0c\u53ea\u9700\u5c06 ",(0,l.kt)("inlineCode",{parentName:"p"},"method")," \u5c5e\u6027\u8bbe\u7f6e\u4e3a ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamp")," \u5373\u53ef\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 .\n sources:\n - ./*.go\n generates:\n - app{{exeExt}}\n method: timestamp\n")),(0,l.kt)("p",null,"\u5728\u9700\u8981\u66f4\u5927\u7075\u6d3b\u6027\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"status")," \u5173\u952e\u5b57\u3002 \u60a8\u751a\u81f3\u53ef\u4ee5\u5c06\u4e24\u8005\u7ed3\u5408\u8d77\u6765\u3002 \u6709\u5173\u793a\u4f8b\uff0c\u8bf7\u53c2\u9605 ",(0,l.kt)("a",{parentName:"p",href:"#%E4%BD%BF%E7%94%A8%E7%A8%8B%E5%BA%8F%E6%A3%80%E6%9F%A5%E6%9D%A5%E8%A1%A8%E7%A4%BA%E4%BB%BB%E5%8A%A1%E6%98%AF%E6%9C%80%E6%96%B0%E7%9A%84"},"\u72b6\u6001")," \u6587\u6863\u3002"),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"\u9ed8\u8ba4\u60c5\u51b5\uff0ctask \u5728\u672c\u5730\u9879\u76ee\u7684 ",(0,l.kt)("inlineCode",{parentName:"p"},".task")," \u76ee\u5f55\u4fdd\u5b58 checksums \u503c\u3002 \u4e00\u822c\u90fd\u4f1a\u5728 ",(0,l.kt)("inlineCode",{parentName:"p"},".gitignore"),"\uff08\u6216\u7c7b\u4f3c\u914d\u7f6e\uff09\u4e2d\u5ffd\u7565\u6389\u8fd9\u4e2a\u76ee\u5f55\uff0c\u8fd9\u6837\u5b83\u5c31\u4e0d\u4f1a\u88ab\u63d0\u4ea4\u3002 (\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u5df2\u63d0\u4ea4\u7684\u4ee3\u7801\u751f\u6210\u4efb\u52a1\uff0c\u90a3\u4e48\u63d0\u4ea4\u8be5\u4efb\u52a1\u7684\u6821\u9a8c\u548c\u4e5f\u662f\u6709\u610f\u4e49\u7684)\u3002"),(0,l.kt)("p",{parentName:"admonition"},"\u5982\u679c\u4f60\u60f3\u8981\u5c06\u8fd9\u4e9b\u6587\u4ef6\u5b58\u50a8\u5728\u53e6\u4e00\u4e2a\u76ee\u5f55\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728\u4f60\u7684\u673a\u5668\u4e2d\u8bbe\u7f6e\u4e00\u4e2a ",(0,l.kt)("inlineCode",{parentName:"p"},"TASK_TEMP_DIR")," \u73af\u5883\u53d8\u91cf\u3002 \u53ef\u4ee5\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\uff0c\u6bd4\u5982 ",(0,l.kt)("inlineCode",{parentName:"p"},"tmp/task"),"\uff0c\u76f8\u5bf9\u9879\u76ee\u6839\u76ee\u5f55\uff0c\u4e5f\u53ef\u4ee5\u7528\u7edd\u5bf9\u8def\u5f84\u3001\u7528\u6237\u76ee\u5f55\u8def\u5f84\uff0c\u6bd4\u5982 ",(0,l.kt)("inlineCode",{parentName:"p"},"/tmp/.task")," \u6216 ",(0,l.kt)("inlineCode",{parentName:"p"},"~/.task"),"\uff08\u6bcf\u4e2a\u9879\u76ee\u5355\u72ec\u521b\u5efa\u5b50\u76ee\u5f55\uff09\u3002"),(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"},"\u6bcf\u4e2a task \u53ea\u4e3a\u5176 ",(0,l.kt)("inlineCode",{parentName:"p"},"sources")," \u5b58\u50a8\u4e00\u4e2a checksum\u3002 \u5982\u679c\u60a8\u60f3\u901a\u8fc7\u4efb\u4f55\u8f93\u5165\u53d8\u91cf\u6765\u533a\u5206 task\uff0c\u60a8\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u53d8\u91cf\u6dfb\u52a0\u4e3a task \u6807\u7b7e\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u5c06\u88ab\u89c6\u4e3a\u4e0d\u540c\u7684 task\u3002"),(0,l.kt)("p",{parentName:"admonition"},"\u5982\u679c\u60a8\u60f3\u4e3a\u6bcf\u4e2a\u4e0d\u540c\u7684\u8f93\u5165\u96c6\u8fd0\u884c\u4e00\u6b21 task\uff0c\u76f4\u5230 sources \u5b9e\u9645\u53d1\u751f\u53d8\u5316\uff0c\u8fd9\u5c06\u5f88\u6709\u7528\u3002 \u4f8b\u5982\uff0c\u5982\u679c sources \u4f9d\u8d56\u4e8e\u53d8\u91cf\u7684\u503c\uff0c\u6216\u8005\u60a8\u5e0c\u671b\u5728\u67d0\u4e9b\u53c2\u6570\u53d1\u751f\u53d8\u5316\u65f6\u91cd\u65b0\u8fd0\u884c task\uff0c\u5373\u4f7f sources \u6ca1\u6709\u53d1\u751f\u53d8\u5316\u4e5f\u662f\u5982\u6b64\u3002")),(0,l.kt)("admonition",{type:"tip"},(0,l.kt)("p",{parentName:"admonition"},"\u5c06 method \u8bbe\u7f6e\u4e3a ",(0,l.kt)("inlineCode",{parentName:"p"},"none")," \u4f1a\u8df3\u8fc7\u4efb\u4f55\u9a8c\u8bc1\u5e76\u59cb\u7ec8\u8fd0\u884c\u4efb\u52a1\u3002")),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"},"\u8981\u4f7f ",(0,l.kt)("inlineCode",{parentName:"p"},"checksum"),"\uff08\u9ed8\u8ba4\uff09\u6216 ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamp")," \u65b9\u6cd5\u8d77\u4f5c\u7528\uff0c\u53ea\u9700\u8981\u901a\u77e5 source \u6587\u4ef6\u5373\u53ef\u3002 \u5f53\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"timestamp")," \u65b9\u6cd5\u65f6\uff0c\u6700\u540e\u4e00\u6b21\u8fd0\u884c task \u88ab\u8ba4\u4e3a\u662f\u4e00\u6b21\u751f\u6210\u3002")),(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"),(0,l.kt)("p",null,"\u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u901a\u77e5\u4e00\u7cfb\u5217\u6d4b\u8bd5\u4f5c\u4e3a ",(0,l.kt)("inlineCode",{parentName:"p"},"status"),"\u3002 \u5982\u679c\u6ca1\u6709\u9519\u8bef\u8fd4\u56de\uff08\u9000\u51fa\u72b6\u6001 0\uff09\uff0ctask \u88ab\u8ba4\u4e3a\u662f\u6700\u65b0\u7684\uff1a"),(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,"\u5982\u679c\u4f60\u60f3\u5f3a\u5236\u4efb\u52a1\u8fd0\u884c\uff0c\u5373\u4f7f\u662f\u6700\u65b0\u7684\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"--force")," \u6216 ",(0,l.kt)("inlineCode",{parentName:"p"},"-f"),"\u3002"),(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,"\u5148\u51b3\u6761\u4ef6\u53ef\u4ee5\u8bbe\u7f6e\u7279\u5b9a\u7684\u5931\u8d25\u6d88\u606f\uff0c\u8fd9\u4e9b\u6d88\u606f\u53ef\u4ee5\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"p"},"msg")," \u5b57\u6bb5\u544a\u8bc9\u7528\u6237\u8981\u91c7\u53d6\u4ec0\u4e48\u6b65\u9aa4\u3002"),(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,(0,l.kt)("inlineCode",{parentName:"p"},"run")," \u652f\u6301\u7684\u503c\uff1a"),(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,"\u5728\u8fdb\u884c\u53d8\u91cf\u63d2\u503c\u65f6\uff0cTask \u5c06\u67e5\u627e\u4ee5\u4e0b\u5185\u5bb9\u3002 \u5b83\u4eec\u6309\u6743\u91cd\u987a\u5e8f\u5217\u5728\u4e0b\u9762\uff08\u5373\u6700\u91cd\u8981\u7684\u7b2c\u4e00\u4f4d\uff09\uff1a"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"task \u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf"),(0,l.kt)("li",{parentName:"ul"},"\u88ab\u5176\u5b83 task \u8c03\u7528\u65f6\u4f20\u5165\u7684\u53d8\u91cf(\u67e5\u770b ",(0,l.kt)("a",{parentName:"li",href:"#%E8%B0%83%E7%94%A8%E5%8F%A6%E4%B8%80%E4%B8%AA-task"},"\u8c03\u7528\u53e6\u4e00\u4e2a task"),")"),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("a",{parentName:"li",href:"#%E5%8C%85%E5%90%AB%E5%85%B6%E4%BB%96-taskfile"},"\u5305\u542b\u5176\u4ed6 Taskfile")," \u4e2d\u7684\u53d8\u91cf (\u5f53\u5305\u542b\u5176\u4ed6 task \u65f6)"),(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,"\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u4f20\u8f93\u53c2\u6570\u7684\u793a\u4f8b\uff1a"),(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,"\u4f7f\u7528\u5176\u5b83 task \u4f5c\u4e3a\u6e05\u7406\u4efb\u52a1\u7684\u547d\u4ee4\u65f6\uff0c\u53ef\u4ee5\u8fd9\u6837\uff1a"),(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 \u5728\u6267\u884c\u547d\u4ee4\u4e4b\u524d\u5c06\u547d\u4ee4\u89e3\u6790\u4e3a ",(0,l.kt)("a",{parentName:"p",href:"https://golang.org/pkg/text/template/"},"Go \u7684\u6a21\u677f\u5f15\u64ce"),"\u3002 \u53ef\u4ee5\u901a\u8fc7\u70b9\u8bed\u6cd5 (",(0,l.kt)("inlineCode",{parentName:"p"},".VARNAME"),") \u8bbf\u95ee\u53d8\u91cf\u3002"),(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 \u8fd8\u589e\u52a0\u4e86\u4ee5\u4e0b\u529f\u80fd\uff1a"),(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,"\u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"task --list"),"\uff08\u6216 ",(0,l.kt)("inlineCode",{parentName:"p"},"task -l"),"\uff09\u5217\u51fa\u6240\u6709\u5e26\u6709\u63cf\u8ff0\u7684\u4efb\u52a1\u3002 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,"\u5c06\u6253\u5370\u4ee5\u4e0b\u8f93\u51fa\uff1a"),(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,"\u5982\u679c\u60a8\u60f3\u67e5\u770b\u6240\u6709\u4efb\u52a1\uff0c\u8fd8\u6709\u4e00\u4e2a ",(0,l.kt)("inlineCode",{parentName:"p"},"--list-all"),"\uff08\u522b\u540d ",(0,l.kt)("inlineCode",{parentName:"p"},"-a"),"\uff09\u6807\u5fd7\u3002"),(0,l.kt)("h2",{id:"\u663e\u793a\u4efb\u52a1\u6458\u8981"},"\u663e\u793a\u4efb\u52a1\u6458\u8981"),(0,l.kt)("p",null,"\u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"task --summary task-name")," \u5c06\u663e\u793a\u4efb\u52a1\u7684\u6458\u8981\u3002 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 \u53d1\u5e03\u4f60\u7684\u9879\u76ee\u5230 github\n\n \u5b83\u5c06\u5728\u5f00\u59cb\u53d1\u5e03\u4e4b\u524d\u6784\u5efa\u60a8\u7684\u9879\u76ee\u3002\n \u8bf7\u786e\u4fdd\u60a8\u5728\u5f00\u59cb\u4e4b\u524d\u5df2\u7ecf\u8bbe\u7f6e\u4e86 GITHUB_TOKEN\u3002\n cmds:\n - your-release-tool\n\n build:\n cmds:\n - your-build-tool\n")),(0,l.kt)("p",null,"\u8fd0\u884c ",(0,l.kt)("inlineCode",{parentName:"p"},"task --summary release")," \u5c06\u6253\u5370\u4ee5\u4e0b\u8f93\u51fa\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"task: release\n\n\u53d1\u5e03\u4f60\u7684\u9879\u76ee\u5230 github\n\n\u5b83\u5c06\u5728\u5f00\u59cb\u53d1\u5e03\u4e4b\u524d\u6784\u5efa\u60a8\u7684\u9879\u76ee\u3002\n\u8bf7\u786e\u4fdd\u60a8\u5728\u5f00\u59cb\u4e4b\u524d\u5df2\u7ecf\u8bbe\u7f6e\u4e86 GITHUB_TOKEN\u3002\n\ndependencies:\n - build\n\ncommands:\n - your-release-tool\n")),(0,l.kt)("p",null,"\u5982\u679c\u7f3a\u5c11\u6458\u8981\uff0c\u5c06\u6253\u5370\u63cf\u8ff0\u3002 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 \u662f task \u7684\u66ff\u4ee3\u540d\u79f0\u3002 \u5b83\u4eec\u53ef\u4ee5\u4f7f\u8fd0\u884c\u5177\u6709\u957f\u540d\u79f0\u6216\u96be\u4ee5\u952e\u5165\u540d\u79f0\u7684 task \u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u548c\u5feb\u901f\u3002 \u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e0a\u4f7f\u7528\u5b83\u4eec\uff0c\u5728\u60a8\u7684 Taskfile \u4e2d ",(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\u5b50\u4efb\u52a1")," \u65f6\u4ee5\u53ca\u5728 ",(0,l.kt)("a",{parentName:"p",href:"#%E5%8C%85%E5%90%AB%E5%85%B6%E4%BB%96-taskfile"},"\u5305\u542b\u6765\u81ea\u53e6\u4e00\u4e2a Taskfile")," \u7684\u522b\u540d task \u65f6\u3002 \u5b83\u4eec\u4e5f\u53ef\u4ee5\u4e0e ",(0,l.kt)("a",{parentName:"p",href:"#%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%E5%88%AB%E5%90%8D"},"\u547d\u540d\u7a7a\u95f4\u522b\u540d")," \u4e00\u8d77\u4f7f\u7528\u3002"),(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:"\u8986\u76d6-task-\u540d\u79f0"},"\u8986\u76d6 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,"\u9759\u9ed8\u6a21\u5f0f\u5728 Task \u8fd0\u884c\u547d\u4ee4\u4e4b\u524d\u7981\u7528\u547d\u4ee4\u56de\u663e\u3002 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,"\u901a\u5e38\u8fd9\u5c06\u6253\u5370\uff1a"),(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,"\u5f00\u542f\u9759\u9ed8\u6a21\u5f0f\u540e\uff0c\u5c06\u6253\u5370\u4ee5\u4e0b\u5185\u5bb9\uff1a"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-sh"},"Print something\n")),(0,l.kt)("p",null,"\u5f00\u542f\u9759\u9ed8\u6a21\u5f0f\u6709\u56db\u79cd\u65b9\u5f0f\uff1a"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"\u5728 cmds \u7ea7\u522b\uff1a")),(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"},"\u5728 task \u7ea7\u522b\uff1a")),(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"},"\u5728 Taskfile \u5168\u5c40\u7ea7\u522b\uff1a")),(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"},"\u6216\u8005\u5168\u5c40\u4f7f\u7528 ",(0,l.kt)("inlineCode",{parentName:"li"},"--silent")," \u6216 ",(0,l.kt)("inlineCode",{parentName:"li"},"-s")," \u6807\u5fd7")),(0,l.kt)("p",null,"\u5982\u679c\u60a8\u60f3\u6539\u4e3a\u7981\u6b62 STDOUT\uff0c\u53ea\u9700\u5c06\u547d\u4ee4\u91cd\u5b9a\u5411\u5230 ",(0,l.kt)("inlineCode",{parentName:"p"},"/dev/null"),"\uff1a"),(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,"\u60a8\u53ef\u4ee5\u9009\u62e9\u5728\u547d\u4ee4\u6267\u884c\u671f\u95f4\u5ffd\u7565\u9519\u8bef\u3002 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,"\u4e3a\u4e86\u4f7f\u5176\u66f4\u5177\u53ef\u5b9a\u5236\u6027\uff0c\u76ee\u524d\u60a8\u53ef\u4ee5\u9009\u62e9\u4e09\u79cd\u4e0d\u540c\u7684\u8f93\u51fa\u9009\u9879\uff1a"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"interleaved")," (\u9ed8\u8ba4)"),(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,"\u8981\u9009\u62e9\u53e6\u4e00\u4e2a\uff0c\u53ea\u9700\u5728 Taskfile \u6839\u76ee\u5f55\u4e2d\u8bbe\u7f6e\u5373\u53ef\uff1a"),(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,(0,l.kt)("inlineCode",{parentName:"p"},"group")," \u8f93\u51fa\u5c06\u5728\u547d\u4ee4\u5b8c\u6210\u540e\u6253\u5370\u4e00\u6b21\u547d\u4ee4\u7684\u5168\u90e8\u8f93\u51fa\uff0c\u56e0\u6b64\u60a8\u4e0d\u4f1a\u5bf9\u9700\u8981\u5f88\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u547d\u4ee4\u6709\u5b9e\u65f6\u53cd\u9988\u3002"),(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"),"."))}d.isMDXComponent=!0}}]);