taskrunner

package module
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: 0BSD Imports: 20 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.

Note: API is not stable yet.

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.

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 a permissive open source license, the 0BSD License. See the LICENSE file 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) Output added in v0.1.9

func (c *Command) Output() string

func (*Command) Run added in v0.1.8

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

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)

Jump to

Keyboard shortcuts

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