WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
See #483
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
@ -10,6 +11,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/tagcmp"
|
||||
"github.com/distribution/reference"
|
||||
@ -45,9 +47,9 @@ func (r Recipe) Ensure(ctx EnsureContext) error {
|
||||
}
|
||||
|
||||
if r.EnvVersion != "" && !ctx.IgnoreEnvVersion {
|
||||
log.Debugf("ensuring env version %s", r.EnvVersion)
|
||||
log.Debug(i18n.G("ensuring env version %s", r.EnvVersion))
|
||||
if strings.Contains(r.EnvVersion, "+U") {
|
||||
return fmt.Errorf("can not redeploy chaos version (%s) without --chaos", r.EnvVersion)
|
||||
return errors.New(i18n.G("can not redeploy chaos version (%s) without --chaos", r.EnvVersion))
|
||||
}
|
||||
|
||||
if _, err := r.EnsureVersion(r.EnvVersion); err != nil {
|
||||
@ -146,16 +148,16 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
|
||||
|
||||
joinedTags := strings.Join(parsedTags, ", ")
|
||||
if joinedTags != "" {
|
||||
log.Debugf("read %s as tags for recipe %s", joinedTags, r.Name)
|
||||
log.Debug(i18n.G("read %s as tags for recipe %s", joinedTags, r.Name))
|
||||
}
|
||||
|
||||
var opts *git.CheckoutOptions
|
||||
if tagRef.String() == "" {
|
||||
log.Debugf("attempting to checkout '%s' as chaos commit", version)
|
||||
log.Debug(i18n.G("attempting to checkout '%s' as chaos commit", version))
|
||||
|
||||
hash, err := repo.ResolveRevision(plumbing.Revision(version))
|
||||
if err != nil {
|
||||
log.Fatalf("unable to resolve '%s': %s", version, err)
|
||||
log.Fatal(i18n.G("unable to resolve '%s': %s", version, err))
|
||||
}
|
||||
|
||||
opts = &git.CheckoutOptions{Hash: *hash, Create: false, Force: true}
|
||||
@ -173,7 +175,7 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
|
||||
return isChaosCommit, nil
|
||||
}
|
||||
|
||||
log.Debugf("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir)
|
||||
log.Debug(i18n.G("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir))
|
||||
|
||||
return isChaosCommit, nil
|
||||
}
|
||||
@ -182,11 +184,11 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
|
||||
func (r Recipe) EnsureIsClean() error {
|
||||
isClean, err := gitPkg.IsClean(r.Dir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to check git clean status in %s: %s", r.Dir, err)
|
||||
return errors.New(i18n.G("unable to check git clean status in %s: %s", r.Dir, err))
|
||||
}
|
||||
|
||||
if !isClean {
|
||||
return fmt.Errorf("%s (%s) has locally unstaged changes?", r.Name, r.Dir)
|
||||
return errors.New(i18n.G("%s (%s) has locally unstaged changes?", r.Name, r.Dir))
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -220,7 +222,7 @@ func (r Recipe) EnsureLatest() error {
|
||||
}
|
||||
|
||||
if err := worktree.Checkout(checkOutOpts); err != nil {
|
||||
log.Debugf("failed to check out %s in %s", branch, r.Dir)
|
||||
log.Debug(i18n.G("failed to check out %s in %s", branch, r.Dir))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -231,33 +233,33 @@ func (r Recipe) EnsureLatest() error {
|
||||
func (r Recipe) EnsureUpToDate() error {
|
||||
repo, err := git.PlainOpen(r.Dir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to open %s: %s", r.Dir, err)
|
||||
return errors.New(i18n.G("unable to open %s: %s", r.Dir, err))
|
||||
}
|
||||
|
||||
remotes, err := repo.Remotes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read remotes in %s: %s", r.Dir, err)
|
||||
return errors.New(i18n.G("unable to read remotes in %s: %s", r.Dir, err))
|
||||
}
|
||||
|
||||
if len(remotes) == 0 {
|
||||
log.Debugf("cannot ensure %s is up-to-date, no git remotes configured", r.Name)
|
||||
log.Debug(i18n.G("cannot ensure %s is up-to-date, no git remotes configured", r.Name))
|
||||
return nil
|
||||
}
|
||||
|
||||
worktree, err := repo.Worktree()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to open git work tree in %s: %s", r.Dir, err)
|
||||
return errors.New(i18n.G("unable to open git work tree in %s: %s", r.Dir, err))
|
||||
}
|
||||
|
||||
branch, err := gitPkg.CheckoutDefaultBranch(repo, r.Dir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to check out default branch in %s: %s", r.Dir, err)
|
||||
return errors.New(i18n.G("unable to check out default branch in %s: %s", r.Dir, err))
|
||||
}
|
||||
|
||||
fetchOpts := &git.FetchOptions{Tags: git.AllTags}
|
||||
if err := repo.Fetch(fetchOpts); err != nil {
|
||||
if !strings.Contains(err.Error(), "already up-to-date") {
|
||||
return fmt.Errorf("unable to fetch tags in %s: %s", r.Dir, err)
|
||||
return errors.New(i18n.G("unable to fetch tags in %s: %s", r.Dir, err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,11 +271,11 @@ func (r Recipe) EnsureUpToDate() error {
|
||||
|
||||
if err := worktree.Pull(opts); err != nil {
|
||||
if !strings.Contains(err.Error(), "already up-to-date") {
|
||||
return fmt.Errorf("unable to git pull in %s: %s", r.Dir, err)
|
||||
return errors.New(i18n.G("unable to git pull in %s: %s", r.Dir, err))
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("fetched latest git changes for %s", r.Name)
|
||||
log.Debug(i18n.G("fetched latest git changes for %s", r.Name))
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -362,7 +364,7 @@ func (r Recipe) Tags() ([]string, error) {
|
||||
return version1.IsLessThan(version2)
|
||||
})
|
||||
|
||||
log.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name)
|
||||
log.Debug(i18n.G("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name))
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
@ -373,7 +375,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
|
||||
|
||||
versions := RecipeVersions{}
|
||||
|
||||
log.Debugf("git: opening repository in %s", r.Dir)
|
||||
log.Debug(i18n.G("git: opening repository in %s", r.Dir))
|
||||
|
||||
repo, err := git.PlainOpen(r.Dir)
|
||||
if err != nil {
|
||||
@ -393,7 +395,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
|
||||
if err := gitTags.ForEach(func(ref *plumbing.Reference) (err error) {
|
||||
tag := strings.TrimPrefix(string(ref.Name()), "refs/tags/")
|
||||
|
||||
log.Debugf("processing %s for %s", tag, r.Name)
|
||||
log.Debug(i18n.G("processing %s for %s", tag, r.Name))
|
||||
|
||||
checkOutOpts := &git.CheckoutOptions{
|
||||
Create: false,
|
||||
@ -401,11 +403,11 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
|
||||
Branch: plumbing.ReferenceName(ref.Name()),
|
||||
}
|
||||
if err := worktree.Checkout(checkOutOpts); err != nil {
|
||||
log.Debugf("failed to check out %s in %s", tag, r.Dir)
|
||||
log.Debug(i18n.G("failed to check out %s in %s", tag, r.Dir))
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("git checkout: %s in %s", ref.Name(), r.Dir)
|
||||
log.Debug(i18n.G("git checkout: %s in %s", ref.Name(), r.Dir))
|
||||
|
||||
config, err := r.GetComposeConfig(nil)
|
||||
if err != nil {
|
||||
@ -429,7 +431,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
|
||||
case reference.NamedTagged:
|
||||
tag = img.(reference.NamedTagged).Tag()
|
||||
case reference.Named:
|
||||
warnMsg = append(warnMsg, fmt.Sprintf("%s service is missing image tag?", path))
|
||||
warnMsg = append(warnMsg, i18n.G("%s service is missing image tag?", path))
|
||||
continue
|
||||
}
|
||||
|
||||
@ -453,7 +455,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
|
||||
|
||||
sortRecipeVersions(versions)
|
||||
|
||||
log.Debugf("collected %s for %s", versions, r.Dir)
|
||||
log.Debug(i18n.G("collected %s for %s", versions, r.Dir))
|
||||
|
||||
var uniqueWarnings []string
|
||||
for _, w := range warnMsg {
|
||||
|
Reference in New Issue
Block a user