vai

package module
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

README

vai

GitHub Tag GitHub go.mod Go version codecov Go Report Card GitHub License FOSSA Status

A simple task runner. Imagine GitHub actions and Makefile had a baby.

[!CAUTION] This project is still in its early stages. Expect breaking changes.

Installation

go install github.com/noxsios/vai/cmd/vai@latest

or if you like to live dangerously:

go install github.com/noxsios/vai/cmd/vai@main

Example

demo

Checkout more examples in the docs.

View CLI usage w/ vai --help

Schema Validation

Enabling schema validation in VSCode:

    "yaml.schemas": {
        "https://raw.githubusercontent.com/noxsios/vai/main/vai.schema.json": "vai.yaml",
    },

Per file basis:

# yaml-language-server: $schema=https://raw.githubusercontent.com/noxsios/vai/main/vai.schema.json

FOSSA Status

Documentation

Overview

Package vai provides a simple task runner.

Index

Constants

View Source
const CacheEnvVar = "VAI_CACHE"

CacheEnvVar is the environment variable for the cache directory.

View Source
const DefaultFileName = "vai.yaml"

DefaultFileName is the default file name

View Source
const DefaultTaskName = "default"

DefaultTaskName is the default task name

Variables

View Source
var EnvVariablePattern = regexp.MustCompile("^[a-zA-Z_]+[a-zA-Z0-9_]*$")

EnvVariablePattern is a regular expression for valid environment variable names

View Source
var TaskNamePattern = regexp.MustCompile("^[_a-zA-Z][a-zA-Z0-9_-]*$")

TaskNamePattern is a regular expression for valid task names, it is also used for step IDs

Functions

func ExecuteUses added in v0.1.6

func ExecuteUses(ctx context.Context, store *uses.Store, u string, with With, prev string, dry bool) error

ExecuteUses runs a task from a remote workflow source.

func ParseOutput added in v0.1.10

func ParseOutput(r io.ReadSeeker) (map[string]string, error)

ParseOutput parses the output file of a step

Matches behavior of GitHub Actions.

https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings

func Run

func Run(ctx context.Context, store *uses.Store, wf Workflow, taskName string, outer With, origin string, dry bool) error

Run executes a task in a workflow with the given inputs.

For all `uses` steps, this function will be called recursively.

func Validate

func Validate(wf Workflow) error

Validate validates a workflow

func WorkFlowSchema

func WorkFlowSchema() *jsonschema.Schema

WorkFlowSchema returns a JSON schema for a vai workflow

Types

type CommandOutputs

type CommandOutputs map[string]map[string]any

CommandOutputs is a map of step IDs to their outputs.

type Step

type Step struct {
	// Run is the command/script to run
	Run string `json:"run,omitempty"`
	// Eval is an expression to evaluate with tengo
	Eval string `json:"eval,omitempty"`
	// Uses is a reference to another task
	Uses string `json:"uses,omitempty"`
	// With is a map of additional parameters for the step/task call
	With `json:"with,omitempty"`
	// ID is a unique identifier for the step
	ID string `json:"id,omitempty"`
	// Name is a human-readable name for the step
	Name string `json:"name,omitempty"`
}

Step is a single step in a task

While a step can have any combination of `run`, `eval`, and `uses` fields, only one of them should be set at a time.

This is enforced by JSON schema validation.

func (Step) JSONSchemaExtend

func (Step) JSONSchemaExtend(schema *jsonschema.Schema)

JSONSchemaExtend extends the JSON schema for a step

type Task

type Task []Step

Task is a list of steps

type With

type With map[string]WithEntry

With is a map of string keys and WithEntry values used to pass parameters to called tasks and within steps

Each key will be mapped to an equivalent environment variable when the command is run. eg. `with: {foo: bar}` will be passed as `foo=bar` to the command.

func PerformLookups

func PerformLookups(ctx context.Context, outer, local With, previousOutputs CommandOutputs) (With, error)

PerformLookups evaluates the expressions in the local With map

type WithEntry

type WithEntry any

WithEntry is a single entry in a With map

type Workflow

type Workflow map[string]Task

Workflow is a map of tasks, where the key is the task name

This is the main structure that represents `vai.yaml` and other vai workflow files

func Read

func Read(r io.Reader) (Workflow, error)

Read reads a workflow from a file

func ReadAndValidate

func ReadAndValidate(r io.Reader) (Workflow, error)

ReadAndValidate reads and validates a workflow

func (Workflow) Find

func (wf Workflow) Find(call string) (Task, bool)

Find returns a task by name

func (Workflow) OrderedTaskNames added in v0.1.8

func (wf Workflow) OrderedTaskNames() []string

OrderedTaskNames returns a list of task names in alphabetical order

The default task is always first

Directories

Path Synopsis
cmd
Package cmd provides the root command for the vai CLI.
Package cmd provides the root command for the vai CLI.
vai command
Package main is the entry point for the application
Package main is the entry point for the application
Package main provides the entry point for the application.
Package main provides the entry point for the application.
Package modv provides extra tengo modules for vai.
Package modv provides extra tengo modules for vai.
Package uses provides a cache+clients for storing and retrieving remote workflows.
Package uses provides a cache+clients for storing and retrieving remote workflows.

Jump to

Keyboard shortcuts

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