fix!: use annotated tags with recipe release #109
|
@ -13,7 +13,6 @@ import (
|
||||||
"coopcloud.tech/tagcmp"
|
"coopcloud.tech/tagcmp"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/go-git/go-git/v5"
|
"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/go-git/go-git/v5/plumbing/object"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
@ -51,6 +50,14 @@ var CommitFlag = &cli.BoolFlag{
|
||||||
Destination: &Commit,
|
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{
|
var recipeReleaseCommand = &cli.Command{
|
||||||
Name: "release",
|
Name: "release",
|
||||||
Usage: "tag a recipe",
|
Usage: "tag a recipe",
|
||||||
|
@ -85,6 +92,7 @@ or a rollback of an app.
|
||||||
PushFlag,
|
PushFlag,
|
||||||
CommitFlag,
|
CommitFlag,
|
||||||
CommitMessageFlag,
|
CommitMessageFlag,
|
||||||
|
TagMessageFlag,
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
recipe := internal.ValidateRecipe(c)
|
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 != "") {
|
if Commit || (CommitMessage != "") {
|
||||||
commitRepo, err := git.PlainOpen(directory)
|
commitRepo, err := git.PlainOpen(directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -178,9 +196,7 @@ or a rollback of an app.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.CreateTag(tagstring, head.Hash(), nil) /* &git.CreateTagOptions{
|
repo.CreateTag(tagstring, head.Hash(), &createTagOptions)
|
||||||
Message: tag,
|
|
||||||
})*/
|
|
||||||
logrus.Info(fmt.Sprintf("created tag %s at %s", tagstring, head.Hash()))
|
logrus.Info(fmt.Sprintf("created tag %s at %s", tagstring, head.Hash()))
|
||||||
if Push {
|
if Push {
|
||||||
if err := repo.Push(&git.PushOptions{}); err != nil {
|
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
|
// get the latest tag with its hash, name etc
|
||||||
var lastGitTag *object.Tag
|
var lastGitTag tagcmp.Tag
|
||||||
iter, err := repo.Tags()
|
iter, err := repo.TagObjects()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := iter.ForEach(func(ref *plumbing.Reference) error {
|
if err := iter.ForEach(func(obj *object.Tag) error {
|
||||||
obj, err := repo.TagObject(ref.Hash())
|
tagcmpTag, err := tagcmp.Parse(obj.Name)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
lastGitTag = obj
|
logrus.Fatal(err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return err
|
if (lastGitTag == tagcmp.Tag{}) {
|
||||||
|
lastGitTag = tagcmpTag
|
||||||
|
} else if tagcmpTag.IsGreaterThan(lastGitTag) {
|
||||||
|
lastGitTag = tagcmpTag
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
newTag, err := tagcmp.Parse(lastGitTag.Name)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fmt.Println(lastGitTag)
|
||||||
|
|
||||||
|
newTag := lastGitTag
|
||||||
var newTagString string
|
var newTagString string
|
||||||
if bumpType > 0 {
|
if bumpType > 0 {
|
||||||
if Patch {
|
if Patch {
|
||||||
|
@ -238,20 +257,17 @@ or a rollback of an app.
|
||||||
newTag.Minor = "0"
|
newTag.Minor = "0"
|
||||||
newTag.Major = strconv.Itoa(now + 1)
|
newTag.Major = strconv.Itoa(now + 1)
|
||||||
}
|
}
|
||||||
newTagString = newTag.String()
|
|
||||||
} else {
|
} else {
|
||||||
logrus.Fatal("we don't support automatic tag generation yet - specify a version or use one of: --major --minor --patch")
|
logrus.Fatal("we don't support automatic tag generation yet - specify a version or use one of: --major --minor --patch")
|
||||||
}
|
}
|
||||||
|
newTag.Metadata = mainAppVersion
|
||||||
newTagString = fmt.Sprintf("%s+%s", newTagString, mainAppVersion)
|
newTagString = newTag.String()
|
||||||
if Dry {
|
if Dry {
|
||||||
logrus.Info(fmt.Sprintf("dry run only: NOT creating tag %s at %s", newTagString, head.Hash()))
|
logrus.Info(fmt.Sprintf("dry run only: NOT creating tag %s at %s", newTagString, head.Hash()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.CreateTag(newTagString, head.Hash(), nil) /* &git.CreateTagOptions{
|
repo.CreateTag(newTagString, head.Hash(), &createTagOptions)
|
||||||
Message: tag,
|
|
||||||
})*/
|
|
||||||
logrus.Info(fmt.Sprintf("created tag %s at %s", newTagString, head.Hash()))
|
logrus.Info(fmt.Sprintf("created tag %s at %s", newTagString, head.Hash()))
|
||||||
if Push {
|
if Push {
|
||||||
if err := repo.Push(&git.PushOptions{}); err != nil {
|
if err := repo.Push(&git.PushOptions{}); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue