Skip to content

Commit 0fedb31

Browse files
authored
ZERO138 show summary at the end of Apply (#190)
* ZERO138 show summary at the end of Apply * ZERO138 export environment as env var * ZERO138 fix broken test
1 parent 72db194 commit 0fedb31

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

internal/apply/apply.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ Only a single environment may be suitable for an initial test, but for a real sy
4444

4545
applyAll(rootDir, *projectConfig, environments)
4646

47-
// TODO Summary
48-
flog.Infof(":check_mark_button: Done - Summary goes here.")
47+
flog.Infof(":check_mark_button: Done.")
48+
49+
summarizeAll(rootDir, *projectConfig, environments)
4950
}
5051

5152
func applyAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEnvironments []string) {
@@ -127,3 +128,39 @@ func validateEnvironments(applyEnvironments []string) {
127128
}
128129
}
129130
}
131+
132+
func summarizeAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEnvironments []string) {
133+
flog.Infof("Your projects and infrastructure have been successfully created. Here are some useful links and commands to get you started:")
134+
135+
graph := projectConfig.GetDAG()
136+
137+
// Walk the graph of modules and run `make summary`
138+
root := []dag.Vertex{projectconfig.GraphRootName}
139+
graph.DepthFirstWalk(root, func(v dag.Vertex, depth int) error {
140+
// Don't process the root
141+
if depth == 0 {
142+
return nil
143+
}
144+
145+
name := v.(string)
146+
mod := projectConfig.Modules[name]
147+
// Add env vars for the makefile
148+
envList := []string{
149+
fmt.Sprintf("ENVIRONMENT=%s", strings.Join(applyEnvironments, ",")),
150+
fmt.Sprintf("REPOSITORY=%s", mod.Files.Repository),
151+
}
152+
153+
modulePath := module.GetSourceDir(mod.Files.Source)
154+
// Passed in `dir` will only be used to find the project path, not the module path,
155+
// unless the module path is relative
156+
if module.IsLocal(mod.Files.Source) && !filepath.IsAbs(modulePath) {
157+
modulePath = filepath.Join(dir, modulePath)
158+
}
159+
160+
envList = util.AppendProjectEnvToCmdEnv(mod.Parameters, envList)
161+
util.ExecuteCommand(exec.Command("make", "summary"), modulePath, envList)
162+
return nil
163+
})
164+
165+
flog.Infof("Happy coding! :smile:")
166+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
current_dir:
22
@echo "foo: ${foo}" > project.out
33
@echo "repo: ${REPOSITORY}" >> project.out
4+
5+
summary:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
current_dir:
22
@echo "baz: ${baz}" > project.out
3+
4+
summary:

0 commit comments

Comments
 (0)