forked from toolshed/abra
refactor: use central logger
This commit is contained in:
@ -13,13 +13,13 @@ import (
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/tagcmp"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -65,74 +65,74 @@ your SSH keys configured on your account.
|
||||
|
||||
imagesTmp, err := getImageVersions(recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
mainApp, err := internal.GetMainAppImage(recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
mainAppVersion := imagesTmp[mainApp]
|
||||
if mainAppVersion == "" {
|
||||
logrus.Fatalf("main app service version for %s is empty?", recipe.Name)
|
||||
log.Fatalf("main app service version for %s is empty?", recipe.Name)
|
||||
}
|
||||
|
||||
tagString := c.Args().Get(1)
|
||||
if tagString != "" {
|
||||
if _, err := tagcmp.Parse(tagString); err != nil {
|
||||
logrus.Fatalf("cannot parse %s, invalid tag specified?", tagString)
|
||||
log.Fatalf("cannot parse %s, invalid tag specified?", tagString)
|
||||
}
|
||||
}
|
||||
|
||||
if (internal.Major || internal.Minor || internal.Patch) && tagString != "" {
|
||||
logrus.Fatal("cannot specify tag and bump type at the same time")
|
||||
log.Fatal("cannot specify tag and bump type at the same time")
|
||||
}
|
||||
|
||||
if tagString != "" {
|
||||
if err := createReleaseFromTag(recipe, tagString, mainAppVersion); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
tags, err := recipe.Tags()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if tagString == "" && (!internal.Major && !internal.Minor && !internal.Patch) {
|
||||
var err error
|
||||
tagString, err = getLabelVersion(recipe, false)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipe.Dir())
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !isClean {
|
||||
logrus.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||
log.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||
if err := gitPkg.DiffUnstaged(recipe.Dir()); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(tags) > 0 {
|
||||
logrus.Warnf("previous git tags detected, assuming this is a new semver release")
|
||||
log.Warnf("previous git tags detected, assuming this is a new semver release")
|
||||
if err := createReleaseFromPreviousTag(tagString, mainAppVersion, recipe, tags); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
logrus.Warnf("no tag specified and no previous tag available for %s, assuming this is the initial release", recipe.Name)
|
||||
log.Warnf("no tag specified and no previous tag available for %s, assuming this is the initial release", recipe.Name)
|
||||
|
||||
if err := createReleaseFromTag(recipe, tagString, mainAppVersion); err != nil {
|
||||
if cleanUpErr := cleanUpTag(tagString, recipe.Name); err != nil {
|
||||
logrus.Fatal(cleanUpErr)
|
||||
log.Fatal(cleanUpErr)
|
||||
}
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,19 +210,19 @@ func createReleaseFromTag(recipe recipe.Recipe, tagString, mainAppVersion string
|
||||
}
|
||||
|
||||
if err := addReleaseNotes(recipe, tagString); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := commitRelease(recipe, tagString); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := tagRelease(tagString, repo); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := pushRelease(recipe, tagString); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -259,7 +259,7 @@ func addReleaseNotes(recipe recipe.Recipe, tag string) error {
|
||||
if _, err := os.Stat(nextReleaseNotePath); err == nil {
|
||||
// release/next note exists. Move it to release/<tag>
|
||||
if internal.Dry {
|
||||
logrus.Debugf("dry run: move release note from 'next' to %s", tag)
|
||||
log.Debugf("dry run: move release note from 'next' to %s", tag)
|
||||
return nil
|
||||
}
|
||||
if !internal.NoInput {
|
||||
@ -321,7 +321,7 @@ func addReleaseNotes(recipe recipe.Recipe, tag string) error {
|
||||
|
||||
func commitRelease(recipe recipe.Recipe, tag string) error {
|
||||
if internal.Dry {
|
||||
logrus.Debugf("dry run: no changes committed")
|
||||
log.Debugf("dry run: no changes committed")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -347,7 +347,7 @@ func commitRelease(recipe recipe.Recipe, tag string) error {
|
||||
|
||||
func tagRelease(tagString string, repo *git.Repository) error {
|
||||
if internal.Dry {
|
||||
logrus.Debugf("dry run: no git tag created (%s)", tagString)
|
||||
log.Debugf("dry run: no git tag created (%s)", tagString)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -367,14 +367,14 @@ func tagRelease(tagString string, repo *git.Repository) error {
|
||||
}
|
||||
|
||||
hash := formatter.SmallSHA(head.Hash().String())
|
||||
logrus.Debugf(fmt.Sprintf("created tag %s at %s", tagString, hash))
|
||||
log.Debugf(fmt.Sprintf("created tag %s at %s", tagString, hash))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func pushRelease(recipe recipe.Recipe, tagString string) error {
|
||||
if internal.Dry {
|
||||
logrus.Info("dry run: no changes published")
|
||||
log.Info("dry run: no changes published")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -393,9 +393,9 @@ func pushRelease(recipe recipe.Recipe, tagString string) error {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/src/tag/%s", config.REPOS_BASE_URL, recipe.Name, tagString)
|
||||
logrus.Infof("new release published: %s", url)
|
||||
log.Infof("new release published: %s", url)
|
||||
} else {
|
||||
logrus.Info("no -p/--publish passed, not publishing")
|
||||
log.Info("no -p/--publish passed, not publishing")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -468,7 +468,7 @@ func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recip
|
||||
}
|
||||
|
||||
if lastGitTag.String() == tagString {
|
||||
logrus.Fatalf("latest git tag (%s) and synced label (%s) are the same?", lastGitTag, tagString)
|
||||
log.Fatalf("latest git tag (%s) and synced label (%s) are the same?", lastGitTag, tagString)
|
||||
}
|
||||
|
||||
if !internal.NoInput {
|
||||
@ -478,28 +478,28 @@ func createReleaseFromPreviousTag(tagString, mainAppVersion string, recipe recip
|
||||
|
||||
var ok bool
|
||||
if err := survey.AskOne(prompt, &ok); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !ok {
|
||||
logrus.Fatal("exiting as requested")
|
||||
log.Fatal("exiting as requested")
|
||||
}
|
||||
}
|
||||
|
||||
if err := addReleaseNotes(recipe, tagString); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := commitRelease(recipe, tagString); err != nil {
|
||||
logrus.Fatalf("failed to commit changes: %s", err.Error())
|
||||
log.Fatalf("failed to commit changes: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := tagRelease(tagString, repo); err != nil {
|
||||
logrus.Fatalf("failed to tag release: %s", err.Error())
|
||||
log.Fatalf("failed to tag release: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := pushRelease(recipe, tagString); err != nil {
|
||||
logrus.Fatalf("failed to publish new release: %s", err.Error())
|
||||
log.Fatalf("failed to publish new release: %s", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -519,7 +519,7 @@ func cleanUpTag(tag, recipeName string) error {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("removed freshly created tag %s", tag)
|
||||
log.Debugf("removed freshly created tag %s", tag)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -531,10 +531,10 @@ func getLabelVersion(recipe recipe.Recipe, prompt bool) (string, error) {
|
||||
}
|
||||
|
||||
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)
|
||||
log.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)
|
||||
log.Warnf("discovered %s as currently synced recipe label", initTag)
|
||||
|
||||
if prompt && !internal.NoInput {
|
||||
var response bool
|
||||
|
Reference in New Issue
Block a user