forked from toolshed/abra
feat: introduce local recipes
This commit is contained in:
@ -28,6 +28,10 @@ type EnsureContext struct {
|
||||
// Ensure makes sure the recipe exists, is up to date and has the specific
|
||||
// version checked out.
|
||||
func (r Recipe) Ensure(ctx EnsureContext) error {
|
||||
if r.Local {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := r.EnsureExists(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -68,6 +72,10 @@ func (r Recipe) Ensure(ctx EnsureContext) error {
|
||||
|
||||
// EnsureExists ensures that the recipe is locally cloned
|
||||
func (r Recipe) EnsureExists() error {
|
||||
if r.Local {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := os.Stat(r.Dir); os.IsNotExist(err) {
|
||||
if err := gitPkg.Clone(r.Dir, r.GitURL); err != nil {
|
||||
return err
|
||||
@ -83,6 +91,10 @@ func (r Recipe) EnsureExists() error {
|
||||
|
||||
// IsChaosCommit determines if a version sttring is a chaos commit or not.
|
||||
func (r Recipe) IsChaosCommit(version string) (bool, error) {
|
||||
if r.Local {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
isChaosCommit := false
|
||||
|
||||
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
|
||||
@ -118,6 +130,10 @@ func (r Recipe) IsChaosCommit(version string) (bool, error) {
|
||||
|
||||
// EnsureVersion checks whether a specific version exists for a recipe.
|
||||
func (r Recipe) EnsureVersion(version string) (bool, error) {
|
||||
if r.Local {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
isChaosCommit := false
|
||||
|
||||
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
|
||||
@ -182,6 +198,10 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
|
||||
|
||||
// EnsureIsClean makes sure that the recipe repository has no unstaged changes.
|
||||
func (r Recipe) EnsureIsClean() error {
|
||||
if r.Local {
|
||||
return nil
|
||||
}
|
||||
|
||||
isClean, err := gitPkg.IsClean(r.Dir)
|
||||
if err != nil {
|
||||
return errors.New(i18n.G("unable to check git clean status in %s: %s", r.Dir, err))
|
||||
@ -196,6 +216,10 @@ func (r Recipe) EnsureIsClean() error {
|
||||
|
||||
// EnsureLatest makes sure the latest commit is checked out for the local recipe repository
|
||||
func (r Recipe) EnsureLatest() error {
|
||||
if r.Local {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -231,6 +255,10 @@ func (r Recipe) EnsureLatest() error {
|
||||
|
||||
// EnsureUpToDate ensures that the local repo is synced to the remote
|
||||
func (r Recipe) EnsureUpToDate() error {
|
||||
if r.Local {
|
||||
return nil
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(r.Dir)
|
||||
if err != nil {
|
||||
return errors.New(i18n.G("unable to open %s: %s", r.Dir, err))
|
||||
@ -282,6 +310,10 @@ func (r Recipe) EnsureUpToDate() error {
|
||||
|
||||
// IsDirty checks whether a recipe is dirty or not.
|
||||
func (r *Recipe) IsDirty() (bool, error) {
|
||||
if r.Local {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
isClean, err := gitPkg.IsClean(r.Dir)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -292,6 +324,10 @@ func (r *Recipe) IsDirty() (bool, error) {
|
||||
|
||||
// ChaosVersion constructs a chaos mode recipe version.
|
||||
func (r *Recipe) ChaosVersion() (string, error) {
|
||||
if r.Local {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var version string
|
||||
|
||||
head, err := r.Head()
|
||||
@ -315,6 +351,10 @@ func (r *Recipe) ChaosVersion() (string, error) {
|
||||
// Push pushes the latest changes to a SSH URL remote. You need to have your
|
||||
// local SSH configuration for git.coopcloud.tech working for this to work
|
||||
func (r Recipe) Push(dryRun bool) error {
|
||||
if r.Local {
|
||||
return nil
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(r.Dir)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -333,6 +373,10 @@ func (r Recipe) Push(dryRun bool) error {
|
||||
|
||||
// Tags list the recipe tags
|
||||
func (r Recipe) Tags() ([]string, error) {
|
||||
if r.Local {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var tags []string
|
||||
|
||||
repo, err := git.PlainOpen(r.Dir)
|
||||
@ -371,6 +415,10 @@ func (r Recipe) Tags() ([]string, error) {
|
||||
|
||||
// GetRecipeVersions retrieves all recipe versions.
|
||||
func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
|
||||
if r.Local {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
var warnMsg []string
|
||||
|
||||
versions := RecipeVersions{}
|
||||
|
||||
Reference in New Issue
Block a user