diff --git a/cli/recipe/release.go b/cli/recipe/release.go index f9c10b19..e266eb59 100644 --- a/cli/recipe/release.go +++ b/cli/recipe/release.go @@ -13,7 +13,6 @@ import ( "coopcloud.tech/tagcmp" "github.com/AlecAivazis/survey/v2" "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" @@ -51,6 +50,14 @@ var CommitFlag = &cli.BoolFlag{ Destination: &Commit, } +var TagMessage string +var TagMessageFlag = &cli.StringFlag{ + Name: "tag-comment", + Usage: "tag comment. If not given, user will be asked for it", + Aliases: []string{"t", "tm"}, + Destination: &TagMessage, +} + var recipeReleaseCommand = &cli.Command{ Name: "release", Usage: "tag a recipe", @@ -85,6 +92,7 @@ or a rollback of an app. PushFlag, CommitFlag, CommitMessageFlag, + TagMessageFlag, }, Action: func(c *cli.Context) error { recipe := internal.ValidateRecipe(c) @@ -109,6 +117,16 @@ or a rollback of an app. } } + if TagMessage == "" { + prompt := &survey.Input{ + Message: "tag message", + } + survey.AskOne(prompt, &TagMessage) + } + + var createTagOptions git.CreateTagOptions + createTagOptions.Message = TagMessage + if Commit || (CommitMessage != "") { commitRepo, err := git.PlainOpen(directory) if err != nil { @@ -178,9 +196,7 @@ or a rollback of an app. return nil } - repo.CreateTag(tagstring, head.Hash(), nil) /* &git.CreateTagOptions{ - Message: tag, - })*/ + repo.CreateTag(tagstring, head.Hash(), &createTagOptions) logrus.Info(fmt.Sprintf("created tag %s at %s", tagstring, head.Hash())) if Push { if err := repo.Push(&git.PushOptions{}); err != nil { @@ -193,27 +209,30 @@ or a rollback of an app. } // get the latest tag with its hash, name etc - var lastGitTag *object.Tag - iter, err := repo.Tags() + var lastGitTag tagcmp.Tag + iter, err := repo.TagObjects() if err != nil { logrus.Fatal(err) } - if err := iter.ForEach(func(ref *plumbing.Reference) error { - obj, err := repo.TagObject(ref.Hash()) - if err == nil { - lastGitTag = obj - return nil + if err := iter.ForEach(func(obj *object.Tag) error { + tagcmpTag, err := tagcmp.Parse(obj.Name) + if err != nil { + logrus.Fatal(err) } - return err + if (lastGitTag == tagcmp.Tag{}) { + lastGitTag = tagcmpTag + } else if tagcmpTag.IsGreaterThan(lastGitTag) { + lastGitTag = tagcmpTag + } + return nil }); err != nil { logrus.Fatal(err) } - newTag, err := tagcmp.Parse(lastGitTag.Name) - if err != nil { - logrus.Fatal(err) - } + fmt.Println(lastGitTag) + + newTag := lastGitTag var newTagString string if bumpType > 0 { if Patch { @@ -238,20 +257,17 @@ or a rollback of an app. newTag.Minor = "0" newTag.Major = strconv.Itoa(now + 1) } - newTagString = newTag.String() } else { logrus.Fatal("we don't support automatic tag generation yet - specify a version or use one of: --major --minor --patch") } - - newTagString = fmt.Sprintf("%s+%s", newTagString, mainAppVersion) + newTag.Metadata = mainAppVersion + newTagString = newTag.String() if Dry { logrus.Info(fmt.Sprintf("dry run only: NOT creating tag %s at %s", newTagString, head.Hash())) return nil } - repo.CreateTag(newTagString, head.Hash(), nil) /* &git.CreateTagOptions{ - Message: tag, - })*/ + repo.CreateTag(newTagString, head.Hash(), &createTagOptions) logrus.Info(fmt.Sprintf("created tag %s at %s", newTagString, head.Hash())) if Push { if err := repo.Push(&git.PushOptions{}); err != nil {