forked from toolshed/abra
feat: diff on release flow
Also, don't commit unstaged files.
This commit is contained in:
@ -1,29 +1,16 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// getGitDiffArgs builds the `git diff` invocation args
|
||||
func getGitDiffArgs(repoPath string) []string {
|
||||
return []string{
|
||||
"-C",
|
||||
repoPath,
|
||||
"--no-pager",
|
||||
"-c",
|
||||
"color.diff=always",
|
||||
"diff",
|
||||
}
|
||||
}
|
||||
|
||||
var recipeDiffCommand = cli.Command{
|
||||
Name: "diff",
|
||||
Usage: "Show unstaged changes in recipe config",
|
||||
@ -43,19 +30,11 @@ var recipeDiffCommand = cli.Command{
|
||||
internal.ValidateRecipe(c)
|
||||
}
|
||||
|
||||
_, err := exec.LookPath("git")
|
||||
if err != nil {
|
||||
logrus.Fatal("unable to locate 'git' command?")
|
||||
}
|
||||
|
||||
gitDiffArgs := getGitDiffArgs(path.Join(config.RECIPES_DIR, recipeName))
|
||||
diff, err := exec.Command("git", gitDiffArgs...).Output()
|
||||
if err != nil {
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
if err := gitPkg.DiffUnstaged(recipeDir); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Print(string(diff))
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -106,6 +106,18 @@ your SSH keys configured on your account.
|
||||
}
|
||||
}
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipe.Dir())
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if !isClean {
|
||||
logrus.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||
if err := gitPkg.DiffUnstaged(recipe.Dir()); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(tags) > 0 {
|
||||
logrus.Warnf("previous git tags detected, assuming this is a new semver release")
|
||||
if err := createReleaseFromPreviousTag(tagString, mainAppVersion, recipe, tags); err != nil {
|
||||
@ -244,7 +256,7 @@ func commitRelease(recipe recipe.Recipe, tag string) error {
|
||||
|
||||
msg := fmt.Sprintf("chore: publish %s release", tag)
|
||||
repoPath := path.Join(config.RECIPES_DIR, recipe.Name)
|
||||
if err := gitPkg.Commit(repoPath, ".", msg, internal.Dry); err != nil {
|
||||
if err := gitPkg.Commit(repoPath, msg, internal.Dry); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"coopcloud.tech/tagcmp"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/go-git/go-git/v5"
|
||||
@ -198,6 +199,17 @@ likely to change.
|
||||
logrus.Infof("dry run: not syncing label %s for recipe %s", nextTag, recipe.Name)
|
||||
}
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipe.Dir())
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if !isClean {
|
||||
logrus.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||
if err := gitPkg.DiffUnstaged(recipe.Dir()); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/tagcmp"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
@ -326,6 +327,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
}
|
||||
|
||||
fmt.Println(string(jsonstring))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -336,6 +338,18 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipeDir)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if !isClean {
|
||||
logrus.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||
if err := gitPkg.DiffUnstaged(recipeDir); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user