Skip to content
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

Allow specifying executable in artifact section and skip bash from WSL #1169

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bundle/config/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type Artifact struct {
Files []ArtifactFile `json:"files,omitempty"`
BuildCommand string `json:"build,omitempty"`

Executable exec.ExecutableType `json:"executable,omitempty"`

paths.Paths
}

Expand All @@ -50,7 +52,13 @@ func (a *Artifact) Build(ctx context.Context) ([]byte, error) {
return nil, fmt.Errorf("no build property defined")
}

e, err := exec.NewCommandExecutor(a.Path)
var e *exec.Executor
var err error
if a.Executable != "" {
e, err = exec.NewCommandExecutorWithExecutable(a.Path, a.Executable)
} else {
e, err = exec.NewCommandExecutor(a.Path)
}
if err != nil {
return nil, err
}
Expand Down
29 changes: 29 additions & 0 deletions libs/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@ package exec

import (
"context"
"fmt"
"io"
"os"
osexec "os/exec"
)

type ExecutableType string

const BashExecutable ExecutableType = `bash`
const ShExecutable ExecutableType = `sh`
const CmdExecutable ExecutableType = `cmd`

var finders map[ExecutableType](func() (shell, error)) = map[ExecutableType](func() (shell, error)){
BashExecutable: newBashShell,
ShExecutable: newShShell,
CmdExecutable: newCmdShell,
}

type Command interface {
// Wait for command to terminate. It must have been previously started.
Wait() error
Expand Down Expand Up @@ -61,6 +74,22 @@ func NewCommandExecutor(dir string) (*Executor, error) {
}, nil
}

func NewCommandExecutorWithExecutable(dir string, execType ExecutableType) (*Executor, error) {
f, ok := finders[execType]
if !ok {
return nil, fmt.Errorf("%s is not supported as an artifact executable", execType)
andrewnester marked this conversation as resolved.
Show resolved Hide resolved
}
shell, err := f()
if err != nil {
return nil, err
}

return &Executor{
shell: shell,
dir: dir,
}, nil
}

func (e *Executor) StartCommand(ctx context.Context, command string) (Command, error) {
ec, err := e.shell.prepare(command)
if err != nil {
Expand Down
Loading