Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply: to check module requirements before run #358

Merged
merged 12 commits into from
Apr 8, 2021
Merged

Conversation

davidcheung
Copy link
Contributor

modules must now provide a make check in their root makefile
make check must exit 0 on all modules before proceeding to apply
this allows checks for module specific binaries or check tokens permissions

modules must now provide a `make check` in their root makefile
make check must exit 0 on all modules before proceeding to apply
this allows checks for module specific binaries or check tokens permissions
@davidcheung davidcheung requested a review from a team April 1, 2021 19:05
internal/apply/apply.go Outdated Show resolved Hide resolved
@bmonkman
Copy link
Contributor

bmonkman commented Apr 1, 2021

Mind pasting text or posting a screenshot of what the final output looks like after this change?

internal/apply/apply.go Outdated Show resolved Hide resolved
@davidcheung
Copy link
Contributor Author

davidcheung commented Apr 1, 2021

image

@bmonkman
Copy link
Contributor

bmonkman commented Apr 1, 2021

Hmm I wonder if we should be checking for return code 2 (a problem with make itself, like specifying a target that doesn't exist) and provide a slightly different message to indicate that it's likely a problem with the module itself.
Might be a little weird, as the function was made more generic, and this would only apply for the check

@davidcheung
Copy link
Contributor Author

check:
	exit 1

Looks like even when i have the make target exits with error code 1, the exec still exits with code 2,
^ the snippet above still gives a code2 exit, so pretty much the exit code will always be 2?

i tried to add a binary check as follow, the code returned from exec.cmd is still 2

REQUIRED_BINS := gh foobar

check:
	$(foreach bin, $(REQUIRED_BINS),\
		$(if $(shell command -v $(bin) 2> /dev/null),$(info Found `$(bin)`),$(error Please install `$(bin)`)))

but it can still show the error if the module is diligent with printing the error since we pipe it out
image

@bmonkman
Copy link
Contributor

bmonkman commented Apr 5, 2021

Hmm okay. In that case we could check stderr for the string "No rule to make target"

@@ -41,21 +50,26 @@ Only a single environment may be suitable for an initial test, but for a real sy

flog.Infof("Infrastructure executor: %s", "Terraform")

applyAll(rootDir, *projectConfig, environments)
err = modulesWalkCmd("apply", rootDir, projectConfig, []string{"make"}, environments)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this stop on the first one that fails? We should really test all the modules, and then return the state / output of all the tests. It wouldn't be a great experience to have to run the app multiple times, installing stuff between runs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good point, right now it fails on the first error

internal/apply/apply.go Outdated Show resolved Hide resolved
@davidcheung
Copy link
Contributor Author

so the new behavior looks like this, if the check uses a script it wont have the makefile noise in the output

image

@bmonkman
Copy link
Contributor

bmonkman commented Apr 7, 2021

Cool! Can we suppress the output as we are executing the command so we can just present Zero's nicer output? I guess we would just have to optionally disable the multi writer in util.ExecuteCommand


})

t.Run("Moudles runs command overides", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and below say "Moudles"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does have a nice ring to it though..

}

go func() {
_, errStdout = io.Copy(os.Stdout, stdoutPipe)
}()
go func() {
_, errStderr = io.Copy(os.Stderr, stderrPipe)
strErrStreams := []io.Writer{errContent}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be stdErrStreams?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry yeah, should have paid more attention with all these typos

@davidcheung davidcheung merged commit 98a272d into main Apr 8, 2021
@davidcheung davidcheung deleted the check-each-module branch April 8, 2021 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants