refactor(recipe): remove direct usage of config.RECIPE_DIR

This commit is contained in:
2024-07-08 13:38:29 +02:00
parent f14d49cc64
commit 87ecc05962
17 changed files with 82 additions and 117 deletions

View File

@ -60,26 +60,26 @@ func TestGetComposeFiles(t *testing.T) {
{
map[string]string{},
[]string{
fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
fmt.Sprintf("%s/compose.yml", r.Dir),
},
},
{
map[string]string{"COMPOSE_FILE": "compose.yml"},
[]string{
fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
fmt.Sprintf("%s/compose.yml", r.Dir),
},
},
{
map[string]string{"COMPOSE_FILE": "compose.extra_secret.yml"},
[]string{
fmt.Sprintf("%s/%s/compose.extra_secret.yml", config.RECIPES_DIR, r.Name),
fmt.Sprintf("%s/compose.extra_secret.yml", r.Dir),
},
},
{
map[string]string{"COMPOSE_FILE": "compose.yml:compose.extra_secret.yml"},
[]string{
fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
fmt.Sprintf("%s/%s/compose.extra_secret.yml", config.RECIPES_DIR, r.Name),
fmt.Sprintf("%s/compose.yml", r.Dir),
fmt.Sprintf("%s/compose.extra_secret.yml", r.Dir),
},
},
}

View File

@ -1,7 +1,6 @@
package envfile_test
import (
"fmt"
"reflect"
"slices"
"strings"
@ -61,8 +60,7 @@ func TestReadAbraShEnvVars(t *testing.T) {
t.Fatal(err)
}
abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh")
abraShEnv, err := envfile.ReadAbraShEnvVars(abraShPath)
abraShEnv, err := envfile.ReadAbraShEnvVars(r.AbraShPath)
if err != nil {
t.Fatal(err)
}
@ -91,8 +89,7 @@ func TestReadAbraShCmdNames(t *testing.T) {
t.Fatal(err)
}
abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh")
cmdNames, err := appPkg.ReadAbraShCmdNames(abraShPath)
cmdNames, err := appPkg.ReadAbraShCmdNames(r.AbraShPath)
if err != nil {
t.Fatal(err)
}
@ -104,7 +101,7 @@ func TestReadAbraShCmdNames(t *testing.T) {
expectedCmdNames := []string{"test_cmd", "test_cmd_args"}
for _, cmdName := range expectedCmdNames {
if !slices.Contains(cmdNames, cmdName) {
t.Fatalf("%s should have been found in %s", cmdName, abraShPath)
t.Fatalf("%s should have been found in %s", cmdName, r.AbraShPath)
}
}
}

View File

@ -460,11 +460,9 @@ func LintSecretLengths(recipe recipe.Recipe) (bool, error) {
}
func LintValidTags(recipe recipe.Recipe) (bool, error) {
recipeDir := path.Join(config.RECIPES_DIR, recipe.Name)
repo, err := git.PlainOpen(recipeDir)
repo, err := git.PlainOpen(recipe.Dir)
if err != nil {
return false, fmt.Errorf("unable to open %s: %s", recipeDir, err)
return false, fmt.Errorf("unable to open %s: %s", recipe.Dir, err)
}
iter, err := repo.Tags()

View File

@ -2,6 +2,8 @@ package recipe
import (
"fmt"
"os"
"path"
"coopcloud.tech/abra/pkg/envfile"
)
@ -13,3 +15,23 @@ func (r Recipe) SampleEnv() (map[string]string, error) {
}
return sampleEnv, nil
}
// GetReleaseNotes prints release notes for the recipe version
func (r Recipe) GetReleaseNotes(version string) (string, error) {
if version == "" {
return "", nil
}
fpath := path.Join(r.Dir, "release", version)
if _, err := os.Stat(fpath); !os.IsNotExist(err) {
releaseNotes, err := os.ReadFile(fpath)
if err != nil {
return "", err
}
withTitle := fmt.Sprintf("%s release notes:\n%s", version, string(releaseNotes))
return withTitle, nil
}
return "", nil
}

View File

@ -132,6 +132,7 @@ func Get(name string) Recipe {
ComposePath: path.Join(dir, "compose.yml"),
ReadmePath: path.Join(dir, "README.md"),
SampleEnvPath: path.Join(dir, ".env.sample"),
AbraShPath: path.Join(dir, "abra.sh"),
}
}
@ -143,6 +144,7 @@ type Recipe struct {
ComposePath string
ReadmePath string
SampleEnvPath string
AbraShPath string
}
// GetRecipesLocal retrieves all local recipe directories
@ -581,8 +583,7 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string) error {
return
}
recipeDir := path.Join(config.RECIPES_DIR, rm.Name)
if err := gitPkg.Clone(recipeDir, rm.CloneURL); err != nil {
if err := gitPkg.Clone(Get(rm.Name).Dir, rm.CloneURL); err != nil {
log.Fatal(err)
}