From ffddef1e9978446d4bb75b9ba966c86335aa952b Mon Sep 17 00:00:00 2001 From: Mykso Bot Date: Fri, 29 Sep 2023 11:31:49 +0000 Subject: [PATCH 1/4] chore(release): 2.0.4 [skip ci] ## [2.0.4](https://github.com/mykso/myks/compare/v2.0.3...v2.0.4) (2023-09-29) ### Bug Fixes * **release:** trigger ([b6dd8bb](https://github.com/mykso/myks/commit/b6dd8bba5458b004c6e58c3365a6e969f2222db2)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a74b43cd..0dfd114d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.0.4](https://github.com/mykso/myks/compare/v2.0.3...v2.0.4) (2023-09-29) + + +### Bug Fixes + +* **release:** trigger ([b6dd8bb](https://github.com/mykso/myks/commit/b6dd8bba5458b004c6e58c3365a6e969f2222db2)) + ## [2.0.3](https://github.com/mykso/myks/compare/v2.0.2...v2.0.3) (2023-09-29) From b39eb8df0a9cc22524314431b61bb7474608d270 Mon Sep 17 00:00:00 2001 From: Kris Budde Date: Mon, 16 Oct 2023 19:11:06 +0200 Subject: [PATCH 2/4] fix(init): ignore top level .myks folder (#116) --- internal/myks/assets/{envs_gitignore => gitignore} | 0 internal/myks/bootstrap.go | 14 +++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) rename internal/myks/assets/{envs_gitignore => gitignore} (100%) diff --git a/internal/myks/assets/envs_gitignore b/internal/myks/assets/gitignore similarity index 100% rename from internal/myks/assets/envs_gitignore rename to internal/myks/assets/gitignore diff --git a/internal/myks/bootstrap.go b/internal/myks/bootstrap.go index 431519af..47fb68c5 100644 --- a/internal/myks/bootstrap.go +++ b/internal/myks/bootstrap.go @@ -12,8 +12,8 @@ import ( //go:embed assets/data-schema.ytt.yaml var dataSchema []byte -//go:embed assets/envs_gitignore -var envsGitignore []byte +//go:embed assets/gitignore +var gitignore []byte //go:embed assets/myks_config.yaml var myksConfig []byte @@ -41,7 +41,7 @@ func (g *Globe) Bootstrap(force, onlyPrint bool, components []string) error { if onlyPrint { if compMap["gitignore"] { - printFileNicely(".gitignore", string(envsGitignore), "Terminfo") + printFileNicely(".gitignore", string(gitignore), "Terminfo") } if compMap["config"] { printFileNicely(".myks.yaml", string(myksConfig), "YAML") @@ -85,17 +85,17 @@ func (g *Globe) createBaseFileStructure(force bool) error { envDir := filepath.Join(g.RootDir, g.EnvironmentBaseDir) protoDir := filepath.Join(g.RootDir, g.PrototypesDir) renderedDir := filepath.Join(g.RootDir, g.RenderedDir) - envsGitignoreFile := filepath.Join(envDir, ".gitignore") + gitignoreFile := filepath.Join(g.RootDir, ".gitignore") myksConfigFile := filepath.Join(g.RootDir, ".myks.yaml") log.Debug().Str("environments directory", envDir).Msg("") log.Debug().Str("prototypes directory", protoDir).Msg("") log.Debug().Str("rendered directory", renderedDir).Msg("") - log.Debug().Str("environments .gitignore file", envsGitignoreFile).Msg("") + log.Debug().Str(".gitignore file", gitignoreFile).Msg("") log.Debug().Str("myks config file", myksConfigFile).Msg("") if !force { - for _, path := range []string{envDir, protoDir, renderedDir, envsGitignoreFile, myksConfigFile} { + for _, path := range []string{envDir, protoDir, renderedDir, gitignoreFile, myksConfigFile} { ok, err := isExist(path) if err != nil { return err @@ -120,7 +120,7 @@ func (g *Globe) createBaseFileStructure(force bool) error { return err } - if err := os.WriteFile(envsGitignoreFile, envsGitignore, 0o600); err != nil { + if err := os.WriteFile(gitignoreFile, gitignore, 0o600); err != nil { return err } From 0a6349a974fca2317f7d51adae337a3dce0dc4c0 Mon Sep 17 00:00:00 2001 From: German Lashevich Date: Mon, 16 Oct 2023 19:38:12 +0200 Subject: [PATCH 3/4] feat(ui): add smart-mode.only-print flag for debugging --- cmd/root.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index c5697aa1..f77123c1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/logrusorgru/aurora/v4" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -57,6 +58,9 @@ func init() { "if not provided, only local changes will be considered" rootCmd.PersistentFlags().String("smart-mode.base-revision", "", smartModeBaseRevisionHelp) + smartModeOnlyPrintHelp := "only print the list of environments and applications that would be rendered in Smart Mode" + rootCmd.PersistentFlags().Bool("smart-mode.only-print", false, smartModeOnlyPrintHelp) + if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { log.Fatal().Err(err).Msg("Unable to bind flags") } @@ -125,6 +129,21 @@ func detectTargetEnvsAndApps(cmd *cobra.Command, args []string) (err error) { Interface("envAppMap", envAppMap). Msg("Parsed arguments") + if viper.GetBool("smart-mode.only-print") { + fmt.Println(aurora.Bold("\nSmart Mode detected:")) + for env, apps := range envAppMap { + fmt.Printf("→ %s\n", env) + if apps == nil { + fmt.Println(aurora.Bold(" ALL")) + } else { + for _, app := range apps { + fmt.Printf(" %s\n", app) + } + } + } + os.Exit(0) + } + return nil } From 93fa2e3786250b4e0c305af0923204d2bf1e9341 Mon Sep 17 00:00:00 2001 From: German Lashevich Date: Mon, 16 Oct 2023 19:58:56 +0200 Subject: [PATCH 4/4] fix(smart-mode): filter out deleted envs and apps Closes #114 --- internal/myks/smart_mode.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/myks/smart_mode.go b/internal/myks/smart_mode.go index 125478ca..1b756a7b 100644 --- a/internal/myks/smart_mode.go +++ b/internal/myks/smart_mode.go @@ -156,6 +156,19 @@ func (g *Globe) runSmartMode(changedFiles ChangedFiles) EnvAppMap { } } + // Remove environments and applications that are not found in the filesystem + for env, apps := range envAppMap { + if _, ok := g.environments[env]; !ok { + delete(envAppMap, env) + continue + } + for _, app := range apps { + if _, ok := g.environments[env].foundApplications[app]; !ok { + envAppMap[env] = filterSlice(envAppMap[env], func(s string) bool { return s != app }) + } + } + } + return envAppMap }