taskrunner

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 21 Imported by: 2

README

Taskrunner

Handling CI-related tasks such as building, testing, and deploying can be automated using bash scripts, but these can quickly get messy. Managing multiple processes, handling cleanup, aborting on failure, adding pretty colored output, and more can lead to complex bash code. That's why Taskrunner was created: a simple, open source library to replace bash scripts with cleaner, more maintainable code written in Go.

Installation
go get github.com/quollix/taskrunner
Usage Example

var ( 
    backendDir = "../backend"
    frontendDir = "../frontend"
    acceptanceTestsDir = "../acceptance"
)

func TestFrontend() {
    tr := taskrunner.GetTaskRunner()
	
    tr.Log.Info("Testing Integrated Components")
    defer tr.Cleanup() // shuts down the daemon processes at the end
    tr.Cmd().Dir(backendDir).Run("go build")
    tr.Cmd().Dir(backendDir).AsDaemon("backend").Run("./backend")
    tr.WaitUntilPortIsReady("8080")

    tr.Cmd().Dir(frontendDir).Run("npm install")
    tr.Cmd().Dir(frontendDir).Env("VITE_APP_PROFILE", "TEST").AsDaemon("frontend").Run("npm run serve")
    tr.WaitForWebPageToBeReady("http://localhost:8081/")
    tr.Cmd().Dir(acceptanceTestsDir).Env("CYPRESS_PROFILE", "TEST").Run(cypressCommand)

    output := tr.Cmd().AllowFail().Run("go test ./...").Output()
    tr.Log.Info("test output:\n%s", output)
}

The idea is to write simple functions like this and build a CLI tool, e.g., by using cobra, to call these functions. The final use of the CLI tool might look like this:

go build
./my-task-runner test frontend

This approach helps you create a modern and scalable CI infrastructure.

It is good practice for your CLI program to print a final success line after the root command has completed successfully:

tr.Log.Info("final exit code: 0")

CI logs can become large, and a predictable final line makes it easy for developers to see whether the overall run succeeded. Taskrunner itself prints the matching non-zero final exit code line when it exits through ExitWithError(), so the failure case is already covered by taskrunner.

Contributing

Please read the Community articles for more information on how to contribute to the project and interact with others.

License

This project is licensed under the Apache License 2.0. See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command added in v0.1.8

type Command struct {
	// contains filtered or unexported fields
}

func (*Command) AllowFail added in v0.1.9

func (c *Command) AllowFail() *Command

func (*Command) AsDaemon added in v0.1.8

func (c *Command) AsDaemon(name string) *Command

func (*Command) Dir added in v0.1.8

func (c *Command) Dir(dir string) *Command

func (*Command) Env added in v0.1.8

func (c *Command) Env(key, value string) *Command

func (*Command) Quiet added in v1.2.1

func (c *Command) Quiet() *Command

func (*Command) Run added in v0.1.8

func (c *Command) Run(format string, args ...any) *CommandResult

type CommandResult added in v1.0.0

type CommandResult struct {
	// contains filtered or unexported fields
}

func (*CommandResult) Output added in v1.0.0

func (r *CommandResult) Output() string

type Config

type Config struct {
	CleanupOnFailure            bool
	CleanupFunc                 func()
	DefaultEnvironmentVariables []string

	DefaultWaitTimeout int
	// contains filtered or unexported fields
}

type TaskRunner

type TaskRunner struct {
	Config *Config
	File   fileOps
	Log    logger
	// contains filtered or unexported fields
}

func GetTaskRunner

func GetTaskRunner() *TaskRunner

func (*TaskRunner) Cleanup

func (t *TaskRunner) Cleanup()

func (*TaskRunner) Cmd added in v0.1.8

func (t *TaskRunner) Cmd() *Command

func (*TaskRunner) EnableAbortForKeystrokeControlPlusC

func (t *TaskRunner) EnableAbortForKeystrokeControlPlusC()

func (*TaskRunner) ExitWithError

func (t *TaskRunner) ExitWithError()

func (*TaskRunner) PromptForContinuation

func (t *TaskRunner) PromptForContinuation(prompt string)

func (*TaskRunner) WaitForWebPageToBeReady

func (t *TaskRunner) WaitForWebPageToBeReady(targetUrl string)

func (*TaskRunner) WaitUntilPortIsReady

func (t *TaskRunner) WaitUntilPortIsReady(port string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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