feat: introduce remote recipes
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
2024-06-24 09:32:28 +02:00
parent 6cd331ebd6
commit b688ddc4b1

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
"path"
"path/filepath"
@ -280,12 +281,15 @@ func Ensure(recipeName string) error {
// EnsureExists ensures that a recipe is locally cloned
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) {
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, url); err != nil {
if err := gitPkg.Clone(recipeDir, parsed.GitURL); err != nil {
return err
}
}
@ -297,6 +301,34 @@ func EnsureExists(recipeName string) error {
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.
func EnsureVersion(recipeName, version string) error {
recipeDir := path.Join(config.RECIPES_DIR, recipeName)