From 0c708f659282253e563774f8169088f7873c7b68 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 24 Aug 2025 15:51:54 +0200 Subject: [PATCH] feat: recipe sync shows changes See https://git.coopcloud.tech/toolshed/abra/issues/579 --- cli/app/new.go | 14 -------------- cli/internal/recipe.go | 6 ++++-- cli/recipe/release.go | 13 ++++--------- cli/recipe/sync.go | 44 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/cli/app/new.go b/cli/app/new.go index 778b260c..1ff6d73f 100644 --- a/cli/app/new.go +++ b/cli/app/new.go @@ -16,7 +16,6 @@ import ( recipePkg "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/abra/pkg/secret" "github.com/AlecAivazis/survey/v2" - "github.com/charmbracelet/lipgloss/table" dockerClient "github.com/docker/docker/client" "github.com/spf13/cobra" ) @@ -144,7 +143,6 @@ var AppNewCommand = &cobra.Command{ } var appSecrets AppSecrets - var secretsTable *table.Table if generateSecrets { sampleEnv, err := recipe.SampleEnv() if err != nil { @@ -178,18 +176,6 @@ var AppNewCommand = &cobra.Command{ if err != nil { log.Fatal(err) } - - secretsTable, err = formatter.CreateTable() - if err != nil { - log.Fatal(err) - } - - headers := []string{i18n.G("NAME"), i18n.G("VALUE")} - secretsTable.Headers(headers...) - - for name, val := range appSecrets { - secretsTable.Row(name, val) - } } if newAppServer == "default" { diff --git a/cli/internal/recipe.go b/cli/internal/recipe.go index 1c253ef3..5cadadf6 100644 --- a/cli/internal/recipe.go +++ b/cli/internal/recipe.go @@ -13,7 +13,7 @@ import ( ) // PromptBumpType prompts for version bump type -func PromptBumpType(tagString, latestRelease string) error { +func PromptBumpType(tagString, latestRelease, changeOverview string) error { if (!Major && !Minor && !Patch) && tagString == "" { fmt.Print(i18n.G(` You need to make a decision about what kind of an update this new recipe @@ -24,6 +24,8 @@ version. The latest published version is %s. +%s + Here is a semver cheat sheet (more on https://semver.org): major: new features/bug fixes, backwards incompatible (e.g 1.0.0 -> 2.0.0). @@ -38,7 +40,7 @@ Here is a semver cheat sheet (more on https://semver.org): should also Just Work and is mostly to do with minor bug fixes and/or security patches. "nothing to worry about". -`, latestRelease)) +`, latestRelease, changeOverview)) var chosenBumpType string prompt := &survey.Select{ diff --git a/cli/recipe/release.go b/cli/recipe/release.go index 4c650d20..161d80f9 100644 --- a/cli/recipe/release.go +++ b/cli/recipe/release.go @@ -72,7 +72,7 @@ your private key and enter your passphrase beforehand. Run: func(cmd *cobra.Command, args []string) { recipe := internal.ValidateRecipe(args, cmd.Name()) - imagesTmp, err := getImageVersions(recipe) + imagesTmp, err := GetImageVersions(recipe) if err != nil { log.Fatal(err) } @@ -151,6 +151,7 @@ your private key and enter your passphrase beforehand. if len(tags) > 0 { log.Warn(i18n.G("previous git tags detected, assuming new semver release")) + if err := createReleaseFromPreviousTag(tagString, mainAppVersion, recipe, tags); err != nil { if cleanErr := cleanTag(recipe, tagString); cleanErr != nil { log.Fatal(cleanErr) @@ -178,8 +179,8 @@ your private key and enter your passphrase beforehand. }, } -// getImageVersions retrieves image versions for a recipe -func getImageVersions(recipe recipe.Recipe) (map[string]string, error) { +// GetImageVersions retrieves image versions for a recipe +func GetImageVersions(recipe recipe.Recipe) (map[string]string, error) { services := make(map[string]string) config, err := recipe.GetComposeConfig(nil) @@ -511,12 +512,6 @@ func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recip newTag.Major = strconv.Itoa(now + 1) } - if tagString == "" { - if err := internal.PromptBumpType(tagString, lastGitTag.String()); err != nil { - return err - } - } - if internal.Major || internal.Minor || internal.Patch { newTag.Metadata = mainAppVersion tagString = newTag.String() diff --git a/cli/recipe/sync.go b/cli/recipe/sync.go index cfa46436..4b865d25 100644 --- a/cli/recipe/sync.go +++ b/cli/recipe/sync.go @@ -6,9 +6,11 @@ import ( "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" + "coopcloud.tech/abra/pkg/formatter" gitPkg "coopcloud.tech/abra/pkg/git" "coopcloud.tech/abra/pkg/i18n" "coopcloud.tech/abra/pkg/log" + recipePkg "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/tagcmp" "github.com/AlecAivazis/survey/v2" "github.com/go-git/go-git/v5" @@ -51,7 +53,7 @@ local file system.`), log.Fatal(err) } - imagesTmp, err := getImageVersions(recipe) + imagesTmp, err := GetImageVersions(recipe) if err != nil { log.Fatal(err) } @@ -105,8 +107,46 @@ likely to change. } if nextTag == "" && (!internal.Major && !internal.Minor && !internal.Patch) { + var changeOverview string + + catl, err := recipePkg.ReadRecipeCatalogue(false) + if err != nil { + log.Fatal(err) + } + + versions, err := recipePkg.GetRecipeCatalogueVersions(recipe.Name, catl) + if err != nil { + log.Fatal(err) + } + + changesTable, err := formatter.CreateTable() + if err != nil { + log.Fatal(err) + } + latestRelease := tags[len(tags)-1] - if err := internal.PromptBumpType("", latestRelease); err != nil { + changesTable.Headers(i18n.G("SERVICE"), latestRelease, i18n.G("PROPOSED CHANGES")) + + latestRecipeVersion := versions[len(versions)-1] + allRecipeVersions := catl[recipe.Name].Versions + for _, recipeVersion := range allRecipeVersions { + if serviceVersions, ok := recipeVersion[latestRecipeVersion]; ok { + for serviceName := range serviceVersions { + serviceMeta := serviceVersions[serviceName] + changesTable.Row( + []string{ + serviceName, + fmt.Sprintf("%s:%s", serviceMeta.Image, serviceMeta.Tag), + fmt.Sprintf("%s:%s", serviceMeta.Image, imagesTmp[serviceMeta.Image]), + }..., + ) + } + } + } + + changeOverview = changesTable.Render() + + if err := internal.PromptBumpType("", latestRelease, changeOverview); err != nil { log.Fatal(err) } }