recipe

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YAMLExtension          = ".yml"
	RecipeFileName         = "recipe"
	RecipeTemplatesDirName = "templates"
	RecipeTestsDirName     = "tests"
	RecipeTestMetaFileName = "test"
	RecipeTestFilesDirName = "files"
	IgnoreFileName         = ".jalapenoignore"
)
View Source
const (
	SaucesFileName = "sauces"

	// The directory name which contains all Jalapeno related files
	// in the project directory
	SauceDirName = ".jalapeno"
)

Variables

View Source
var (
	ErrNoTestsSpecified    error = errors.New("no tests specified")
	ErrTestWrongFileAmount       = errors.New("recipe rendered different amount of files than expected")
	ErrTestMissingFile           = errors.New("recipe did not render file which was expected")
	ErrTestContentMismatch       = errors.New("the contents of the files did not match")
)
View Source
var (
	ErrSauceNotFound = errors.New("sauce not found")
)
View Source
var TestID uuid.UUID = uuid.Must(uuid.FromString("12345678-1234-5678-1234-567812345678"))

Random hardcoded UUID

Functions

This section is empty.

Types

type File added in v0.1.0

type File struct {
	Checksum string `yaml:"checksum"` // e.g. "sha256:xxxxxxxxx" w. default algo
	Content  []byte `yaml:"-"`
}

type Metadata

type Metadata struct {
	// Version of the recipe metadata API schema. Currently should have value "v1"
	APIVersion string `yaml:"apiVersion"`

	// Name of the recipe
	Name string `yaml:"name"`

	// Version of the recipe. Must be valid [semver](https://semver.org/)
	Version string `yaml:"version"`

	// Description of what the recipe does
	Description string `yaml:"description"`

	// A list of URLs to source code for this recipe
	Sources []string `yaml:"sources,omitempty"`

	// A message which will be showed to an user after a succesful recipe execution.
	// Can be used to guide the user what should be done next in the project directory.
	InitHelp string `yaml:"initHelp,omitempty"`

	// Glob patterns for ignoring generated files from future recipe upgrades. Ignored
	// files will not be regenerated even if their templates change in future versions
	// of the recipe.
	IgnorePatterns []string `yaml:"ignorePatterns,omitempty"`
}

func (*Metadata) Validate

func (m *Metadata) Validate() error

type Recipe

type Recipe struct {
	Metadata  `yaml:",inline"`
	Variables []Variable        `yaml:"vars,omitempty"`
	Templates map[string][]byte `yaml:"-"`
	Tests     []Test            `yaml:"-"`
	// contains filtered or unexported fields
}

func LoadRecipe added in v0.1.0

func LoadRecipe(path string) (*Recipe, error)

LoadRecipe reads a recipe from a given path

func NewRecipe added in v0.1.0

func NewRecipe() *Recipe

func (*Recipe) Execute added in v0.1.0

func (re *Recipe) Execute(values VariableValues, id uuid.UUID) (*Sauce, error)

Execute executes the recipe and returns a sauce

func (*Recipe) RunTests added in v0.1.0

func (re *Recipe) RunTests() []error

func (*Recipe) Save

func (re *Recipe) Save(dest string) error

Save saves recipe to given destination

func (*Recipe) SetEngine added in v0.1.0

func (re *Recipe) SetEngine(e RenderEngine)

func (*Recipe) Validate

func (re *Recipe) Validate() error

type RecipeConflict added in v0.1.0

type RecipeConflict struct {
	Path           string
	Sha256Sum      string
	OtherSha256Sum string
}

type RenderEngine

type RenderEngine interface {
	Render(templates map[string][]byte, values map[string]interface{}) (map[string][]byte, error)
}

type Sauce added in v0.1.0

type Sauce struct {
	Recipe Recipe          `yaml:",inline"`
	Values VariableValues  `yaml:"values,omitempty"`
	Files  map[string]File `yaml:"files"`

	// Random unique ID whose value is determined on first render and stays the same
	// on subsequent re-renders (upgrades) of the sauce. Can be used for example as a seed
	// for template random functions to provide same result on each template
	ID uuid.UUID `yaml:"id"`

	// CheckFrom defines the repository where updates should be checked for the recipe
	CheckFrom string `yaml:"from,omitempty"`
}

Sauce represents a rendered recipe

func LoadSauce added in v0.1.0

func LoadSauce(projectDir, recipeName string) (*Sauce, error)

func LoadSauces added in v0.1.0

func LoadSauces(projectDir string) ([]*Sauce, error)

Load all sauces from a project directory. Returns empty slice if the project directory did not contain any sayces

func NewSauce added in v0.1.0

func NewSauce() *Sauce

func (*Sauce) Conflicts added in v0.1.0

func (s *Sauce) Conflicts(other *Sauce) []RecipeConflict

Check if the recipe conflicts with another recipe. Recipes conflict if they touch the same files.

func (*Sauce) Save added in v0.1.0

func (s *Sauce) Save(dest string) error

Save saves sauce to given destination

func (*Sauce) Validate added in v0.1.0

func (s *Sauce) Validate() error

type Test added in v0.1.0

type Test struct {
	// Name of the test case. Defined by directory name of the test case
	Name string `yaml:"-"`

	// Values to use to render the recipe templates
	Values VariableValues `yaml:"values"`

	// Snapshots of the rendered templates which were rendered with the values specified in the test
	Files map[string][]byte `yaml:"-"`

	// If true, test will not fail if the templates generates more files than the test specifies
	IgnoreExtraFiles bool `yaml:"ignoreExtraFiles"`
}

func (*Test) Validate added in v0.1.0

func (t *Test) Validate() error

type Variable

type Variable struct {
	// The name of the variable. It is also used as unique identifier.
	Name        string `yaml:"name"`
	Description string `yaml:"description,omitempty"`

	// Default value of the variable
	Default string `yaml:"default,omitempty"`

	// If set to true, the prompt will be yes/no question, and the value type will be boolean
	Confirm bool `yaml:"confirm,omitempty"`

	// If set to true, the variable can be left empty
	Optional bool `yaml:"optional,omitempty"`

	// The user selects the value from a list of options
	Options []string `yaml:"options,omitempty"`

	// Validators for the variable
	Validators []VariableValidator `yaml:"validators,omitempty"`

	// Makes the variable conditional based on the result of the expression. The result of the evaluation needs to be a boolean value. Uses https://github.com/antonmedv/expr
	If string `yaml:"if,omitempty"`

	// Set the variable as a table type with columns defined by this property
	Columns []string `yaml:"columns,omitempty"`
}

func (*Variable) Validate

func (v *Variable) Validate() error

type VariableValidator added in v0.1.12

type VariableValidator struct {
	// Regular expression pattern to match the input against
	Pattern string `yaml:"pattern,omitempty"`

	// If the regular expression validation fails, this help message will be shown to the user
	Help string `yaml:"help,omitempty"`

	// Apply the validator to a column if the variable type is table
	Column string `yaml:"column,omitempty"`
}

func (*VariableValidator) CreateValidatorFunc added in v0.1.12

func (r *VariableValidator) CreateValidatorFunc() func(input string) error

type VariableValues

type VariableValues map[string]interface{}

VariableValues stores values for each variable

Jump to

Keyboard shortcuts

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