smush

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: MIT Imports: 12 Imported by: 0

README

Smush

Smush together commands and run them in parallel. If any of it fails, Smush will wait for all of the commands to finish, then report non-zero exit code.

Usage

Smush configuration can be written in YAML.

commands:
  - name: ruff
    runs: poetry run ruff
  - name: prettier
    runs: npx prettier --check .

And then tell Smush where to find that file:

smush -c path-to-config.yaml

Why?

GitHub Actions is a powerful tool that makes continuous integration (CI) setup easy for many projects. Projects often have several linters to run in CI and they are significantly faster than, say, running tests. Typically, this ends up with either of the following scenario.

  1. Consolidate the linters into a single job that run sequentially. The downside here is if the first one fails, you won't know if the rest passes or not until you fix that first one.
  2. Run in separate jobs, such that if you have N linters, you will have to duplicate setup (e.g. installing compiler and dependencies) by N times. Not only tt's wasteful, but it also eats up GitHub Action credits.[^1]

Option 2 is the good stuff, but the cost adds up quickly as the number of contributor grows.

gantt
    title Parallel without Smush (3 minute credit per run)
    dateFormat  HH:mm:ss
    axisFormat  %M:%S
    section Linter 1
    Installing compiler     :a, 00:00:00, 20s
    Installing dependencies :b, after a , 10s
    Linter 1 ¯\_(ツ)_/¯      :after b, 1s
    section Linter 2
    Installing compiler     :a, 00:00:00, 20s
    Installing dependencies :b, after a , 10s
    Linter 2 ¯\_(ツ)_/¯     :after b, 2s
    section Linter 3
    Installing compiler     :a, 00:00:00, 20s
    Installing dependencies :b, after a , 10s
    Linter 3 ¯\_(ツ)_/¯     :after b, 3s

With Smush, you can smush (promise it's the last time) both approaches together by creating one job for all linters and delegate parallelism to Smush.

gantt
    title Parallel on 2-core machine with Smush (1 minute credit)
    dateFormat  HH:mm:ss
    axisFormat  %M:%S
    section Linters
    Installing compiler     :a, 00:00:00, 20s
    Installing dependencies :b, after a , 10s
    Linter 1                :c, after b, 1s
    Linter 2                :after b, 2s
    Linter 1                :after c, 3s

A longer story of how this project came to be was posted on Wilson's site.

[^1]: GitHub Actions rounds credit consumption to the nearest whole minute.

Documentation

Index

Constants

View Source
const NewLineByte = byte('\n')

Variables

This section is empty.

Functions

func RunAll

func RunAll(ctx context.Context, maxProcs int64, commands []*Command) error

Types

type Command

type Command struct {
	Name string `yaml:"name"`
	Runs string `yaml:"runs"`
	// contains filtered or unexported fields
}

func (*Command) Label

func (c *Command) Label() string

func (*Command) Run

func (c *Command) Run(ctx context.Context, stdout, stderr io.Writer) error

type Config

type Config struct {
	Commands []*Command `yaml:"commands"`
}

func ReadConfig

func ReadConfig(r io.Reader) (*Config, error)

type Failure added in v0.2.0

type Failure struct {
	Command *Command
	Error   error
	Index   int
}

type Logger

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

func NewLogger

func NewLogger(w io.Writer, prefix string, colorIndex int) *Logger

func (*Logger) Write

func (l *Logger) Write(p []byte) (n int, err error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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