Skip to content

Commit

Permalink
fix: deploy command calls the build and executes the build print
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm committed Jul 9, 2024
1 parent a80b0b9 commit af78573
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 27 deletions.
11 changes: 4 additions & 7 deletions pkg/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions pkg/cmd/build/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ 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
}

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)
Expand Down Expand Up @@ -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)

}
22 changes: 15 additions & 7 deletions pkg/cmd/build/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/build/vulcan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/deploy/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/deploy/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/deploy/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`),
Expand Down

0 comments on commit af78573

Please sign in to comment.