Skip to content

Commit

Permalink
fix(github-action): Change args type to string
Browse files Browse the repository at this point in the history
GitHub actions don't support arrays as argument so the type
conversion turned it into an empty array.

Signed-off-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc committed Jan 14, 2025
1 parent 662588e commit d724ded
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
9 changes: 7 additions & 2 deletions tools/github-action/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"time"

"github.com/mattn/go-shellwords"
"github.com/rancher/wrangler/pkg/signals"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -61,11 +62,15 @@ func (opts *GithubAction) execute(ctx context.Context) error {
targetName = opts.target.Platform().Name() + "/" + opts.target.Architecture().Name()
}

args, err := shellwords.Parse(opts.Args)
if err != nil {
return err
}

machine.Spec.Kernel = "project://" + opts.project.Name() + ":" + targetName
machine.Spec.Architecture = opts.target.Architecture().Name()
machine.Spec.Platform = opts.target.Platform().Name()
machine.Spec.ApplicationArgs = opts.Args

machine.Spec.ApplicationArgs = args
machine.Status.KernelPath = opts.target.Kernel()

if _, err := os.Stat(machine.Status.KernelPath); err != nil && os.IsNotExist(err) {
Expand Down
20 changes: 11 additions & 9 deletions tools/github-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ type GithubAction struct {
Timeout uint64 `long:"timeout" env:"INPUT_TIMEOUT" usage:"Timeout for the unikernel"`

// Packaging flags
Args []string `long:"args" env:"INPUT_ARGS" usage:"Arguments to pass to the unikernel"`
Rootfs string `long:"rootfs" env:"INPUT_ROOTFS" usage:"Include a rootfs at path"`
Memory string `long:"memory" env:"INPUT_MEMORY" usage:"Set the memory size"`
Name string `long:"name" env:"INPUT_NAME" usage:"Set the name of the output"`
Output string `long:"output" env:"INPUT_OUTPUT" usage:"Set the output path"`
Push bool `long:"push" env:"INPUT_PUSH" usage:"Push the output"`
Strategy string `long:"strategy" env:"INPUT_STRATEGY" usage:"Merge strategy to use when packaging"`
Dbg bool `long:"dbg" env:"INPUT_DBG" usage:"Use the debug kernel"`
Args string `long:"args" env:"INPUT_ARGS" usage:"Arguments to pass to the unikernel"`
Rootfs string `long:"rootfs" env:"INPUT_ROOTFS" usage:"Include a rootfs at path"`
Memory string `long:"memory" env:"INPUT_MEMORY" usage:"Set the memory size"`
Name string `long:"name" env:"INPUT_NAME" usage:"Set the name of the output"`
Output string `long:"output" env:"INPUT_OUTPUT" usage:"Set the output path"`
Push bool `long:"push" env:"INPUT_PUSH" usage:"Push the output"`
Strategy string `long:"strategy" env:"INPUT_STRATEGY" usage:"Merge strategy to use when packaging"`
Dbg bool `long:"dbg" env:"INPUT_DBG" usage:"Use the debug kernel"`

// Internal attributes
project app.Application
Expand Down Expand Up @@ -255,7 +255,7 @@ func (opts *GithubAction) Run(ctx context.Context, args []string) (err error) {
opts.Target,
)

if len(targets) != 1 {
if len(targets) > 1 {
// TODO(nderjung): We should support building multiple targets in the
// future, but for now we disable this ability. This is largely to do with
// package management afterwards which does not yet support multi-target
Expand All @@ -264,6 +264,8 @@ func (opts *GithubAction) Run(ctx context.Context, args []string) (err error) {
// unikernel after a successful build via this action, multiple targets
// would also fail at this step.
return fmt.Errorf("cannot build more than one target using action")
} else if len(targets) == 0 {
return fmt.Errorf("no targets found")
}

opts.target = targets[0]
Expand Down
35 changes: 21 additions & 14 deletions tools/github-action/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,23 @@ func (opts *GithubAction) packUnikraft(ctx context.Context, output string, forma
}
}

var cmdShellArgs []string

// If no arguments have been specified, use the ones which are default and
// that have been included in the package.
if len(opts.Args) == 0 {
if len(opts.project.Command()) > 0 {
opts.Args = opts.project.Command()
cmdShellArgs = opts.project.Command()
} else if len(opts.target.Command()) > 0 {
opts.Args = opts.target.Command()
cmdShellArgs = opts.target.Command()
}
}

cmdShellArgs, err := shellwords.Parse(strings.Join(opts.Args, " "))
if err != nil {
return err
cmdShellArgs, err = shellwords.Parse(strings.Join(cmdShellArgs, " "))
if err != nil {
return err
}
} else {
cmdShellArgs = strings.Split(opts.Args, " ")
}

popts := []packmanager.PackOption{
Expand Down Expand Up @@ -454,27 +458,29 @@ func (opts *GithubAction) packRuntime(ctx context.Context, output string, format
return fmt.Errorf("could not build rootfs: %w", err)
}

args := []string{}

// If no arguments have been specified, use the ones which are default and
// that have been included in the package.
if len(opts.Args) == 0 {
if len(opts.project.Command()) > 0 {
opts.Args = opts.project.Command()
args = opts.project.Command()
} else if cmds != nil {
opts.Args = cmds
args = cmds
} else if len(targ.Command()) > 0 {
opts.Args = targ.Command()
args = targ.Command()
}
}

args := []string{}
// Only parse arguments if they have been provided.
if len(opts.Args) > 0 {
args, err = shellwords.Parse(fmt.Sprintf("'%s'", strings.Join(opts.Args, "' '")))
args, err = shellwords.Parse(fmt.Sprintf("'%s'", strings.Join(args, "' '")))
if err != nil {
return err
}
} else {
args = strings.Split(opts.Args, " ")
}

fmt.Println("Packaging args:", args)

labels := opts.project.Labels()

var popts []packmanager.PackOption
Expand Down Expand Up @@ -507,6 +513,7 @@ func (opts *GithubAction) packRuntime(ctx context.Context, output string, format
}

if opts.Push {
fmt.Println("Pushing")
return packaged[0].Push(ctx)
}

Expand Down

0 comments on commit d724ded

Please sign in to comment.