mirror of
https://github.com/go-task/task.git
synced 2026-06-11 09:51:50 +00:00
Adds a new `gitlab` output style that wraps each task's output in GitLab CI collapsible section markers. Section IDs are generated automatically so that start and end markers always match and stay unique per invocation — even when the same task runs multiple times in one job. Options: `collapsed` (maps to GitLab's native `[collapsed=true]`) and `error_only` (Task-level behavior, identical to `group.error_only`). Also introduces `output-ci-auto` (taskrc + TASK_OUTPUT_CI_AUTO env var) that auto-selects a CI-aware output style when a supported CI runner is detected (currently `GITLAB_CI=true` → gitlab) and no output style is explicitly configured. Keeps the Taskfile neutral so local devs are not forced into CI-shaped output. Refs #2806.
85 lines
1.9 KiB
Go
85 lines
1.9 KiB
Go
package ast
|
|
|
|
import (
|
|
"go.yaml.in/yaml/v3"
|
|
|
|
"github.com/go-task/task/v3/errors"
|
|
)
|
|
|
|
// Output of the Task output
|
|
type Output struct {
|
|
// Name of the Output.
|
|
Name string `yaml:"-"`
|
|
// Group specific style
|
|
Group OutputGroup
|
|
// GitLab specific style
|
|
GitLab OutputGitLab
|
|
}
|
|
|
|
// IsSet returns true if and only if a custom output style is set.
|
|
func (s *Output) IsSet() bool {
|
|
return s.Name != ""
|
|
}
|
|
|
|
func (s *Output) UnmarshalYAML(node *yaml.Node) error {
|
|
switch node.Kind {
|
|
|
|
case yaml.ScalarNode:
|
|
var name string
|
|
if err := node.Decode(&name); err != nil {
|
|
return errors.NewTaskfileDecodeError(err, node)
|
|
}
|
|
s.Name = name
|
|
return nil
|
|
|
|
case yaml.MappingNode:
|
|
var tmp struct {
|
|
Group *OutputGroup
|
|
GitLab *OutputGitLab `yaml:"gitlab"`
|
|
}
|
|
if err := node.Decode(&tmp); err != nil {
|
|
return errors.NewTaskfileDecodeError(err, node)
|
|
}
|
|
switch {
|
|
case tmp.Group != nil && tmp.GitLab != nil:
|
|
return errors.NewTaskfileDecodeError(nil, node).WithMessage(`output style cannot set both "group" and "gitlab"`)
|
|
case tmp.Group != nil:
|
|
*s = Output{
|
|
Name: "group",
|
|
Group: *tmp.Group,
|
|
}
|
|
return nil
|
|
case tmp.GitLab != nil:
|
|
*s = Output{
|
|
Name: "gitlab",
|
|
GitLab: *tmp.GitLab,
|
|
}
|
|
return nil
|
|
default:
|
|
return errors.NewTaskfileDecodeError(nil, node).WithMessage(`output style must have the "group" or "gitlab" key when in mapping form`)
|
|
}
|
|
}
|
|
|
|
return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("output")
|
|
}
|
|
|
|
// OutputGroup is the style options specific to the Group style.
|
|
type OutputGroup struct {
|
|
Begin, End string
|
|
ErrorOnly bool `yaml:"error_only"`
|
|
}
|
|
|
|
// IsSet returns true if and only if a custom output style is set.
|
|
func (g *OutputGroup) IsSet() bool {
|
|
if g == nil {
|
|
return false
|
|
}
|
|
return g.Begin != "" || g.End != ""
|
|
}
|
|
|
|
// OutputGitLab is the style options specific to the GitLab style.
|
|
type OutputGitLab struct {
|
|
Collapsed bool
|
|
ErrorOnly bool `yaml:"error_only"`
|
|
}
|