taskutil

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 14 Imported by: 0

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

func GetFileTypeListerCommand(fileType string) string

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

func InitSystem(ctx context.Context) error

InitSystem runs setup & checks against the host itself, so that oscar can run.

func RunCommand

func RunCommand(ctx context.Context, cmdArgs []string) (string, error)

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

func RunDurationString(t time.Time) string

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.

func NewRepo

func NewRepo(ctx context.Context) (Repo, error)

NewRepo returns a populated Repo.

func (Repo) String

func (repo Repo) String() string

String implements the fmt.Stringer interface.

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 NewRun

func NewRun(ctx context.Context, runType string) (Run, error)

NewRun returns a populated Run.

func (Run) PrintRunTypeBanner

func (run Run) PrintRunTypeBanner()

PrintRunTypeBanner prints a banner about the type of Run underway.

func (Run) PrintTaskBanner

func (run Run) PrintTaskBanner(task Tasker)

PrintTaskBanner prints a banner about the Task being run.

func (Run) PrintTaskMapBanner

func (run Run) PrintTaskMapBanner(lang string)

PrintTaskMapBanner prints a banner about the TaskMap being run.

func (Run) ReportFailure

func (run Run) ReportFailure(err error) error

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

type TaskMap map[string][]Tasker

TaskMap aliases a map of a Task's language/tooling name to its list of Tasks.

func (TaskMap) SortedKeys

func (tm TaskMap) SortedKeys() []string

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

func (t Tool) RenderRunCommandArgs() []string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL