From 6c55796c7cb789b77b16d41acdca1e07f03fa7d3 Mon Sep 17 00:00:00 2001 From: CJ Hawkins Date: Fri, 26 Jun 2020 16:07:21 -0700 Subject: [PATCH 1/3] ZERO138 show summary at the end of Apply --- internal/apply/apply.go | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/internal/apply/apply.go b/internal/apply/apply.go index 7b1fc5a69..69b02b521 100644 --- a/internal/apply/apply.go +++ b/internal/apply/apply.go @@ -44,8 +44,9 @@ Only a single environment may be suitable for an initial test, but for a real sy applyAll(rootDir, *projectConfig, environments) - // TODO Summary - flog.Infof(":check_mark_button: Done - Summary goes here.") + flog.Infof(":check_mark_button: Done.") + + summarizeAll(rootDir, *projectConfig) } func applyAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEnvironments []string) { @@ -127,3 +128,39 @@ func validateEnvironments(applyEnvironments []string) { } } } + +func summarizeAll(dir string, projectConfig projectconfig.ZeroProjectConfig) { + flog.Infof("Your projects and infrastructure have been successfully created. Here are some useful links and commands to get you started:") + + graph := projectConfig.GetDAG() + + // Walk the graph of modules and run `make summary` + root := []dag.Vertex{projectconfig.GraphRootName} + graph.DepthFirstWalk(root, func(v dag.Vertex, depth int) error { + // Don't process the root + if depth == 0 { + return nil + } + + name := v.(string) + mod := projectConfig.Modules[name] + // Add env vars for the makefile + envList := []string{ + fmt.Sprintf("REPOSITORY=%s", mod.Files.Repository), + } + + modulePath := module.GetSourceDir(mod.Files.Source) + // Passed in `dir` will only be used to find the project path, not the module path, + // unless the module path is relative + if module.IsLocal(mod.Files.Source) && !filepath.IsAbs(modulePath) { + modulePath = filepath.Join(dir, modulePath) + } + + envList = util.AppendProjectEnvToCmdEnv(mod.Parameters, envList) + util.ExecuteCommand(exec.Command("make", "summary"), modulePath, envList) + fmt.Println() + return nil + }) + + flog.Infof("Happy coding! :smile:") +} From 743b86b5ce48f9c33e16947dd08c5ca12e37b0d2 Mon Sep 17 00:00:00 2001 From: CJ Hawkins Date: Mon, 29 Jun 2020 17:33:55 -0700 Subject: [PATCH 2/3] ZERO138 export environment as env var --- internal/apply/apply.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/apply/apply.go b/internal/apply/apply.go index 69b02b521..7faba5677 100644 --- a/internal/apply/apply.go +++ b/internal/apply/apply.go @@ -46,7 +46,7 @@ Only a single environment may be suitable for an initial test, but for a real sy flog.Infof(":check_mark_button: Done.") - summarizeAll(rootDir, *projectConfig) + summarizeAll(rootDir, *projectConfig, environments) } func applyAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEnvironments []string) { @@ -129,7 +129,7 @@ func validateEnvironments(applyEnvironments []string) { } } -func summarizeAll(dir string, projectConfig projectconfig.ZeroProjectConfig) { +func summarizeAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEnvironments []string) { flog.Infof("Your projects and infrastructure have been successfully created. Here are some useful links and commands to get you started:") graph := projectConfig.GetDAG() @@ -146,6 +146,7 @@ func summarizeAll(dir string, projectConfig projectconfig.ZeroProjectConfig) { mod := projectConfig.Modules[name] // Add env vars for the makefile envList := []string{ + fmt.Sprintf("ENVIRONMENT=%s", strings.Join(applyEnvironments, ",")), fmt.Sprintf("REPOSITORY=%s", mod.Files.Repository), } @@ -158,7 +159,6 @@ func summarizeAll(dir string, projectConfig projectconfig.ZeroProjectConfig) { envList = util.AppendProjectEnvToCmdEnv(mod.Parameters, envList) util.ExecuteCommand(exec.Command("make", "summary"), modulePath, envList) - fmt.Println() return nil }) From f9050b5b0bf7db5bde6955d7114b5d5913e9a98c Mon Sep 17 00:00:00 2001 From: CJ Hawkins Date: Mon, 29 Jun 2020 18:25:22 -0700 Subject: [PATCH 3/3] ZERO138 fix broken test --- tests/test_data/apply/project1/Makefile | 2 ++ tests/test_data/apply/project2/Makefile | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/test_data/apply/project1/Makefile b/tests/test_data/apply/project1/Makefile index a60a27603..181788f40 100644 --- a/tests/test_data/apply/project1/Makefile +++ b/tests/test_data/apply/project1/Makefile @@ -1,3 +1,5 @@ current_dir: @echo "foo: ${foo}" > project.out @echo "repo: ${REPOSITORY}" >> project.out + +summary: diff --git a/tests/test_data/apply/project2/Makefile b/tests/test_data/apply/project2/Makefile index a17340f10..41f42f07b 100644 --- a/tests/test_data/apply/project2/Makefile +++ b/tests/test_data/apply/project2/Makefile @@ -1,2 +1,4 @@ current_dir: @echo "baz: ${baz}" > project.out + +summary: