All checks were successful
continuous-integration/drone/push Build is passing
Some bugs squashed while testing this extensively.
119 lines
2.6 KiB
Go
119 lines
2.6 KiB
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"coopcloud.tech/abra/pkg/recipe"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var Major bool
|
|
var MajorFlag = &cli.BoolFlag{
|
|
Name: "major",
|
|
Usage: "Increase the major part of the version",
|
|
Value: false,
|
|
Aliases: []string{"ma", "x"},
|
|
Destination: &Major,
|
|
}
|
|
|
|
var Minor bool
|
|
var MinorFlag = &cli.BoolFlag{
|
|
Name: "minor",
|
|
Usage: "Increase the minor part of the version",
|
|
Value: false,
|
|
Aliases: []string{"mi", "y"},
|
|
Destination: &Minor,
|
|
}
|
|
|
|
var Patch bool
|
|
var PatchFlag = &cli.BoolFlag{
|
|
Name: "patch",
|
|
Usage: "Increase the patch part of the version",
|
|
Value: false,
|
|
Aliases: []string{"p", "z"},
|
|
Destination: &Patch,
|
|
}
|
|
|
|
var Dry bool
|
|
var DryFlag = &cli.BoolFlag{
|
|
Name: "dry-run",
|
|
Usage: "No changes are made, only reports changes that would be made",
|
|
Value: false,
|
|
Aliases: []string{"d"},
|
|
Destination: &Dry,
|
|
}
|
|
|
|
// PromptBumpType prompts for version bump type
|
|
func PromptBumpType(tagString string) error {
|
|
if (!Major && !Minor && !Patch) && tagString == "" {
|
|
fmt.Printf(`
|
|
semver cheat sheet (more via semver.org):
|
|
major: new features/bug fixes, backwards incompatible
|
|
minor: new features/bug fixes, backwards compatible
|
|
patch: bug fixes, backwards compatible
|
|
|
|
`)
|
|
var chosenBumpType string
|
|
prompt := &survey.Select{
|
|
Message: fmt.Sprintf("select recipe version increment type"),
|
|
Options: []string{"major", "minor", "patch"},
|
|
}
|
|
if err := survey.AskOne(prompt, &chosenBumpType); err != nil {
|
|
return err
|
|
}
|
|
SetBumpType(chosenBumpType)
|
|
}
|
|
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?")
|
|
}
|
|
}
|
|
|
|
// GetMainApp retrieves the main 'app' image name
|
|
func GetMainApp(recipe recipe.Recipe) string {
|
|
var app string
|
|
|
|
for _, service := range recipe.Config.Services {
|
|
name := service.Name
|
|
if name == "app" {
|
|
app = strings.Split(service.Image, ":")[0]
|
|
}
|
|
}
|
|
|
|
if app == "" {
|
|
logrus.Fatalf("%s has no main 'app' service?", recipe.Name)
|
|
}
|
|
|
|
return app
|
|
}
|