-
Notifications
You must be signed in to change notification settings - Fork 70
Fix compute build rendered output
#842
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
Changes from all commits
3124283
b17a353
feab26c
4f29133
97f6173
952746d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,7 +157,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) { | |
| return err | ||
| } | ||
|
|
||
| language, err := language(toolchain, c, out) | ||
| language, err := language(toolchain, c, in, out, spinner) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was related to simplifying the Toolchain interface's |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -167,17 +167,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) { | |
| return err | ||
| } | ||
|
|
||
| postBuildCallback := func() error { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fix the order of rendering I needed to move this logic (and associated prompt functionality) inside the toolchain implementation. |
||
| if !c.Globals.Flags.AutoYes && !c.Globals.Flags.NonInteractive { | ||
| err := promptForBuildContinue(CustomPostBuildScriptMessage, c.Manifest.File.Scripts.PostBuild, out, in, c.Globals.Verbose()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| if err := language.Build(out, spinner, c.Globals.Flags.Verbose, postBuildCallback); err != nil { | ||
| if err := language.Build(); err != nil { | ||
| c.Globals.ErrLog.AddWithContext(err, map[string]any{ | ||
| "Language": language.Name, | ||
| }) | ||
|
|
@@ -318,7 +308,7 @@ func toolchain(c *BuildCommand) (string, error) { | |
| } | ||
|
|
||
| // language returns a pointer to a supported language. | ||
| func language(toolchain string, c *BuildCommand, out io.Writer) (*Language, error) { | ||
| func language(toolchain string, c *BuildCommand, in io.Reader, out io.Writer, spinner text.Spinner) (*Language, error) { | ||
| var language *Language | ||
| switch toolchain { | ||
| case "assemblyscript": | ||
|
|
@@ -327,10 +317,11 @@ func language(toolchain string, c *BuildCommand, out io.Writer) (*Language, erro | |
| SourceDirectory: AsSourceDirectory, | ||
| Toolchain: NewAssemblyScript( | ||
| &c.Manifest.File, | ||
| c.Globals.ErrLog, | ||
| c.Flags.Timeout, | ||
| c.Globals, | ||
| c.Flags, | ||
| in, | ||
| out, | ||
| c.Globals.Verbose(), | ||
| spinner, | ||
| ), | ||
| }) | ||
| case "go": | ||
|
|
@@ -339,11 +330,11 @@ func language(toolchain string, c *BuildCommand, out io.Writer) (*Language, erro | |
| SourceDirectory: GoSourceDirectory, | ||
| Toolchain: NewGo( | ||
| &c.Manifest.File, | ||
| c.Globals.ErrLog, | ||
| c.Flags.Timeout, | ||
| c.Globals.Config.Language.Go, | ||
| c.Globals, | ||
| c.Flags, | ||
| in, | ||
| out, | ||
| c.Globals.Verbose(), | ||
| spinner, | ||
| ), | ||
| }) | ||
| case "javascript": | ||
|
|
@@ -352,10 +343,11 @@ func language(toolchain string, c *BuildCommand, out io.Writer) (*Language, erro | |
| SourceDirectory: JsSourceDirectory, | ||
| Toolchain: NewJavaScript( | ||
| &c.Manifest.File, | ||
| c.Globals.ErrLog, | ||
| c.Flags.Timeout, | ||
| c.Globals, | ||
| c.Flags, | ||
| in, | ||
| out, | ||
| c.Globals.Verbose(), | ||
| spinner, | ||
| ), | ||
| }) | ||
| case "rust": | ||
|
|
@@ -364,20 +356,23 @@ func language(toolchain string, c *BuildCommand, out io.Writer) (*Language, erro | |
| SourceDirectory: RustSourceDirectory, | ||
| Toolchain: NewRust( | ||
| &c.Manifest.File, | ||
| c.Globals.ErrLog, | ||
| c.Flags.Timeout, | ||
| c.Globals.Config.Language.Rust, | ||
| c.Globals, | ||
| c.Flags, | ||
| in, | ||
| out, | ||
| c.Globals.Verbose(), | ||
| spinner, | ||
| ), | ||
| }) | ||
| case "other": | ||
| language = NewLanguage(&LanguageOptions{ | ||
| Name: "other", | ||
| Toolchain: NewOther( | ||
| c.Manifest.File.Scripts, | ||
| c.Globals.ErrLog, | ||
| c.Flags.Timeout, | ||
| &c.Manifest.File, | ||
| c.Globals, | ||
| c.Flags, | ||
| in, | ||
| out, | ||
| spinner, | ||
| ), | ||
| }) | ||
| default: | ||
|
|
@@ -406,35 +401,6 @@ func binDir(c *BuildCommand) error { | |
| return nil | ||
| } | ||
|
|
||
| // promptForBuildContinue ensures the user is happy to continue with the build | ||
| // when there is either a custom build or post build in the fastly.toml | ||
| // manifest file. | ||
| func promptForBuildContinue(msg, script string, out io.Writer, in io.Reader, verbose bool) error { | ||
| text.Info(out, "%s:\n", msg) | ||
| text.Break(out) | ||
| text.Indent(out, 4, "%s", script) | ||
|
|
||
| var post string | ||
| if msg == CustomPostBuildScriptMessage { | ||
| post = "post " | ||
| } | ||
|
|
||
| label := fmt.Sprintf("\nAre you sure you want to continue with the %sbuild step? [y/N] ", post) | ||
| answer, err := text.AskYesNo(out, label, in) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if !answer { | ||
| text.Info(out, "Stopping the %sbuild process.", post) | ||
| if !verbose { | ||
| text.Break(out) | ||
| } | ||
| return fsterr.ErrBuildStopped | ||
| } | ||
| text.Break(out) | ||
| return nil | ||
| } | ||
|
|
||
| // CreatePackageArchive packages build artifacts as a Fastly package. | ||
| // The package must be a GZipped Tar archive. | ||
| // | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -727,8 +727,8 @@ func TestBuildOther(t *testing.T) { | |
| wantOutput: []string{ | ||
| "echo doing a post build", | ||
| "Are you sure you want to continue with the post build step?", | ||
| "Stopping the post build process", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed a redundant message that was duplicating the final error message displayed. |
||
| }, | ||
| wantError: "build process stopped by user", | ||
| }, | ||
| // NOTE: All following tests pass --verbose so we can see post_build output. | ||
| { | ||
|
|
@@ -772,14 +772,14 @@ func TestBuildOther(t *testing.T) { | |
| name = "test" | ||
| [scripts] | ||
| build = "touch ./bin/main.wasm" | ||
| post_build = "echo doing a post build with no confirmation prompt"`, | ||
| post_build = "echo doing a post build with no confirmation prompt && exit 1"`, // force an error so post_build is displayed to validate it was run. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now only show build/post_build output when there is an error (no need to show it if the project compiles successfully) and so we needed to fix the test to force an error so we could validate the post_build script was run. |
||
| wantOutput: []string{ | ||
| "doing a post build with no confirmation prompt", | ||
| "Built package", | ||
| }, | ||
| dontWantOutput: []string{ | ||
| "Are you sure you want to continue with the build step?", | ||
| }, | ||
| wantError: "exit status 1", // because we have to trigger an error to see the post_build output | ||
| }, | ||
| } { | ||
| t.Run(testcase.name, func(t *testing.T) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing a nil pointer dereference bug