build

package module
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 20 Imported by: 5

README

Build

Yet another implementation of Makefile concept in go. Advantages over all the other available packages:

  • go only, compile and commit to your repo
  • no magic command discovery based on go source code, you explicitly declare paths and functions for your commands
  • bash autocompletion supported
  • command functions are executed using IoC container so they may receive any interfaces required to do the job

Example

Take a look at example/main.go

First compilation

This build system is written in pure go so you have to compile it using go build before first usage. You may write little bash wrapper which compiles build if binary doesn't exist or do it manually once and commit to your repo (not recommended).

Taking this into consideration one of the commands available in this executable should be responsible for compiling build itself so you don't need to use go build later on when build is modified.

Autocompletion

build supports autocompletion natively. To use it add this line to your ~/.bashrc:

complete -o nospace -C <path-to-your-build-binary> <alias-used-to-run-build>

Assuming your build executable file is named build and is available in your PATH the exact complete is this:

complete -o nospace -C build build

Executing commands

Commands are organised in paths similar to the one in normal filesystem. Some examples how commands may be structured:

build tools/apiClient
build deploy/db
build tests/backend/web-server
build lint

You may specify many commands at once:

build tests deploy

They are executed in specified order. This will save some time if both commands execute same dependencies.

Dependencies

Every command may specify dependencies - other commands which have to finish before the actual one may continue. It allows you to move some code common to many commands to another function.

If many commands require the same dependency, it is executed once.

Dependencies are executed one by one in order.

If circular dependency is detected error is raised.

Errors

build always panics on first failure.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, name string, executor Executor) error

Do receives configuration and runs commands

func EnsureTool added in v1.5.1

func EnsureTool(ctx context.Context, tool Tool) error

EnsureTool ensures that tool exists, if not it is installed

func GetName added in v1.5.1

func GetName(ctx context.Context) string

GetName returns name passed to `Do` function

func InstallTools added in v1.5.1

func InstallTools(ctx context.Context, tools ...map[string]Tool) error

InstallTools installs tools

Types

type CommandFunc

type CommandFunc func(ctx context.Context) error

CommandFunc represents executable command

type DepsFunc

type DepsFunc func(deps ...interface{})

DepsFunc represents function for executing dependencies

type Executor

type Executor interface {
	// Paths lists all available command paths
	Paths() []string

	// Execute executes commands by their paths
	Execute(ctx context.Context, name string, paths []string) error
}

Executor defines interface of command executor

func NewIoCExecutor

func NewIoCExecutor(commands map[string]interface{}, c *ioc.Container) Executor

NewIoCExecutor returns new executor using IoC container to resolve parameters of commands

type Tool added in v1.5.1

type Tool struct {
	// Name is the name of the tool
	Name string

	// Version is the version of the tool
	Version string

	// URL is the url to the archive containing the tool
	URL string

	// Hash is the hash of the downloade file
	Hash string

	// Binaries is the list of relative paths to binaries to install in local bin folder
	Binaries []string
}

Tool represents the tool to be required by the build system

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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