Skip to content

Commit

Permalink
Install choco deps for jfrog ootb (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham149 authored Apr 10, 2023
1 parent f29f297 commit 67572ec
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 39 deletions.
90 changes: 53 additions & 37 deletions plugin/harness/execer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,13 @@ func (e *Execer) Exec(ctx context.Context) error {
return err
}

// install linux dependencies
// install dependencies
if runtime.GOOS == "linux" {
if len(out.Deps.Apt) > 0 {
slog.Debug("apt-get update")

cmd := exec.Command("sudo", "apt-get", "update")
cmd.Env = e.Environ
cmd.Dir = e.Workdir
cmd.Stderr = e.Stderr
cmd.Stdout = e.Stdout
cmd.Run()
}

for _, item := range out.Deps.Apt {
slog.Debug("apt-get install", slog.String("package", item))

cmd := exec.Command("sudo", "apt-get", "install", item)
cmd.Env = e.Environ
cmd.Stderr = e.Stderr
cmd.Stdout = e.Stdout
cmd.Run()
}
}

// install darwin dependencies
if runtime.GOOS == "darwin" {
for _, item := range out.Deps.Brew {
slog.Debug("brew install", slog.String("package", item))

cmd := exec.Command("brew", "install", item)
cmd.Env = e.Environ
cmd.Dir = e.Workdir
cmd.Stderr = e.Stderr
cmd.Stdout = e.Stdout
cmd.Run()
}
e.installAptDeps(ctx, out.Deps.Apt)
} else if runtime.GOOS == "darwin" {
e.installBrewDeps(ctx, out.Deps.Brew)
} else if runtime.GOOS == "windows" {
e.installChocoDeps(ctx, out.Deps.Choco)
}

// execute the plugin. the execution logic differs
Expand All @@ -85,8 +56,6 @@ func (e *Execer) Exec(ctx context.Context) error {
} else {
return e.runShellExecutable(ctx, out)
}

return nil
}

func (e *Execer) runSourceExecutable(ctx context.Context, source string) error {
Expand Down Expand Up @@ -184,6 +153,53 @@ func (e *Execer) buildGoExecutable(ctx context.Context, module string) (
return binpath, nil
}

func (e *Execer) installAptDeps(ctx context.Context, deps []string) {
if len(deps) > 0 {
slog.Debug("apt-get update")

cmd := exec.Command("sudo", "apt-get", "update")
if err := runCmds(ctx, []*exec.Cmd{cmd}, e.Environ, e.Workdir,
e.Stdout, e.Stderr); err != nil {
slog.Error("apt-get update failed", "error", err)
}

}

for _, item := range deps {
slog.Debug("apt-get install", slog.String("package", item))

cmd := exec.Command("sudo", "apt-get", "install", item)
if err := runCmds(ctx, []*exec.Cmd{cmd}, e.Environ, e.Workdir,
e.Stdout, e.Stderr); err != nil {
slog.Error("apt-get install failed", slog.String("package", item), "error", err)
}
}
}

func (e *Execer) installBrewDeps(ctx context.Context, deps []string) {
for _, item := range deps {
slog.Debug("brew install", slog.String("package", item))

cmd := exec.Command("brew", "install", item)
if err := runCmds(ctx, []*exec.Cmd{cmd}, e.Environ, e.Workdir,
e.Stdout, e.Stderr); err != nil {
slog.Error("brew install failed", slog.String("package", item), "error", err)
}
}
}

func (e *Execer) installChocoDeps(ctx context.Context, deps []string) {
for _, item := range deps {
slog.Debug("choco install", slog.String("package", item))

cmd := exec.Command("choco", "install", item)
if err := runCmds(ctx, []*exec.Cmd{cmd}, e.Environ, e.Workdir,
e.Stdout, e.Stderr); err != nil {
slog.Error("choco install failed", slog.String("package", item), "error", err)
}
}
}

func runCmds(ctx context.Context, cmds []*exec.Cmd, env []string, workdir string,
stdout io.Writer, stderr io.Writer) error {
for _, cmd := range cmds {
Expand Down
5 changes: 3 additions & 2 deletions plugin/harness/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package harness
// spec defines the bitrise plugin.
type spec struct {
Deps struct {
Brew []string
Apt []string
Brew []string
Apt []string
Choco []string
}
Run struct {
Docker struct {
Expand Down

0 comments on commit 67572ec

Please sign in to comment.