关于 taskfiles
用于编写 Taskfiles 的技能,面向维护 Taskfile.yaml 和相关任务文件的开发者。它汇总命名空间引入、通配任务、依赖、前置条件及动态变量等模式。
主要功能
- 01规范 Taskfile 模板
- 02引入命名空间任务文件
- 03配置通配任务与依赖
- 04定义内部辅助任务
- 05使用动态变量和循环
适用场景
- 01为仓库新增命名空间任务文件
- 02创建带参数的任务命令
- 03为任务设置前置条件与并行依赖
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ ionfury/ homelab --skill taskfiles安装后在 Claude Code 中输入/taskfiles确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
tests.yamlreferences/cli.mdschema.mdstyleguide.mdtask-catalog.md详细介绍
Taskfiles
仓库结构
Taskfile.yaml # Root: includes namespaced taskfiles
.taskfiles/
├── inventory/taskfile.yaml # inv: IPMI host management
├── terragrunt/taskfile.yaml # tg: Infrastructure operations
├── worktree/taskfile.yaml # wt: Git worktree management
└── renovate/taskfile.yaml # renovate: Config validation
文件模板
始终包含 schema 和 version:
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
vars:
MY_DIR: "{{.ROOT_DIR}}/path"
tasks:
my-task:
desc: Short description for --list output.
cmds:
- echo "hello"
模式
引入新 Taskfile
添加到根 Taskfile.yaml:
includes:
namespace: .taskfiles/namespace
通配符任务
用于参数化操作:
plan-*:
desc: Plans a specific terragrunt stack.
vars:
STACK: "{{index .MATCH 0}}"
label: plan-{{.STACK}}
cmds:
- terragrunt plan --working-dir {{.INFRASTRUCTURE_DIR}}/stacks/{{.STACK}}
preconditions:
- which terragrunt
- test -d "{{.INFRASTRUCTURE_DIR}}/stacks/{{.STACK}}"
依赖
在 cmds 之前并行运行 deps:
apply-*:
deps: [use, fmt]
cmds:
- terragrunt apply ...
内部辅助任务
ipmi-command:
internal: true
silent: true
requires:
vars: [HOST, COMMAND]
cmds:
- ipmitool ... {{.COMMAND}}
前置条件
preconditions:
- which required-tool
- test -d "{{.PATH}}"
- sh: test "{{.VALUE}}" != ""
msg: "VALUE cannot be empty"
来源追踪
fmt:
sources:
- "{{.DIR}}/**/*.tf"
generates:
- "{{.DIR}}/**/*.tf"
cmds:
- tofu fmt -recursive
动态变量与 For 循环
vars:
VALID_HOSTS:
sh: "cat {{.INVENTORY_FILE}} | yq -r '.hosts | keys[]'"
power-status:
cmds:
- for: { var: VALID_HOSTS }
cmd: task inv:status-{{.ITEM}}
命令行参数
new:
requires:
vars: [CLI_ARGS]
vars:
NAME: "{{.CLI_ARGS}}"
cmds:
- git worktree add ... -b "{{.NAME}}"
用法:task wt:new -- feature-branch
参考
- references/task-catalog.md - 按命名空间列出的所有可用任务
- references/styleguide.md - 命名和格式约定
- references/schema.md - 完整的属性参考
- references/cli.md - 命令行标志和选项
评论
支持 Markdown