Documentation
¶
Index ¶
- Variables
- func ArgsToRequest(ctx context.Context, args ...string) (*http.Request, error)
- func CURLToRequest(ctx context.Context, curl string) (*http.Request, error)
- func ExecuteOutputs(tmpl *template.Template, data any, inputs, outputs map[string]any) (err error)
- func LoadEnv(ctx context.Context) map[string]any
- func NewTemplate(name string) *template.Template
- func Plaintext(text string) (string, error)
- func ToValue[T any](tmpl *template.Template, text string, data any) (value T, err error)
- func UpdateEnv(ctx context.Context, tmpl *template.Template, data any, env map[string]any) (context.Context, *template.Template, error)
- type Action
- type Input
- type Job
- type Needs
- type Output
- type Step
- type Steps
- type Workflow
Constants ¶
This section is empty.
Variables ¶
var BuiltinFuncMap = template.FuncMap{ "int": strconv.Atoi, "str": strconv.Itoa, "reg": func(pattern string, s string) (string, error) { expr, err := regexp.Compile(pattern) if err != nil { return "", err } return expr.FindString(s), nil }, "type": func(v any) string { return fmt.Sprintf("%T", v) }, "json": func(v any) (string, error) { b, err := json.Marshal(v) return string(b), err }, "gjson": func(path, json string) (any, error) { if r := gjson.Get(json, path); r.Exists() { return r.Value(), nil } return nil, fmt.Errorf("path not found: %q", path) }, "base64encode": func(s string) string { return base64.StdEncoding.EncodeToString([]byte(s)) }, "base64decode": func(s string) (string, error) { data, err := base64.StdEncoding.DecodeString(s) if err != nil { return "", err } return string(data), nil }, "plaintext": Plaintext, }
BuiltinFuncMap 内置函数
var CheckKey string = "__check__"
CheckKey 用来从上下文获取工作流是否已经检测过环
checked, ok := ctx.Value(CheckKey).(bool)
var EnvKey string = "__env__"
EnvKey 用来从上下文获取环境变量映射的键
env, ok := ctx.Value(EnvKey).(map[string]any)
var ErrLoadEnv = errors.New("cannot load env from nil context")
ErrLoadEnv 加载环境变量错误
var GoodName = func(name string) error { if name == "" { return fmt.Errorf("name %q: empty identifier", name) } for i, r := range name { switch { case r == '_': case i == 0 && !unicode.IsLetter(r): return fmt.Errorf("name %q: invalid identifier", name) case !unicode.IsLetter(r) && !unicode.IsDigit(r): return fmt.Errorf("name %q: invalid identifier", name) } } return nil }
GoodName 判断 ID 是否合法
var NormalizeUses = func(uses string) string { if abs, err := filepath.Abs(uses); err == nil { return filepath.Clean(abs) } return filepath.Clean(uses) }
NormalizeUses 归一化 uses 标识,用于环检测中的节点判等
默认反序列化实现从文件读取,因此默认按文件路径归一化,以合并 同一文件的不同写法。若替换了 UnmarshalAction 与 UnmarshalWorkflow, 请一并替换本函数以匹配新的标识语义。
var UnmarshalAction = func(name string) (*Action, error) { b, err := os.ReadFile(name) if err != nil { return nil, err } var a Action return &a, yaml.Unmarshal(b, &a) }
UnmarshalAction 反序列化可复用动作
var UnmarshalWorkflow = func(name string) (*Workflow, error) { b, err := os.ReadFile(name) if err != nil { return nil, err } var w Workflow return &w, yaml.Unmarshal(b, &w) }
UnmarshalWorkflow 反序列化工作流
Functions ¶
func ArgsToRequest ¶
ArgsToRequest 将 cURL 字符串的参数解析为 *http.Request
func CURLToRequest ¶
CURLToRequest 将 cURL 字符串解析为 *http.Request
func ExecuteOutputs ¶
ExecuteOutputs 执行模板获取值并写入输出映射
func NewTemplate ¶
func UpdateEnv ¶
func UpdateEnv(ctx context.Context, tmpl *template.Template, data any, env map[string]any) (context.Context, *template.Template, error)
UpdateEnv 更新上下文和模板中的环境变量映射
先对模板进行克隆,此时可以使用原先的环境变量函数,还可以为其设置新函数而不影响旧模板。 接着从上下文获取到旧的环境变量映射的克隆,在对其更新后作为新的环境变量映射。 对要添加的环境变量进行计算后写入新映射,再将新映射绑定在要返回的上下文和模板上。
Types ¶
type Action ¶
type Action struct {
Name string `yaml:"name,omitempty"` // 动作名称
Description string `yaml:"description,omitempty"` // 动作描述
Author string `yaml:"author,omitempty"` // 动作作者
Inputs map[string]Input `yaml:"inputs,omitempty"` // 动作输入
Outputs map[string]Output `yaml:"outputs,omitempty"` // 动作输出
Steps Steps `yaml:"steps,omitempty"` // 动作步骤
}
Action 是可复用动作
type Input ¶
type Input struct {
Description string `yaml:"description,omitempty"` // 输入描述
Required bool `yaml:"required,omitempty"` // 是否必填
Type string `yaml:"type,omitempty"` // 输入类型
Default any `yaml:"default,omitempty"` // 默认值
}
Input 是可复用动作、工作流的输入
type Job ¶
type Job struct {
If string `yaml:"if,omitempty"` // 执行条件
Name string `yaml:"name,omitempty"` // 任务名称
Needs Needs `yaml:"needs,omitempty"` // 依赖任务
Uses string `yaml:"uses,omitempty"` // 引用工作流
Env map[string]any `yaml:"env,omitempty"` // 环境变量
With map[string]any `yaml:"with,omitempty"` // 输入参数
Outputs map[string]any `yaml:"outputs,omitempty"` // 输出参数
Timeout int `yaml:"timeout,omitempty"` // 超时秒数
Steps Steps `yaml:"steps,omitempty"` // 任务步骤
// contains filtered or unexported fields
}
Job 是包含多个顺序执行步骤的任务
type Output ¶
type Output struct {
Description string `yaml:"description,omitempty"` // 输出描述
Value any `yaml:"value,omitempty"` // 输出值
}
Output 是可复用动作、工作流的输出
type Step ¶
type Step struct {
ID string `yaml:"id,omitempty"` // 步骤标识符
If string `yaml:"if,omitempty"` // 执行条件
Name string `yaml:"name,omitempty"` // 步骤名称
CURL string `yaml:"curl,omitempty"` // 请求命令
Uses string `yaml:"uses,omitempty"` // 引用动作
Env map[string]any `yaml:"env,omitempty"` // 环境变量
With map[string]any `yaml:"with,omitempty"` // 输入参数
Outputs map[string]any `yaml:"outputs,omitempty"` // 输出参数
Timeout int `yaml:"timeout,omitempty"` // 超时秒数
// contains filtered or unexported fields
}
Step 是包含请求信息的步骤
type Workflow ¶
type Workflow struct {
Name string `yaml:"name,omitempty"` // 工作流名称
Inputs map[string]Input `yaml:"inputs,omitempty"` // 工作流输入
Outputs map[string]Output `yaml:"outputs,omitempty"` // 工作流输出
Env map[string]any `yaml:"env,omitempty"` // 环境变量
Jobs map[string]*Job `yaml:"jobs,omitempty"` // 工作流任务
// contains filtered or unexported fields
}
Workflow 是包含多个同时执行任务的工作流