Skip to content

Commit 8c2f90a

Browse files
authored
Add --run-post-install and --skip-post-install flags to upgrade command (#953)
* Add --run-post-install and --skip-post-install flags to upgrade command
1 parent be39aa9 commit 8c2f90a

15 files changed

+291
-252
lines changed

Diff for: cli/core/install.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func initInstallCommand() *cobra.Command {
4343
Args: cobra.MinimumNArgs(1),
4444
Run: runInstallCommand,
4545
}
46-
addPostInstallFlagsToCommand(installCommand)
46+
AddPostInstallFlagsToCommand(installCommand)
4747
return installCommand
4848
}
4949

@@ -52,12 +52,15 @@ var postInstallFlags struct {
5252
skipPostInstall bool
5353
}
5454

55-
func addPostInstallFlagsToCommand(cmd *cobra.Command) {
55+
// AddPostInstallFlagsToCommand adds flags that can be used to force running or skipping
56+
// of post installation scripts
57+
func AddPostInstallFlagsToCommand(cmd *cobra.Command) {
5658
cmd.Flags().BoolVar(&postInstallFlags.runPostInstall, "run-post-install", false, "Force run of post-install scripts (if the CLI is not running interactively).")
5759
cmd.Flags().BoolVar(&postInstallFlags.skipPostInstall, "skip-post-install", false, "Force skip of post-install scripts (if the CLI is running interactively).")
5860
}
5961

60-
func detectSkipPostInstallValue() bool {
62+
// DetectSkipPostInstallValue returns true if a post install script must be run
63+
func DetectSkipPostInstallValue() bool {
6164
if postInstallFlags.runPostInstall && postInstallFlags.skipPostInstall {
6265
feedback.Errorf("The flags --run-post-install and --skip-post-install can't be both set at the same time.")
6366
os.Exit(errorcodes.ErrBadArgument)
@@ -100,7 +103,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
100103
PlatformPackage: platformRef.PackageName,
101104
Architecture: platformRef.Architecture,
102105
Version: platformRef.Version,
103-
SkipPostInstall: detectSkipPostInstallValue(),
106+
SkipPostInstall: DetectSkipPostInstallValue(),
104107
}
105108
_, err := core.PlatformInstall(context.Background(), platformInstallReq, output.ProgressBar(), output.TaskProgress())
106109
if err != nil {

Diff for: cli/core/upgrade.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func initUpgradeCommand() *cobra.Command {
4242
" " + os.Args[0] + " core upgrade arduino:samd",
4343
Run: runUpgradeCommand,
4444
}
45-
addPostInstallFlagsToCommand(upgradeCommand)
45+
AddPostInstallFlagsToCommand(upgradeCommand)
4646
return upgradeCommand
4747
}
4848

@@ -92,7 +92,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
9292
Instance: inst,
9393
PlatformPackage: platformRef.PackageName,
9494
Architecture: platformRef.Architecture,
95-
SkipPostInstall: detectSkipPostInstallValue(),
95+
SkipPostInstall: DetectSkipPostInstallValue(),
9696
}
9797

9898
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())

Diff for: cli/upgrade/upgrade.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"os"
2121

22+
"github.com/arduino/arduino-cli/cli/core"
2223
"github.com/arduino/arduino-cli/cli/errorcodes"
2324
"github.com/arduino/arduino-cli/cli/feedback"
2425
"github.com/arduino/arduino-cli/cli/instance"
@@ -40,6 +41,7 @@ func NewCommand() *cobra.Command {
4041
Run: runUpgradeCommand,
4142
}
4243

44+
core.AddPostInstallFlagsToCommand(upgradeCommand)
4345
return upgradeCommand
4446
}
4547

@@ -53,7 +55,8 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
5355
logrus.Info("Executing `arduino upgrade`")
5456

5557
err = commands.Upgrade(context.Background(), &rpc.UpgradeReq{
56-
Instance: inst,
58+
Instance: inst,
59+
SkipPostInstall: core.DetectSkipPostInstallValue(),
5760
}, output.NewDownloadProgressBarCB(), output.TaskProgress())
5861

5962
if err != nil {

Diff for: commands/instances.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
515515
toolsToInstall := []*cores.ToolRelease{}
516516
for _, tool := range tools {
517517
if tool.IsInstalled() {
518+
logrus.WithField("tool", tool).Warn("Tool already installed")
518519
taskCB(&rpc.TaskProgress{Name: "Tool " + tool.String() + " already installed", Completed: true})
519520
} else {
520521
toolsToInstall = append(toolsToInstall, tool)
@@ -536,7 +537,8 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
536537
return err
537538
}
538539

539-
taskCB(&rpc.TaskProgress{Name: "Installing " + latest.String()})
540+
logrus.Info("Updating platform " + installed.String())
541+
taskCB(&rpc.TaskProgress{Name: "Updating " + latest.String()})
540542

541543
// Installs tools
542544
for _, tool := range toolsToInstall {
@@ -549,6 +551,7 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
549551
// Installs platform
550552
err = pm.InstallPlatform(latest)
551553
if err != nil {
554+
logrus.WithError(err).Error("Cannot install platform")
552555
taskCB(&rpc.TaskProgress{Message: "Error installing " + latest.String()})
553556
return err
554557
}
@@ -558,12 +561,27 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
558561

559562
// In case uninstall fails tries to rollback
560563
if err != nil {
564+
logrus.WithError(err).Error("Error updating platform.")
561565
taskCB(&rpc.TaskProgress{Message: "Error upgrading platform: " + err.Error()})
562566

563567
// Rollback
564568
if err := pm.UninstallPlatform(latest); err != nil {
569+
logrus.WithError(err).Error("Error rolling-back changes.")
565570
taskCB(&rpc.TaskProgress{Message: "Error rolling-back changes: " + err.Error()})
571+
return err
572+
}
573+
}
574+
575+
// Perform post install
576+
if !req.SkipPostInstall {
577+
logrus.Info("Running post_install script")
578+
taskCB(&rpc.TaskProgress{Message: "Configuring platform"})
579+
if err := pm.RunPostInstallScript(latest); err != nil {
580+
taskCB(&rpc.TaskProgress{Message: fmt.Sprintf("WARNING: cannot run post install: %s", err)})
566581
}
582+
} else {
583+
logrus.Info("Skipping platform configuration (post_install run).")
584+
taskCB(&rpc.TaskProgress{Message: "Skipping platform configuration"})
567585
}
568586
}
569587
}

Diff for: rpc/commands/board.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)