refactor: improved version choice flow

This commit is contained in:
decentral1se 2021-12-28 03:16:23 +01:00
parent 26a11533b4
commit 1fd0941239
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
3 changed files with 74 additions and 39 deletions

View File

@ -13,10 +13,27 @@ import (
// PromptBumpType prompts for version bump type // PromptBumpType prompts for version bump type
func PromptBumpType(tagString string) error { func PromptBumpType(tagString string) error {
if (!Major && !Minor && !Patch) && tagString == "" { if (!Major && !Minor && !Patch) && tagString == "" {
fmt.Printf(`semver cheat sheet (more via semver.org): fmt.Printf(`
major: new features/bug fixes, backwards incompatible You need to make a decision about what kind of an update this new recipe
minor: new features/bug fixes, backwards compatible version is. If someone else performs this upgrade, do they have to do some
patch: bug fixes, backwards compatible migration work or take care of some breaking changes? This can be signaled in
the version you specify on the recipe deploy label and is called a semantic
version.
Here is a semver cheat sheet (more on https://semver.org):
major: new features/bug fixes, backwards incompatible (e.g 1.0.0 -> 2.0.0).
the upgrade won't work without some preparation work and others need
to take care when performing it. "it could go wrong".
minor: new features/bug fixes, backwards compatible (e.g. 0.1.0 -> 0.2.0).
the upgrade should Just Work and there are no breaking changes in
the app and the recipe config. "it should go fine".
patch: bug fixes, backwards compatible (e.g. 0.0.1 -> 0.0.2). this upgrade
should also Just Work and is mostly to do with minor bug fixes
and/or security patches. "nothing to worry about".
`) `)
var chosenBumpType string var chosenBumpType string

View File

@ -99,6 +99,14 @@ keys configured on your account.
logrus.Fatal(err) logrus.Fatal(err)
} }
if tagString == "" {
var err error
tagString, err = getLabelVersion(recipe)
if err != nil {
logrus.Fatal(err)
}
}
if len(tags) > 0 { if len(tags) > 0 {
logrus.Warnf("previous git tags detected, assuming this is a new semver release") logrus.Warnf("previous git tags detected, assuming this is a new semver release")
if err := createReleaseFromPreviousTag(tagString, mainAppVersion, recipe, tags); err != nil { if err := createReleaseFromPreviousTag(tagString, mainAppVersion, recipe, tags); err != nil {
@ -107,32 +115,8 @@ keys configured on your account.
} else { } else {
logrus.Warnf("no tag specified and no previous tag available for %s, assuming this is the initial release", recipe.Name) logrus.Warnf("no tag specified and no previous tag available for %s, assuming this is the initial release", recipe.Name)
initTag, err := recipePkg.GetVersionLabelLocal(recipe) if err := createReleaseFromTag(recipe, tagString, mainAppVersion); err != nil {
if err != nil { if cleanUpErr := cleanUpTag(tagString, recipe.Name); err != nil {
logrus.Fatal(err)
}
if initTag == "" {
logrus.Fatalf("unable to read version for %s from synced label. Did you try running \"abra recipe sync %s\" already?", recipe.Name, recipe.Name)
}
logrus.Warnf("discovered %s as currently synced recipe label", initTag)
prompt := &survey.Confirm{
Message: fmt.Sprintf("use %s as the initial release?", initTag),
}
var response bool
if err := survey.AskOne(prompt, &response); err != nil {
logrus.Fatal(err)
}
if !response {
logrus.Fatalf("please fix your synced label for %s and re-run this command", recipe.Name)
}
if err := createReleaseFromTag(recipe, initTag, mainAppVersion); err != nil {
if cleanUpErr := cleanUpTag(initTag, recipe.Name); err != nil {
logrus.Fatal(cleanUpErr) logrus.Fatal(cleanUpErr)
} }
logrus.Fatal(err) logrus.Fatal(err)
@ -417,10 +401,39 @@ func cleanUpTag(tag, recipeName string) error {
} }
if err := repo.DeleteTag(tag); err != nil { if err := repo.DeleteTag(tag); err != nil {
return err if !strings.Contains(err.Error(), "not found") {
return err
}
} }
logrus.Debugf("removed freshly created tag %s", tag) logrus.Debugf("removed freshly created tag %s", tag)
return nil return nil
} }
func getLabelVersion(recipe recipe.Recipe) (string, error) {
initTag, err := recipePkg.GetVersionLabelLocal(recipe)
if err != nil {
return "", err
}
if initTag == "" {
logrus.Fatalf("unable to read version for %s from synced label. Did you try running \"abra recipe sync %s\" already?", recipe.Name, recipe.Name)
}
logrus.Warnf("discovered %s as currently synced recipe label", initTag)
if !internal.NoInput {
var response bool
prompt := &survey.Confirm{Message: fmt.Sprintf("use %s as the new version?", initTag)}
if err := survey.AskOne(prompt, &response); err != nil {
return "", err
}
if !response {
return "", fmt.Errorf("please fix your synced label for %s and re-run this command", recipe.Name)
}
}
return initTag, nil
}

View File

@ -61,16 +61,21 @@ local file system.
if len(tags) == 0 && nextTag == "" { if len(tags) == 0 && nextTag == "" {
logrus.Warnf("no git tags found for %s", recipe.Name) logrus.Warnf("no git tags found for %s", recipe.Name)
fmt.Println(fmt.Sprintf(` fmt.Println(fmt.Sprintf(`
The following options are two types of initial version that you can pick for The following options are two types of initial semantic version that you can
the first published version of %s that will be in the recipe catalogue. This pick for %s that will be published in the recipe catalogue. This follows the
follows the semver convention (more on semver.org), here is a short cheatsheet semver convention (more on https://semver.org), here is a short cheatsheet
0.1.0 -> development release, still hacking 0.1.0: development release, still hacking. when you make a major upgrade
1.0.0 -> public release, assumed to be working 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.
In other words, if you want people to be able alpha test your current config 1.0.0: public release, assumed to be working. you already have a stable
for %s but don't think it is quite ready and reliable, go with 0.1.0 and people and reliable deployment of this app and feel relatively confident
will know that things are likely to change. 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.
`, recipe.Name, recipe.Name)) `, recipe.Name, recipe.Name))
var chosenVersion string var chosenVersion string