feat: recipe sync shows changes
All checks were successful
continuous-integration/drone/push Build is passing

See #579
This commit is contained in:
2025-08-24 15:51:54 +02:00
parent 4cb660c348
commit 0c708f6592
4 changed files with 50 additions and 27 deletions

View File

@ -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" {

View File

@ -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{

View File

@ -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()

View File

@ -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)
}
}