Documentation
¶
Overview ¶
Package taskutil contains type definitions and functionality for working with Tasks & Tools across the oscar codebase.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFileTypeListerCommand ¶
GetFileTypeListerCommand takes a ripgrep-known file type, and returns a string (to be used as an arg after `bash -c`) representing a command & its args to find matching files. ripgrep is used as the default file-finder across the codebase because not only is it fast, but it also supports files like `.gitignore` without any extra configuration.
func InitSystem ¶
InitSystem runs setup & checks against the host itself, so that oscar can run.
func RunCommand ¶
RunCommand takes a string slice containing a command & its args to run, and returns a consistent error message in case of failure. It also returns the command output, in case the caller needs to parse it on their own.
func RunDurationString ¶
RunDurationString returns a calculated duration used to indicate how long a particular Task (or set of Tasks) took to run.
Types ¶
type Repo ¶
type Repo struct {
HasGo bool
HasPython bool
HasShell bool
HasTerraform bool
HasContainerfile bool
HasYaml bool
HasMarkdown bool
}
A Repo stores information about the contents of the repository being run against.
type Run ¶
type Run struct {
// The "type" of Run as an informative string, i.e. "CI", "Deliver", etc. Used in
// banner-printing in [Run.PrintRunTypeBanner].
Type string
// A timestamp for storing when the overall run started.
StartTime time.Time
// Keeps track of all task failures.
Failures []string
}
A Run holds metadata about an instance of an oscar subcommand run, e.g. a list of Tasks for the `ci` subcommand.
func (Run) PrintRunTypeBanner ¶
func (run Run) PrintRunTypeBanner()
PrintRunTypeBanner prints a banner about the type of Run underway.
func (Run) PrintTaskBanner ¶
PrintTaskBanner prints a banner about the Task being run.
func (Run) PrintTaskMapBanner ¶
PrintTaskMapBanner prints a banner about the TaskMap being run.
func (Run) ReportFailure ¶
ReportFailure prints information about the failure of a Run. It takes an `error` arg in case the caller is expecting to return a joined error because of e.g. deferred calls or later-checked errors that an outer variable already holds.
func (Run) ReportSuccess ¶
func (run Run) ReportSuccess()
ReportSuccess prints information about the success of a Run.
type TaskMap ¶
TaskMap aliases a map of a Task's language/tooling name to its list of Tasks.
func (TaskMap) SortedKeys ¶
SortedKeys sorts the keys of the TaskMap. Useful for iterating through Tasks in a predictable order during runs.
type Tasker ¶
type Tasker interface {
// InfoText should return a human-readable display string that describes the task, e.g. "Run
// tests".
InfoText() string
// Exec should perform the actual task's actions.
Exec(ctx context.Context) error
// Post should perform any post-run actions for the task, if necessary.
Post(ctx context.Context) error
}
Tasker defines the method set for working with metadata for a given CI Task.
type Tool ¶
type Tool struct {
// The list of command & arguments to run during [Tasker.Exec].
RunArgs []string
// The path to the tool's config file, if it has one to use.
ConfigFilePath string
}
A Tool defines information about a tool used for running oscar's tasks. A Tool should be defined if a language etc. cannot perform the task itself. For example, you would not need a Tool to represent a task that runs "go test", but you *would* need a tool to represent a task that runs the external "staticcheck" linter for Go.
func (Tool) RenderRunCommandArgs ¶
RenderRunCommandArgs uses [Tool.RunArgs] and does naive templating to replace certain values before being used.
This is useful because when instantiating [Tasker]s, sometimes the fields need to be self-referential within the struct. For example, if a [Tool.RunArgs] needs to specify a config file path, but it can't know that value until instantiation (even though it's likely defined right below it in [Tool.ConfigFilePath]), you can write the `RunArgs` to have a `{{ConfigFilePath}}` placeholder that will be interpolated when calling this function.