Documentation ¶
Index ¶
- Constants
- Variables
- func GitRepoRoot(dir string) (string, error)
- type Blob
- type BlobWalkCallback
- type BuildResult
- type BuildSummary
- type Cmd
- type CmdFailure
- type CmdOptions
- type CmdStage
- type CmdStageCallback
- type Commit
- type DiffDelta
- type Discover
- type FilterOptions
- type KVP
- type Log
- type Manifest
- type ManifestBuilder
- type Module
- func (a *Module) Build() map[string]*Cmd
- func (a *Module) Commands() map[string]*UserCmd
- func (a *Module) FileDependencies() []string
- func (a *Module) Hash() string
- func (a *Module) Name() string
- func (a *Module) Path() string
- func (a *Module) Properties() map[string]interface{}
- func (a *Module) RequiredBy() Modules
- func (a *Module) Requires() Modules
- func (a *Module) Version() string
- type Modules
- type ProcessManager
- type Reducer
- type Reference
- type Repo
- type RunResult
- type Spec
- type System
- type TemplateData
- type UserCmd
- type WorkspaceManager
Constants ¶
const ( // LogLevelNormal logs info and above LogLevelNormal = iota // LogLevelDebug logs debug and above LogLevelDebug )
const ( // ErrClassNone Not specified ErrClassNone = iota // ErrClassUser is a user error that can be corrected ErrClassUser // ErrClassInternal is an internal error potentially due to a bug ErrClassInternal )
const ( // CmdStageBeforeBuild is the stage before executing module build command CmdStageBeforeBuild = iota // CmdStageAfterBuild is the stage after executing the module build command CmdStageAfterBuild // CmdStageSkipBuild is when module building is skipped due to lack of matching building command CmdStageSkipBuild // CmdStageFailedBuild is when module command is failed CmdStageFailedBuild )
Variables ¶
var NoFilter = &FilterOptions{}
NoFilter is built-in filter that represents no filtering
Functions ¶
func GitRepoRoot ¶
GitRepoRoot returns path to a git repo reachable from the specified directory. If the specified directory itself is not a git repo, this function searches for it in the parent directory path.
Types ¶
type Blob ¶
type Blob interface { // ID of the blob. ID() string // Name of the blob. Name() string // Path (relative) to the blob. Path() string //String returns a printable id. String() string }
Blob stored in git.
type BlobWalkCallback ¶
BlobWalkCallback used for discovering blobs in a commit tree.
type BuildResult ¶
type BuildResult struct { // Module of the build result Module *Module }
BuildResult is summary for a single module build
type BuildSummary ¶
type BuildSummary struct { // Manifest used to trigger the build Manifest *Manifest // Completed list of the modules built. This list does not // include the modules that were skipped due to // the unavailability of a build command for the // host platform. Completed []*BuildResult // Skipped modules due to the unavailability of a build command for // the host platform Skipped []*Module }
BuildSummary is a summary of a successful build.
type CmdFailure ¶
CmdFailure contains the failures occurred while running a user defined command.
type CmdOptions ¶
type CmdOptions struct { Stdin io.Reader Stdout, Stderr io.Writer Callback CmdStageCallback FailFast bool }
CmdOptions defines various options required by methods executing user defined commands.
func CmdOptionsWithStdIO ¶
func CmdOptionsWithStdIO(callback CmdStageCallback) *CmdOptions
CmdOptionsWithStdIO creates an instance of CmdOptions with its streams pointing to std io streams.
type CmdStageCallback ¶
CmdStageCallback is the callback function used to notify various build stages
type Commit ¶
Commit in the repo. All commit based APIs in Repo interface accepts this interface. It gives the implementations the ability to optimise the access to commits. For example, a libgit2 based Repo implementation we use by default caches the access to commit tree.
type DiffDelta ¶
type DiffDelta struct { // NewFile path of the delta NewFile string // OldFile path of the delta OldFile string }
DiffDelta is a single delta in a git diff.
type Discover ¶
type Discover interface { // ModulesInCommit walks the git tree at a specific commit looking for // directories with .mbt.yml file. Returns discovered Modules. ModulesInCommit(commit Commit) (Modules, error) // ModulesInWorkspace walks current workspace looking for // directories with .mbt.yml file. Returns discovered Modules. ModulesInWorkspace() (Modules, error) }
Discover module metadata for various conditions
func NewDiscover ¶
NewDiscover creates an instance of standard discover implementation.
type FilterOptions ¶
FilterOptions describe how to filter the modules in a manifest
func ExactMatchDependentsFilter ¶
func ExactMatchDependentsFilter(name string) *FilterOptions
ExactMatchDependentsFilter is a helper to create an exact match FilterOptions
func ExactMatchFilter ¶
func ExactMatchFilter(name string) *FilterOptions
ExactMatchFilter is a helper to create an exact match FilterOptions
func FuzzyDependentsFilter ¶
func FuzzyDependentsFilter(name string) *FilterOptions
FuzzyDependentsFilter is a helper to create a fuzzy match FilterOptions
func FuzzyFilter ¶
func FuzzyFilter(name string) *FilterOptions
FuzzyFilter is a helper to create a fuzzy match FilterOptions
type Log ¶
type Log interface { Info(args ...interface{}) Infof(format string, args ...interface{}) Warn(args ...interface{}) Warnf(format string, args ...interface{}) Error(error) Errorf(format string, args ...interface{}) Debug(format string, args ...interface{}) }
Log used to write system events
type Manifest ¶
Manifest represents a collection modules in the repository.
func (*Manifest) ApplyFilters ¶
func (m *Manifest) ApplyFilters(filterOptions *FilterOptions) (*Manifest, error)
ApplyFilters will filter the modules in the manifest to the ones that matches the specified filter. If filter is not specified, original manifest is returned.
func (*Manifest) FilterByName ¶
func (m *Manifest) FilterByName(filterOptions *FilterOptions) *Manifest
FilterByName reduces the modules in a Manifest to the ones that are matching the terms specified in filter. Multiple terms can be specified as a comma separated string. If fuzzy argument is true, comparison is a case insensitive subsequence comparison. Otherwise, it's a case insensitive exact match.
type ManifestBuilder ¶
type ManifestBuilder interface { // ByDiff creates the manifest for diff between two commits ByDiff(from, to Commit) (*Manifest, error) // ByPr creates the manifest for diff between two branches ByPr(src, dst string) (*Manifest, error) // ByCommit creates the manifest for the specified commit ByCommit(sha Commit) (*Manifest, error) // ByCommitContent creates the manifest for the content of the // specified commit. ByCommitContent(sha Commit) (*Manifest, error) // ByBranch creates the manifest for the specified branch ByBranch(name string) (*Manifest, error) // ByCurrentBranch creates the manifest for the current branch ByCurrentBranch() (*Manifest, error) // ByWorkspace creates the manifest for the current workspace ByWorkspace() (*Manifest, error) // ByWorkspaceChanges creates the manifest for the changes in workspace ByWorkspaceChanges() (*Manifest, error) }
ManifestBuilder builds Manifest for various conditions
func NewManifestBuilder ¶
func NewManifestBuilder(repo Repo, reducer Reducer, discover Discover, log Log) ManifestBuilder
NewManifestBuilder creates a new ManifestBuilder
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module represents a single module in the repository.
func (*Module) FileDependencies ¶
FileDependencies returns the list of file dependencies this module has.
func (*Module) Properties ¶
Properties returns the custom properties in the configuration.
func (*Module) RequiredBy ¶
RequiredBy returns an array of modules requires this module.
type Modules ¶
type Modules []*Module
Modules is an array of Module.
func (Modules) GroupedSerializeAsDot ¶
GroupedSerializeAsDot converts specified modules into a dot graph that can be used for visualization with gv package.
This variant groups impacted modules in red, while plotting the rest of the graph in powderblue
func (Modules) SerializeAsDot ¶
SerializeAsDot converts specified modules into a dot graph that can be used for visualization with gv package.
type ProcessManager ¶
type ProcessManager interface { // Exec runs an external command in the context of a module in a manifest. // Following actions are performed prior to executing the command: // - Current working directory of the target process is set to module path // - Initialises important information in the target process environment Exec(manifest *Manifest, module *Module, options *CmdOptions, command string, args ...string) error }
ProcessManager manages the execution of build and user defined commands.
func NewProcessManager ¶
func NewProcessManager(log Log) ProcessManager
NewProcessManager creates an instance of ProcessManager.
type Reference ¶
Reference to a tree in the repository. For example, if you consider a git repository this could be pointing to a branch, tag or commit.
type Repo ¶
type Repo interface { // GetCommit returns the commit object for the specified SHA. GetCommit(sha string) (Commit, error) // Path of the repository. Path() string // Diff gets the diff between two commits. Diff(a, b Commit) ([]*DiffDelta, error) // DiffMergeBase gets the diff between the merge base of from and to and, to. // In other words, diff contains the deltas of changes occurred in 'to' commit tree // since it diverged from 'from' commit tree. DiffMergeBase(from, to Commit) ([]*DiffDelta, error) // DiffWorkspace gets the changes in current workspace. // This should include untracked changes. DiffWorkspace() ([]*DiffDelta, error) // Changes returns a an array of DiffDelta objects representing the changes // in the specified commit. // Return an empty array if the specified commit is the first commit // in the repo. Changes(c Commit) ([]*DiffDelta, error) // WalkBlobs invokes the callback for each blob reachable from the commit tree. WalkBlobs(a Commit, callback BlobWalkCallback) error // BlobContents of specified blob. BlobContents(blob Blob) ([]byte, error) // BlobContentsByPath gets the blob contents from a specific git tree. BlobContentsFromTree(commit Commit, path string) ([]byte, error) // EntryID of a git object in path. // ID is resolved from the commit tree of the specified commit. EntryID(commit Commit, path string) (string, error) // BranchCommit returns the last commit for the specified branch. BranchCommit(name string) (Commit, error) // CurrentBranch returns the name of current branch. CurrentBranch() (string, error) // CurrentBranchCommit returns the last commit for the current branch. CurrentBranchCommit() (Commit, error) // IsEmpty informs if the current repository is empty or not. IsEmpty() (bool, error) // FindAllFilesInWorkspace returns all files in repository matching given pathSpec, including untracked files. FindAllFilesInWorkspace(pathSpec []string) ([]string, error) // EnsureSafeWorkspace returns an error workspace is in a safe state // for operations requiring a checkout. // For example, in git repositories we consider uncommitted changes or // a detached head is an unsafe state. EnsureSafeWorkspace() error // Checkout specified commit into workspace. // Also returns a reference to the previous tree pointed by current workspace. Checkout(commit Commit) (Reference, error) // CheckoutReference checks out the specified reference into workspace. CheckoutReference(Reference) error // MergeBase returns the merge base of two commits. MergeBase(a, b Commit) (Commit, error) }
Repo defines the set of interactions with the git repository.
type RunResult ¶
type RunResult struct { Manifest *Manifest Completed []*Module Skipped []*Module Failures []*CmdFailure }
RunResult is the result of running a user defined command.
type Spec ¶
type Spec struct { Name string `yaml:"name"` Build map[string]*Cmd `yaml:"build"` Commands map[string]*UserCmd `yaml:"commands"` Properties map[string]interface{} `yaml:"properties"` Dependencies []string `yaml:"dependencies"` FileDependencies []string `yaml:"fileDependencies"` }
Spec represents the structure of .mbt.yml contents.
type System ¶
type System interface { // ApplyBranch applies the manifest of specified branch over a template. // Template is retrieved from the commit tree of last commit of that branch. ApplyBranch(templatePath, branch string, output io.Writer) error // ApplyCommit applies the manifest of specified commit over a template. // Template is retrieved from the commit tree of the specified commit. ApplyCommit(sha, templatePath string, output io.Writer) error // ApplyHead applies the manifest of current branch over a template. // Template is retrieved from the commit tree of last commit current branch. ApplyHead(templatePath string, output io.Writer) error // ApplyLocal applies the manifest of local workspace. // Template is retrieved from the current workspace. ApplyLocal(templatePath string, output io.Writer) error // BuildBranch builds the specified branch. // This function accepts FilterOptions to specify which modules to be built // within that branch. BuildBranch(name string, filterOptions *FilterOptions, options *CmdOptions) (*BuildSummary, error) // BuildPr builds changes in 'src' branch since it diverged from 'dst' branch. BuildPr(src, dst string, options *CmdOptions) (*BuildSummary, error) // Build builds changes between two commits BuildDiff(from, to string, options *CmdOptions) (*BuildSummary, error) // BuildCurrentBranch builds the current branch. // This function accepts FilterOptions to specify which modules to be built // within that branch. BuildCurrentBranch(filterOptions *FilterOptions, options *CmdOptions) (*BuildSummary, error) // BuildCommit builds specified commit. // This function accepts FilterOptions to specify which modules to be built // within that branch. BuildCommit(commit string, filterOptions *FilterOptions, options *CmdOptions) (*BuildSummary, error) // BuildCommitChanges builds the changes in specified commit BuildCommitContent(commit string, options *CmdOptions) (*BuildSummary, error) // BuildWorkspace builds the current workspace. // This function accepts FilterOptions to specify which modules to be built // within that branch. BuildWorkspace(filterOptions *FilterOptions, options *CmdOptions) (*BuildSummary, error) // BuildWorkspace builds changes in current workspace. BuildWorkspaceChanges(options *CmdOptions) (*BuildSummary, error) // IntersectionByCommit returns the manifest of intersection of modules modified // between two commits. // If we consider M as the merge base of first and second commits, // intersection contains the modules that have been changed // between M and first and M and second. IntersectionByCommit(first, second string) (Modules, error) // IntersectionByBranch returns the manifest of intersection of modules modified // between two branches. // If we consider M as the merge base of first and second branches, // intersection contains the modules that have been changed // between M and first and M and second. IntersectionByBranch(first, second string) (Modules, error) // ManifestByDiff creates the manifest for diff between two commits ManifestByDiff(from, to string) (*Manifest, error) // ManifestByPr creates the manifest for diff between two branches ManifestByPr(src, dst string) (*Manifest, error) // ManifestByCommit creates the manifest for the specified commit ManifestByCommit(sha string) (*Manifest, error) // ManifestByCommitContent creates the manifest for the content in specified commit ManifestByCommitContent(sha string) (*Manifest, error) // ByBranch creates the manifest for the specified branch ManifestByBranch(name string) (*Manifest, error) // ByCurrentBranch creates the manifest for the current branch ManifestByCurrentBranch() (*Manifest, error) // ByWorkspace creates the manifest for the current workspace ManifestByWorkspace() (*Manifest, error) // ByWorkspaceChanges creates the manifest for the changes in workspace ManifestByWorkspaceChanges() (*Manifest, error) // RunInBranch runs a command in a branch. // This function accepts FilterOptions to specify a subset of modules. RunInBranch(command, name string, filterOptions *FilterOptions, options *CmdOptions) (*RunResult, error) // RunInPr runs a command in modules that have been changed in // 'src' branch since it diverged from 'dst' branch. RunInPr(command, src, dst string, options *CmdOptions) (*RunResult, error) // RunInDiff runs a command in modules that have been changed in 'from' // commit since it diverged from 'to' commit. RunInDiff(command, from, to string, options *CmdOptions) (*RunResult, error) // RunInCurrentBranch runs a command in modules in the current branch. // This function accepts FilterOptions to filter the modules included in this // operation. RunInCurrentBranch(command string, filterOptions *FilterOptions, options *CmdOptions) (*RunResult, error) // RunInCommit runs a command in all modules in a commit. // This function accepts FilterOptions to filter the modules included in this // operation. RunInCommit(command, commit string, filterOptions *FilterOptions, options *CmdOptions) (*RunResult, error) // RunInCommitContent runs a command in modules modified in a commit. RunInCommitContent(command, commit string, options *CmdOptions) (*RunResult, error) // RunInWorkspace runs a command in all modules in workspace. // This function accepts FilterOptions to filter the modules included in this // operation. RunInWorkspace(command string, filterOptions *FilterOptions, options *CmdOptions) (*RunResult, error) // RunInWorkspaceChanges runs a command in modules modified in workspace. RunInWorkspaceChanges(command string, options *CmdOptions) (*RunResult, error) }
System is the interface used by users to invoke the core functionality of this package
type TemplateData ¶
type TemplateData struct { Args map[string]interface{} Sha string Env map[string]string Modules map[string]*Module ModulesList []*Module OrderedModules []*Module }
TemplateData is the data passed into template.
type WorkspaceManager ¶
type WorkspaceManager interface { // CheckoutAndRun checks out the given commit and executes the specified function. // Returns an error if current workspace is dirty. // Otherwise returns the output from fn. CheckoutAndRun(commit string, fn func() (interface{}, error)) (interface{}, error) }
WorkspaceManager contains various functions to manipulate workspace.
func NewWorkspaceManager ¶
func NewWorkspaceManager(log Log, repo Repo) WorkspaceManager
NewWorkspaceManager creates a new workspace manager.