2021-11-06 22:40:22 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"coopcloud.tech/abra/pkg/recipe"
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
2021-12-27 18:56:27 +00:00
|
|
|
"github.com/docker/distribution/reference"
|
2021-11-06 22:40:22 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PromptBumpType prompts for version bump type
|
|
|
|
func PromptBumpType(tagString string) error {
|
|
|
|
if (!Major && !Minor && !Patch) && tagString == "" {
|
2021-12-21 01:04:19 +00:00
|
|
|
fmt.Printf(`semver cheat sheet (more via semver.org):
|
2021-11-06 22:40:22 +00:00
|
|
|
major: new features/bug fixes, backwards incompatible
|
|
|
|
minor: new features/bug fixes, backwards compatible
|
|
|
|
patch: bug fixes, backwards compatible
|
|
|
|
`)
|
2021-12-22 00:36:17 +00:00
|
|
|
|
2021-11-06 22:40:22 +00:00
|
|
|
var chosenBumpType string
|
|
|
|
prompt := &survey.Select{
|
|
|
|
Message: fmt.Sprintf("select recipe version increment type"),
|
|
|
|
Options: []string{"major", "minor", "patch"},
|
|
|
|
}
|
2021-12-22 00:36:17 +00:00
|
|
|
|
2021-11-06 22:40:22 +00:00
|
|
|
if err := survey.AskOne(prompt, &chosenBumpType); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-12-22 00:36:17 +00:00
|
|
|
|
2021-11-06 22:40:22 +00:00
|
|
|
SetBumpType(chosenBumpType)
|
|
|
|
}
|
2021-12-22 00:36:17 +00:00
|
|
|
|
2021-11-06 22:40:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBumpType figures out which bump type is specified
|
|
|
|
func GetBumpType() string {
|
|
|
|
var bumpType string
|
|
|
|
|
|
|
|
if Major {
|
|
|
|
bumpType = "major"
|
|
|
|
} else if Minor {
|
|
|
|
bumpType = "minor"
|
|
|
|
} else if Patch {
|
|
|
|
bumpType = "patch"
|
|
|
|
} else {
|
|
|
|
logrus.Fatal("no version bump type specififed?")
|
|
|
|
}
|
|
|
|
|
|
|
|
return bumpType
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBumpType figures out which bump type is specified
|
|
|
|
func SetBumpType(bumpType string) {
|
|
|
|
if bumpType == "major" {
|
|
|
|
Major = true
|
|
|
|
} else if bumpType == "minor" {
|
|
|
|
Minor = true
|
|
|
|
} else if bumpType == "patch" {
|
|
|
|
Patch = true
|
|
|
|
} else {
|
|
|
|
logrus.Fatal("no version bump type specififed?")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 18:56:27 +00:00
|
|
|
// GetMainAppImage retrieves the main 'app' image name
|
|
|
|
func GetMainAppImage(recipe recipe.Recipe) (string, error) {
|
|
|
|
var path string
|
2021-11-06 22:40:22 +00:00
|
|
|
|
|
|
|
for _, service := range recipe.Config.Services {
|
2021-12-27 18:56:27 +00:00
|
|
|
if service.Name == "app" {
|
|
|
|
img, err := reference.ParseNormalizedNamed(service.Image)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
path = reference.Path(img)
|
|
|
|
if strings.Contains(path, "library") {
|
|
|
|
path = strings.Split(path, "/")[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
return path, nil
|
2021-11-06 22:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 18:56:27 +00:00
|
|
|
if path == "" {
|
|
|
|
return path, fmt.Errorf("%s has no main 'app' service?", recipe.Name)
|
2021-11-06 22:40:22 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 18:56:27 +00:00
|
|
|
return path, nil
|
2021-11-06 22:40:22 +00:00
|
|
|
}
|