forked from toolshed/abra
refactor!: simplifying publish logic
This commit is contained in:
@ -47,20 +47,16 @@ Abra does its best to read the "a.b.c" version scheme and communicate what
|
||||
action needs to be taken when performing different operations such as an update
|
||||
or a rollback of an app.
|
||||
|
||||
You may invoke this command in "wizard" mode and be prompted for input:
|
||||
|
||||
abra recipe release gitea
|
||||
|
||||
Publish your new release git.coopcloud.tech with "-p/--publish". This requires
|
||||
that you have permission to git push to these repositories and have your SSH
|
||||
keys configured on your account.
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
internal.DryFlag,
|
||||
internal.MajorFlag,
|
||||
internal.MinorFlag,
|
||||
internal.PatchFlag,
|
||||
internal.PushFlag,
|
||||
internal.CommitFlag,
|
||||
internal.CommitMessageFlag,
|
||||
internal.TagMessageFlag,
|
||||
internal.PublishFlag,
|
||||
},
|
||||
BashComplete: autocomplete.RecipeNameComplete,
|
||||
Action: func(c *cli.Context) error {
|
||||
@ -71,7 +67,11 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
mainApp := internal.GetMainApp(recipe)
|
||||
mainApp, err := internal.GetMainAppImage(recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
mainAppVersion := imagesTmp[mainApp]
|
||||
if mainAppVersion == "" {
|
||||
logrus.Fatalf("main app service version for %s is empty?", recipe.Name)
|
||||
@ -201,14 +201,14 @@ func createReleaseFromTag(recipe recipe.Recipe, tagString, mainAppVersion string
|
||||
tag.MissingPatch = false
|
||||
}
|
||||
|
||||
if err := commitRelease(recipe); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if tagString == "" {
|
||||
tagString = fmt.Sprintf("%s+%s", tag.String(), mainAppVersion)
|
||||
}
|
||||
|
||||
if err := commitRelease(recipe, tagString); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := tagRelease(tagString, repo); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -230,50 +230,30 @@ func btoi(b bool) int {
|
||||
}
|
||||
|
||||
// getTagCreateOptions constructs git tag create options
|
||||
func getTagCreateOptions() (git.CreateTagOptions, error) {
|
||||
if internal.TagMessage == "" && !internal.NoInput {
|
||||
prompt := &survey.Input{
|
||||
Message: "git tag message?",
|
||||
Default: "chore: publish new release",
|
||||
}
|
||||
|
||||
if err := survey.AskOne(prompt, &internal.TagMessage); err != nil {
|
||||
return git.CreateTagOptions{}, err
|
||||
}
|
||||
}
|
||||
|
||||
return git.CreateTagOptions{Message: internal.TagMessage}, nil
|
||||
func getTagCreateOptions(tag string) (git.CreateTagOptions, error) {
|
||||
msg := fmt.Sprintf("chore: publish %s release", tag)
|
||||
return git.CreateTagOptions{Message: msg}, nil
|
||||
}
|
||||
|
||||
func commitRelease(recipe recipe.Recipe) error {
|
||||
func commitRelease(recipe recipe.Recipe, tag string) error {
|
||||
if internal.Dry {
|
||||
logrus.Info("dry run: no changed committed")
|
||||
logrus.Debugf("dry run: no changes committed")
|
||||
return nil
|
||||
}
|
||||
|
||||
if !internal.Commit && !internal.NoInput {
|
||||
prompt := &survey.Confirm{
|
||||
Message: "git commit changes?",
|
||||
}
|
||||
|
||||
if err := survey.AskOne(prompt, &internal.Commit); err != nil {
|
||||
return err
|
||||
}
|
||||
isClean, err := gitPkg.IsClean(recipe.Dir())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if internal.CommitMessage == "" && !internal.NoInput && internal.Commit {
|
||||
prompt := &survey.Input{
|
||||
Message: "git commit message?",
|
||||
Default: "chore: publish new version",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &internal.CommitMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
if isClean {
|
||||
return fmt.Errorf("no changes discovered in %s, nothing to publish?", recipe.Dir())
|
||||
}
|
||||
|
||||
if internal.Commit {
|
||||
if internal.Publish {
|
||||
msg := fmt.Sprintf("chore: publish %s release", tag)
|
||||
repoPath := path.Join(config.RECIPES_DIR, recipe.Name)
|
||||
if err := gitPkg.Commit(repoPath, "compose.**yml", internal.CommitMessage, internal.Dry); err != nil {
|
||||
if err := gitPkg.Commit(repoPath, "compose.**yml", msg, internal.Dry); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -283,7 +263,7 @@ func commitRelease(recipe recipe.Recipe) error {
|
||||
|
||||
func tagRelease(tagString string, repo *git.Repository) error {
|
||||
if internal.Dry {
|
||||
logrus.Infof("dry run: no git tag created (%s)", tagString)
|
||||
logrus.Debugf("dry run: no git tag created (%s)", tagString)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -292,7 +272,7 @@ func tagRelease(tagString string, repo *git.Repository) error {
|
||||
return err
|
||||
}
|
||||
|
||||
createTagOptions, err := getTagCreateOptions()
|
||||
createTagOptions, err := getTagCreateOptions(tagString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -303,33 +283,36 @@ func tagRelease(tagString string, repo *git.Repository) error {
|
||||
}
|
||||
|
||||
hash := abraFormatter.SmallSHA(head.Hash().String())
|
||||
logrus.Info(fmt.Sprintf("created tag %s at %s", tagString, hash))
|
||||
logrus.Debugf(fmt.Sprintf("created tag %s at %s", tagString, hash))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func pushRelease(recipe recipe.Recipe) error {
|
||||
if internal.Dry {
|
||||
logrus.Info("dry run: no changes pushed")
|
||||
logrus.Info("dry run: no changes published")
|
||||
return nil
|
||||
}
|
||||
|
||||
if !internal.Push && !internal.NoInput {
|
||||
if !internal.Publish && !internal.NoInput {
|
||||
prompt := &survey.Confirm{
|
||||
Message: "git push changes?",
|
||||
Message: "publish new release?",
|
||||
}
|
||||
|
||||
if err := survey.AskOne(prompt, &internal.Push); err != nil {
|
||||
if err := survey.AskOne(prompt, &internal.Publish); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if internal.Push {
|
||||
if internal.Publish {
|
||||
if err := recipe.Push(internal.Dry); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/tags", config.REPOS_BASE_URL, recipe.Name)
|
||||
logrus.Infof("new release published: %s", url)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -392,13 +375,13 @@ func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recip
|
||||
newTag.Major = strconv.Itoa(now + 1)
|
||||
}
|
||||
|
||||
if err := commitRelease(recipe); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
newTag.Metadata = mainAppVersion
|
||||
newTagString := newTag.String()
|
||||
|
||||
if err := commitRelease(recipe, newTagString); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := tagRelease(newTagString, repo); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -422,7 +405,7 @@ func cleanUpTag(tag, recipeName string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Warnf("removed freshly created tag %s", tag)
|
||||
logrus.Debugf("removed freshly created tag %s", tag)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
|
||||
var recipeSyncCommand = &cli.Command{
|
||||
Name: "sync",
|
||||
Usage: "Ensure recipe version labels are up-to-date",
|
||||
Usage: "Sync recipe version label",
|
||||
Aliases: []string{"s"},
|
||||
ArgsUsage: "<recipe> [<version>]",
|
||||
Flags: []cli.Flag{
|
||||
@ -29,23 +29,21 @@ var recipeSyncCommand = &cli.Command{
|
||||
},
|
||||
Description: `
|
||||
This command will generate labels for the main recipe service (i.e. by
|
||||
convention, the service named "app") which corresponds to the following format:
|
||||
convention, the service named 'app') which corresponds to the following format:
|
||||
|
||||
coop-cloud.${STACK_NAME}.version=<version>
|
||||
|
||||
The <version> is determined by the recipe maintainer and is specified on the
|
||||
command-line. The <recipe> configuration will be updated on the local file
|
||||
system.
|
||||
|
||||
You may invoke this command in "wizard" mode and be prompted for input:
|
||||
|
||||
abra recipe sync
|
||||
|
||||
Where <version> can be specifed on the command-line or Abra can attempt to
|
||||
auto-generate it for you. The <recipe> configuration will be updated on the
|
||||
local file system.
|
||||
`,
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := internal.ValidateRecipeWithPrompt(c)
|
||||
|
||||
mainApp := internal.GetMainApp(recipe)
|
||||
mainApp, err := internal.GetMainAppImage(recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
imagesTmp, err := getImageVersions(recipe)
|
||||
if err != nil {
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
@ -42,7 +43,8 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
abra recipe upgrade
|
||||
|
||||
`,
|
||||
ArgsUsage: "<recipe>",
|
||||
BashComplete: autocomplete.RecipeNameComplete,
|
||||
ArgsUsage: "<recipe>",
|
||||
Flags: []cli.Flag{
|
||||
internal.PatchFlag,
|
||||
internal.MinorFlag,
|
||||
|
Reference in New Issue
Block a user