forked from toolshed/abra
Merge pull request 'feat: add a flag to commit your changes before creating a tag' (#102) from knoflook/abra:recipe-release into main
Reviewed-on: coop-cloud/abra#102
This commit is contained in:
commit
75bdd59585
@ -10,6 +10,7 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
"coopcloud.tech/abra/pkg/recipe"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
"coopcloud.tech/tagcmp"
|
"coopcloud.tech/tagcmp"
|
||||||
|
"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"
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
@ -56,6 +57,22 @@ var PatchFlag = &cli.BoolFlag{
|
|||||||
Destination: &Patch,
|
Destination: &Patch,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var CommitMessage string
|
||||||
|
var CommitMessageFlag = &cli.StringFlag{
|
||||||
|
Name: "commit-message",
|
||||||
|
Usage: "commit message",
|
||||||
|
Aliases: []string{"cm"},
|
||||||
|
Destination: &CommitMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
var Commit bool
|
||||||
|
var CommitFlag = &cli.BoolFlag{
|
||||||
|
Name: "commit",
|
||||||
|
Value: false,
|
||||||
|
Aliases: []string{"c"},
|
||||||
|
Destination: &Commit,
|
||||||
|
}
|
||||||
|
|
||||||
var recipeReleaseCommand = &cli.Command{
|
var recipeReleaseCommand = &cli.Command{
|
||||||
Name: "release",
|
Name: "release",
|
||||||
Usage: "tag a recipe",
|
Usage: "tag a recipe",
|
||||||
@ -67,6 +84,8 @@ var recipeReleaseCommand = &cli.Command{
|
|||||||
MinorFlag,
|
MinorFlag,
|
||||||
MajorFlag,
|
MajorFlag,
|
||||||
PushFlag,
|
PushFlag,
|
||||||
|
CommitFlag,
|
||||||
|
CommitMessageFlag,
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
recipe := internal.ValidateRecipe(c)
|
recipe := internal.ValidateRecipe(c)
|
||||||
@ -79,6 +98,36 @@ var recipeReleaseCommand = &cli.Command{
|
|||||||
logrus.Fatal("Main app's version is empty.")
|
logrus.Fatal("Main app's version is empty.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tagstring != "" {
|
||||||
|
_, err := tagcmp.Parse(tagstring)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal("invalid tag specified")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if Commit || (CommitMessage != "") {
|
||||||
|
commitRepo, err := git.PlainOpen(directory)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
commitWorktree, err := commitRepo.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if CommitMessage == "" {
|
||||||
|
prompt := &survey.Input{
|
||||||
|
Message: "commit message",
|
||||||
|
}
|
||||||
|
survey.AskOne(prompt, &CommitMessage)
|
||||||
|
}
|
||||||
|
_, err = commitWorktree.Commit(CommitMessage, &git.CommitOptions{})
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
logrus.Info("changes commited")
|
||||||
|
}
|
||||||
|
|
||||||
repo, err := git.PlainOpen(directory)
|
repo, err := git.PlainOpen(directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
@ -99,9 +148,21 @@ var recipeReleaseCommand = &cli.Command{
|
|||||||
|
|
||||||
if tagstring != "" {
|
if tagstring != "" {
|
||||||
if bumpType > 0 {
|
if bumpType > 0 {
|
||||||
logrus.Warn("User specified a version number and --major/--minor/--patch at the same time! Using version number.")
|
logrus.Warn("user specified a version number and --major/--minor/--patch at the same time! Using version number.")
|
||||||
}
|
}
|
||||||
tagstring = fmt.Sprintf("%s+%s", tagstring, mainAppVersion)
|
tag, err := tagcmp.Parse(tagstring)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
if tag.MissingMinor {
|
||||||
|
tag.Minor = "0"
|
||||||
|
tag.MissingMinor = false
|
||||||
|
}
|
||||||
|
if tag.MissingPatch {
|
||||||
|
tag.Patch = "0"
|
||||||
|
tag.MissingPatch = false
|
||||||
|
}
|
||||||
|
tagstring = fmt.Sprintf("%s+%s", tag.String(), mainAppVersion)
|
||||||
if Dry {
|
if Dry {
|
||||||
logrus.Info(fmt.Sprintf("Dry run only. NOT creating tag %s at %s", tagstring, head.Hash()))
|
logrus.Info(fmt.Sprintf("Dry run only. NOT creating tag %s at %s", tagstring, head.Hash()))
|
||||||
return nil
|
return nil
|
||||||
@ -166,15 +227,7 @@ var recipeReleaseCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
newTagString = newTag.String()
|
newTagString = newTag.String()
|
||||||
} else {
|
} else {
|
||||||
// calculate the new tag
|
logrus.Fatal("we don't support auto tag generation yet. Specify a verion or use one of: --major --minor --patch")
|
||||||
var images = make(map[string]tagcmp.Tag)
|
|
||||||
for name, version := range imagesTmp {
|
|
||||||
t, err := tagcmp.Parse(version)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
images[name] = t
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newTagString = fmt.Sprintf("%s+%s", newTagString, mainAppVersion)
|
newTagString = fmt.Sprintf("%s+%s", newTagString, mainAppVersion)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user