From 0643df6d73ae5464fa1c29e52c2c5fbb5ae97e30 Mon Sep 17 00:00:00 2001 From: p4u1 Date: Wed, 24 Jan 2024 15:01:33 +0000 Subject: [PATCH] feat: fetch all recipes when no recipe is specified (!401) Closes https://git.coopcloud.tech/coop-cloud/organising/issues/530 Reviewed-on: https://git.coopcloud.tech/coop-cloud/abra/pulls/401 Reviewed-by: decentral1se Co-authored-by: p4u1 Co-committed-by: p4u1 --- cli/recipe/fetch.go | 22 ++++++++++++++-------- pkg/recipe/recipe.go | 14 ++++++++++++++ tests/integration/recipe_fetch.bats | 12 +++++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/cli/recipe/fetch.go b/cli/recipe/fetch.go index acfc1708..de81cfec 100644 --- a/cli/recipe/fetch.go +++ b/cli/recipe/fetch.go @@ -3,6 +3,7 @@ package recipe import ( "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" + "coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -17,26 +18,31 @@ var recipeFetchCommand = cli.Command{ Flags: []cli.Flag{ internal.DebugFlag, internal.NoInputFlag, + internal.OfflineFlag, }, Before: internal.SubCommandBefore, BashComplete: autocomplete.RecipeNameComplete, Action: func(c *cli.Context) error { recipeName := c.Args().First() - if recipeName != "" { internal.ValidateRecipe(c) + if err := recipe.Ensure(recipeName); err != nil { + logrus.Fatal(err) + } + return nil } - if err := recipe.EnsureExists(recipeName); err != nil { + catalogue, err := recipe.ReadRecipeCatalogue(internal.Offline) + if err != nil { logrus.Fatal(err) } - if err := recipe.EnsureUpToDate(recipeName); err != nil { - logrus.Fatal(err) - } - - if err := recipe.EnsureLatest(recipeName); err != nil { - logrus.Fatal(err) + catlBar := formatter.CreateProgressbar(len(catalogue), "fetching latest recipes...") + for recipeName := range catalogue { + if err := recipe.Ensure(recipeName); err != nil { + logrus.Error(err) + } + catlBar.Add(1) } return nil diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index dbd4a520..a5d6d2eb 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -264,6 +264,20 @@ func (r Recipe) SampleEnv() (map[string]string, error) { return sampleEnv, nil } +// Ensure makes sure the recipe exists, is up to date and has the latest version checked out. +func Ensure(recipeName string) error { + if err := EnsureExists(recipeName); err != nil { + return err + } + if err := EnsureUpToDate(recipeName); err != nil { + return err + } + if err := EnsureLatest(recipeName); err != nil { + return err + } + return nil +} + // EnsureExists ensures that a recipe is locally cloned func EnsureExists(recipeName string) error { recipeDir := path.Join(config.RECIPES_DIR, recipeName) diff --git a/tests/integration/recipe_fetch.bats b/tests/integration/recipe_fetch.bats index a64306ab..1cc61e7c 100644 --- a/tests/integration/recipe_fetch.bats +++ b/tests/integration/recipe_fetch.bats @@ -5,7 +5,17 @@ setup() { _common_setup } -@test "recipe fetch" { +@test "recipe fetch all" { + run rm -rf "$ABRA_DIR/recipes/matrix-synapse" + assert_success + assert_not_exists "$ABRA_DIR/recipes/matrix-synapse" + + run $ABRA recipe fetch + assert_success + assert_exists "$ABRA_DIR/recipes/matrix-synapse" +} + +@test "recipe fetch single recipe" { run rm -rf "$ABRA_DIR/recipes/matrix-synapse" assert_success assert_not_exists "$ABRA_DIR/recipes/matrix-synapse"