From d724ded0ec92f79bb7f23f5eb7222976056a03d8 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Tue, 14 Jan 2025 11:36:40 +0200 Subject: [PATCH] fix(github-action): Change args type to string GitHub actions don't support arrays as argument so the type conversion turned it into an empty array. Signed-off-by: Cezar Craciunoiu --- tools/github-action/execute.go | 9 +++++++-- tools/github-action/main.go | 20 ++++++++++--------- tools/github-action/pack.go | 35 ++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/tools/github-action/execute.go b/tools/github-action/execute.go index 36e7bc982..15137a741 100644 --- a/tools/github-action/execute.go +++ b/tools/github-action/execute.go @@ -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" @@ -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) { diff --git a/tools/github-action/main.go b/tools/github-action/main.go index c22011a22..82d96ca9d 100644 --- a/tools/github-action/main.go +++ b/tools/github-action/main.go @@ -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 @@ -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 @@ -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] diff --git a/tools/github-action/pack.go b/tools/github-action/pack.go index 8fcc32e79..ec1bd1d7e 100644 --- a/tools/github-action/pack.go +++ b/tools/github-action/pack.go @@ -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{ @@ -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 @@ -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) }