WIP: fix(recipe): Prevent crash when recipe has no previous tag or release #706

Draft
p4u1 wants to merge 1 commits from p4u1/abra:fix-crash-sync into main
2 changed files with 15 additions and 4 deletions

View File

@ -42,7 +42,8 @@ local file system.`),
ValidArgsFunction: func(
cmd *cobra.Command,
args []string,
toComplete string) ([]string, cobra.ShellCompDirective) {
toComplete string,
) ([]string, cobra.ShellCompDirective) {
switch l := len(args); l {
case 0:
return autocomplete.RecipeNameComplete()
@ -131,10 +132,16 @@ likely to change.
log.Fatal(err)
}
latestRelease := tags[len(tags)-1]
latestRelease := "0.0.0+0.0.0"

Isn't the left-hand side supposed to be 1.0.0 / 0.1.0 following:

cli/recipe/sync.go Lines 85 to 100 in 11656c009d
fmt.Println(i18n.G(`
The following options are two types of initial semantic version that you can
pick for %s that will be published in the recipe catalogue. This follows the
semver convention (more on https://semver.org), here is a short cheatsheet
0.1.0: development release, still hacking. when you make a major upgrade
you increment the "y" part (i.e. 0.1.0 -> 0.2.0) and only move to
using the "x" part when things are stable.
1.0.0: public release, assumed to be working. you already have a stable
and reliable deployment of this app and feel relatively confident
about it.
If you want people to be able alpha test your current config for %s but don't
think it is quite reliable, go with 0.1.0 and people will know that things are
likely to change.

I thought this case was covered 🤔 The logic of the code above doesn't look right because it tests len(tags) == 0 and then access tags later on 😬 I would assume if have no previous release/tag we can construct a choice from the above question and the tag of the app? Otherwise, probably 0.0.0+0.0.0 is going to explode somewhere else 🙃

Isn't the left-hand side supposed to be `1.0.0` / `0.1.0` following: https://git.coopcloud.tech/toolshed/abra/src/commit/11656c009df0f6acb272a0614b12264cf08e82e5/cli/recipe/sync.go#L85-L100 I thought this case was covered 🤔 The logic of the code above doesn't look right because it tests `len(tags) == 0` and then access `tags` later on 😬 I would assume if have no previous release/tag we can construct a choice from the above question and the tag of the `app`? Otherwise, probably `0.0.0+0.0.0` is going to explode somewhere else 🙃
if len(tags) > 0 {
latestRelease = tags[len(tags)-1]
}
changesTable.Headers(i18n.G("SERVICE"), latestRelease, i18n.G("PROPOSED CHANGES"))
latestRecipeVersion := versions[len(versions)-1]
latestRecipeVersion := latestRelease
if len(versions) > 0 {
latestRecipeVersion = versions[len(versions)-1]
}
allRecipeVersions := catl[recipe.Name].Versions
for _, recipeVersion := range allRecipeVersions {
if serviceVersions, ok := recipeVersion[latestRecipeVersion]; ok {

View File

@ -282,7 +282,11 @@ func GatherImagesForDeploy(cl *dockerClient.Client, app appPkg.App, compose *com
}
imageBaseName := reference.Path(imageParsed)
imageTag := imageParsed.(reference.NamedTagged).Tag()
namedTag, ok := imageParsed.(reference.NamedTagged)
if !ok {
continue
}
imageTag := namedTag.Tag()
existingImageVersion, ok := newImages[imageBaseName]
if !ok {