From af785739999650b083a330457a1fd264f6062c30 Mon Sep 17 00:00:00 2001 From: maxwelbm Date: Tue, 9 Jul 2024 11:46:42 -0300 Subject: [PATCH] fix: deploy command calls the build and executes the build print --- pkg/cmd/build/build.go | 11 ++++------- pkg/cmd/build/run.go | 8 ++++---- pkg/cmd/build/utils.go | 22 +++++++++++++++------- pkg/cmd/build/vulcan.go | 4 ++-- pkg/cmd/deploy/bucket.go | 3 ++- pkg/cmd/deploy/deploy.go | 5 +++-- pkg/cmd/deploy/purge.go | 6 ++++-- pkg/cmd/deploy/requests.go | 2 +- pkg/cmd/dev/dev.go | 2 +- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/pkg/cmd/build/build.go b/pkg/cmd/build/build.go index 904fbc816..717faa48e 100644 --- a/pkg/cmd/build/build.go +++ b/pkg/cmd/build/build.go @@ -44,7 +44,8 @@ func NewCobraCmd(build *BuildCmd) *cobra.Command { SilenceUsage: true, Example: heredoc.Doc("\n$ azion build\n"), RunE: func(cmd *cobra.Command, args []string) error { - return build.run(fields) + msgs := []string{} + return build.run(fields, &msgs) }, } @@ -83,11 +84,7 @@ func NewBuildCmd(f *cmdutil.Factory) *BuildCmd { } } -func (cmd *BuildCmd) Run(fields *contracts.BuildInfo) error { - return cmd.run(fields) -} - -func (cmd *BuildCmd) ExternalRun(fields *contracts.BuildInfo, confPath string) error { +func (cmd *BuildCmd) ExternalRun(fields *contracts.BuildInfo, confPath string, msgs *[]string) error { fields.ProjectPath = confPath - return cmd.run(fields) + return cmd.run(fields, msgs) } diff --git a/pkg/cmd/build/run.go b/pkg/cmd/build/run.go index ac832d56d..6e5e2a44d 100644 --- a/pkg/cmd/build/run.go +++ b/pkg/cmd/build/run.go @@ -10,10 +10,10 @@ import ( "go.uber.org/zap" ) -func (cmd *BuildCmd) run(fields *contracts.BuildInfo) error { +func (cmd *BuildCmd) run(fields *contracts.BuildInfo, msgs *[]string) error { logger.Debug("Running build command") - err := RunBuildCmdLine(cmd, fields) + err := RunBuildCmdLine(cmd, fields, msgs) if err != nil { return err } @@ -21,7 +21,7 @@ func (cmd *BuildCmd) run(fields *contracts.BuildInfo) error { return nil } -func RunBuildCmdLine(cmd *BuildCmd, fields *contracts.BuildInfo) error { +func RunBuildCmdLine(cmd *BuildCmd, fields *contracts.BuildInfo, msgs *[]string) error { var err error conf, err := cmd.GetAzionJsonContent(fields.ProjectPath) @@ -64,6 +64,6 @@ func RunBuildCmdLine(cmd *BuildCmd, fields *contracts.BuildInfo) error { vulcanParams += " --firewall " } - return vulcan(cmd, conf, vulcanParams, fields) + return vulcan(cmd, conf, vulcanParams, fields, msgs) } diff --git a/pkg/cmd/build/utils.go b/pkg/cmd/build/utils.go index 3687dc998..68a5e66a2 100644 --- a/pkg/cmd/build/utils.go +++ b/pkg/cmd/build/utils.go @@ -9,15 +9,19 @@ import ( "go.uber.org/zap" ) -func runCommand(cmd *BuildCmd, command string) error { - msgs := []string{} +func runCommand(cmd *BuildCmd, command string, msgs *[]string) error { + var hasDeployMessage bool + if len(*msgs) > 0 { + hasDeployMessage = true + } + logger.FInfoFlags(cmd.Io.Out, msg.BuildStart, cmd.f.Format, cmd.f.Out) - msgs = append(msgs, msg.BuildStart) + *msgs = append(*msgs, msg.BuildStart) logger.FInfoFlags(cmd.Io.Out, msg.BuildRunningCmd, cmd.f.Format, cmd.f.Out) - msgs = append(msgs, msg.BuildRunningCmd) + *msgs = append(*msgs, msg.BuildRunningCmd) logger.FInfoFlags(cmd.Io.Out, fmt.Sprintf("$ %s\n", command), cmd.f.Format, cmd.f.Out) - msgs = append(msgs, fmt.Sprintf("$ %s\n", command)) + *msgs = append(*msgs, fmt.Sprintf("$ %s\n", command)) err := cmd.CommandRunInteractive(cmd.f, command) if err != nil { @@ -26,10 +30,14 @@ func runCommand(cmd *BuildCmd, command string) error { } logger.FInfoFlags(cmd.Io.Out, msg.BuildSuccessful, cmd.f.Format, cmd.f.Out) - msgs = append(msgs, msg.BuildSuccessful) + *msgs = append(*msgs, msg.BuildSuccessful) + + if hasDeployMessage { + return nil + } outSlice := output.SliceOutput{ - Messages: msgs, + Messages: *msgs, GeneralOutput: output.GeneralOutput{ Out: cmd.f.IOStreams.Out, Flags: cmd.f.Flags, diff --git a/pkg/cmd/build/vulcan.go b/pkg/cmd/build/vulcan.go index 3e6457e4a..a576d21a5 100644 --- a/pkg/cmd/build/vulcan.go +++ b/pkg/cmd/build/vulcan.go @@ -12,7 +12,7 @@ import ( "go.uber.org/zap" ) -func vulcan(cmd *BuildCmd, conf *contracts.AzionApplicationOptions, vulcanParams string, fields *contracts.BuildInfo) error { +func vulcan(cmd *BuildCmd, conf *contracts.AzionApplicationOptions, vulcanParams string, fields *contracts.BuildInfo, msgs *[]string) error { // checking if vulcan major is correct vulcanVer, err := cmd.CommandRunner(cmd.f, "npm show edge-functions version", []string{}) if err != nil { @@ -26,7 +26,7 @@ func vulcan(cmd *BuildCmd, conf *contracts.AzionApplicationOptions, vulcanParams command := vul.Command("", "build --preset %s --mode %s%s", cmd.f) - err = runCommand(cmd, fmt.Sprintf(command, strings.ToLower(conf.Preset), strings.ToLower(conf.Mode), vulcanParams)) + err = runCommand(cmd, fmt.Sprintf(command, strings.ToLower(conf.Preset), strings.ToLower(conf.Mode), vulcanParams), msgs) if err != nil { return fmt.Errorf(msg.ErrorVulcanExecute.Error(), err.Error()) } diff --git a/pkg/cmd/deploy/bucket.go b/pkg/cmd/deploy/bucket.go index 6c62c856b..609aafd7e 100644 --- a/pkg/cmd/deploy/bucket.go +++ b/pkg/cmd/deploy/bucket.go @@ -25,7 +25,8 @@ func (cmd *DeployCmd) doBucket( return nil } - logger.FInfo(cmd.Io.Out, msg.ProjectNameMessage) + logger.FInfoFlags(cmd.Io.Out, msg.ProjectNameMessage, cmd.F.Format, cmd.F.Out) + *msgs = append(*msgs, msg.ProjectNameMessage) nameBucket := replaceInvalidChars(conf.Name) err := client.CreateBucket(ctx, api.RequestBucket{ diff --git a/pkg/cmd/deploy/deploy.go b/pkg/cmd/deploy/deploy.go index dc044eea1..7385d9ede 100644 --- a/pkg/cmd/deploy/deploy.go +++ b/pkg/cmd/deploy/deploy.go @@ -108,8 +108,9 @@ func (cmd *DeployCmd) ExternalRun(f *cmdutil.Factory, configPath string) error { } func (cmd *DeployCmd) Run(f *cmdutil.Factory) error { - logger.Debug("Running deploy command") msgs := []string{} + logger.FInfoFlags(cmd.F.IOStreams.Out, "Running deploy command", cmd.F.Format, cmd.F.Out) + msgs = append(msgs, "Running deploy command") ctx := context.Background() err := checkToken(f) @@ -127,7 +128,7 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error { if !SkipBuild { buildCmd := cmd.BuildCmd(f) - err = buildCmd.ExternalRun(&contracts.BuildInfo{}, ProjectConf) + err = buildCmd.ExternalRun(&contracts.BuildInfo{}, ProjectConf, &msgs) if err != nil { logger.Debug("Error while running build command called by deploy command", zap.Error(err)) return err diff --git a/pkg/cmd/deploy/purge.go b/pkg/cmd/deploy/purge.go index 467b46284..040dc38b8 100644 --- a/pkg/cmd/deploy/purge.go +++ b/pkg/cmd/deploy/purge.go @@ -52,7 +52,7 @@ func (cmd *DeployCmd) PurgeUrls(domain []string, path string) error { return nil } -func PurgeForUpdatedFiles(cmd *DeployCmd, domain apidom.DomainResponse, confPath string) error { +func PurgeForUpdatedFiles(cmd *DeployCmd, domain apidom.DomainResponse, confPath string, msgs *[]string) error { listURLsDomains := domain.GetCnames() if !domain.GetCnameAccessOnly() { listURLsDomains = append(listURLsDomains, domain.GetDomainName()) @@ -69,7 +69,9 @@ func PurgeForUpdatedFiles(cmd *DeployCmd, domain apidom.DomainResponse, confPath if err := cmd.PurgeWildcard([]string{v}, wildCard); err != nil { logger.Debug("Error purge path domain", zap.String("wildCard", wildCard), zap.Error(err)) } - logger.FInfo(cmd.F.IOStreams.Out, fmt.Sprintf(msg.DeployOutputCachePurgeWildCard, v)) + msgsf := fmt.Sprintf(msg.DeployOutputCachePurgeWildCard, v) + logger.FInfoFlags(cmd.F.IOStreams.Out, msgsf, cmd.F.Format, cmd.F.Out) + *msgs = append(*msgs, msgsf) } } diff --git a/pkg/cmd/deploy/requests.go b/pkg/cmd/deploy/requests.go index a376e40b8..7e68cf13d 100644 --- a/pkg/cmd/deploy/requests.go +++ b/pkg/cmd/deploy/requests.go @@ -217,7 +217,7 @@ func (cmd *DeployCmd) doDomain(client *apidom.Client, ctx context.Context, conf } if conf.RtPurge.PurgeOnPublish && !newDomain { - err = PurgeForUpdatedFiles(cmd, domain, ProjectConf) + err = PurgeForUpdatedFiles(cmd, domain, ProjectConf, msgs) if err != nil { logger.Debug("Error while purging domain", zap.Error(err)) return err diff --git a/pkg/cmd/dev/dev.go b/pkg/cmd/dev/dev.go index 205ed463d..ae652ee6f 100644 --- a/pkg/cmd/dev/dev.go +++ b/pkg/cmd/dev/dev.go @@ -45,7 +45,7 @@ func NewCobraCmd(dev *DevCmd) *cobra.Command { Long: msg.DevLongDescription, SilenceUsage: true, SilenceErrors: true, - Example: heredoc.Doc(` + Example: heredoc.Doc(` $ azion dev $ azion dev --help `),