forked from toolshed/abra
feat: introduce remote recipes
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -280,12 +281,15 @@ func Ensure(recipeName string) error {
|
|||||||
|
|
||||||
// EnsureExists ensures that a recipe is locally cloned
|
// EnsureExists ensures that a recipe is locally cloned
|
||||||
func EnsureExists(recipeName string) error {
|
func EnsureExists(recipeName string) error {
|
||||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
parsed, err := ParseName(recipeName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
recipeDir := path.Join(config.RECIPES_DIR, parsed.Name)
|
||||||
|
|
||||||
if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
|
if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
|
||||||
logrus.Debugf("%s does not exist, attemmpting to clone", recipeDir)
|
logrus.Debugf("%s does not exist, attemmpting to clone", recipeDir)
|
||||||
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipeName)
|
if err := gitPkg.Clone(recipeDir, parsed.GitURL); err != nil {
|
||||||
if err := gitPkg.Clone(recipeDir, url); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,6 +301,34 @@ func EnsureExists(recipeName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RecipeName struct {
|
||||||
|
Name string
|
||||||
|
GitURL string
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseName(recipeName string) (RecipeName, error) {
|
||||||
|
if !strings.Contains(recipeName, "/") {
|
||||||
|
return RecipeName{
|
||||||
|
Name: recipeName,
|
||||||
|
GitURL: fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipeName),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(recipeName)
|
||||||
|
if err != nil {
|
||||||
|
return RecipeName{}, err
|
||||||
|
}
|
||||||
|
u.Scheme = "https"
|
||||||
|
u.RawPath, err = url.JoinPath(u.RawPath, ".git")
|
||||||
|
if err != nil {
|
||||||
|
return RecipeName{}, err
|
||||||
|
}
|
||||||
|
return RecipeName{
|
||||||
|
Name: recipeName,
|
||||||
|
GitURL: u.String(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// EnsureVersion checks whether a specific version exists for a recipe.
|
// EnsureVersion checks whether a specific version exists for a recipe.
|
||||||
func EnsureVersion(recipeName, version string) error {
|
func EnsureVersion(recipeName, version string) error {
|
||||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||||
|
Reference in New Issue
Block a user