Skip to content

Commit

Permalink
Merge branch 'dev' into add_untracked_files_to_smart_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebradil authored Oct 29, 2023
2 parents c514df4 + 93fa2e3 commit c739328
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
19 changes: 19 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}

Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions internal/myks/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions internal/myks/smart_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c739328

Please sign in to comment.