From a5104336a29e9bc3573460406aa85ae18d0459d7 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 18 Aug 2025 10:10:52 +0200 Subject: [PATCH] feat: catalogue sync command --- cli/catalogue/catalogue.go | 18 ++++++++++++++++++ cli/run.go | 1 + tests/integration/catalogue.bats | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/cli/catalogue/catalogue.go b/cli/catalogue/catalogue.go index 6998f1aa..6b21bc50 100644 --- a/cli/catalogue/catalogue.go +++ b/cli/catalogue/catalogue.go @@ -20,6 +20,24 @@ import ( "github.com/spf13/cobra" ) +var CatalogueSyncCommand = &cobra.Command{ + Use: i18n.G("sync [flags]"), + Aliases: []string{i18n.G("g")}, + Short: i18n.G("Sync recipe catalogue for latest changes"), + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + if err := catalogue.EnsureCatalogue(); err != nil { + log.Fatal(err) + } + + if err := catalogue.EnsureUpToDate(); err != nil { + log.Fatal(err) + } + + log.Info(i18n.G("catalogue successfully synced")) + }, +} + var CatalogueGenerateCommand = &cobra.Command{ Use: i18n.G("generate [recipe] [flags]"), Aliases: []string{i18n.G("g")}, diff --git a/cli/run.go b/cli/run.go index 72d98088..647c57d4 100644 --- a/cli/run.go +++ b/cli/run.go @@ -143,6 +143,7 @@ func Run(version, commit string) { catalogue.CatalogueCommand.AddCommand( catalogue.CatalogueGenerateCommand, + catalogue.CatalogueSyncCommand, ) server.ServerCommand.AddCommand( diff --git a/tests/integration/catalogue.bats b/tests/integration/catalogue.bats index 0d4c25f7..27938a83 100644 --- a/tests/integration/catalogue.bats +++ b/tests/integration/catalogue.bats @@ -47,3 +47,24 @@ setup(){ assert_success assert_exists "$ABRA_DIR/recipes/gitea/.git" } + +# bats test_tags=slow +@test "sync latest changes" { + _ensure_catalogue + + latestHash=$(git -C "$ABRA_DIR/catalogue" show -s --format="%H") + + wantHash=$(git -C "$ABRA_DIR/catalogue" show -s --format="%H" "HEAD~3") + + run git -C "$ABRA_DIR/catalogue" reset --hard HEAD~3 + assert_success + + currHash=$(git -C "$ABRA_DIR/catalogue" show -s --format="%H") + assert_equal "$currHash" "$wantHash" + + run $ABRA catalogue sync + assert_success + + syncHash=$(git -C "$ABRA_DIR/catalogue" show -s --format="%H") + assert_equal "$syncHash" "$latestHash" +}