Skip to content

Commit

Permalink
feat: Expose merge strategy in GitHub Action (#900)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
  • Loading branch information
craciunoiuc committed Oct 21, 2023
2 parents 2e05ff2 + daaa505 commit 19a6f5e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ inputs:
description: Push the output.
required: false
default: false
strategy:
description: Merge strategy to use when packaging.
required: false
default: merge

runs:
# Use a composite type so we can set up BuildKit beforehand so that
Expand Down Expand Up @@ -122,6 +126,7 @@ runs:
-e "INPUT_NAME=${{ inputs.name }}" \
-e "INPUT_OUTPUT=${{ inputs.output }}" \
-e "INPUT_PLAT=${{ inputs.plat }}" \
-e "INPUT_STRATEGY=${{ inputs.strategy }}" \
-e "INPUT_PUSH=${{ inputs.push }}" \
-e "INPUT_RUNTIMEDIR=${{ inputs.runtimedir }}" \
-e "INPUT_TARGET=${{ inputs.target }}" \
Expand Down
30 changes: 24 additions & 6 deletions tools/github-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ 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"`
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"`

// Internal attributes
project app.Application
Expand Down Expand Up @@ -193,6 +194,23 @@ func (opts *GithubAction) Pre(cmd *cobra.Command, args []string) (err error) {
opts.Arch = opts.target.Architecture().Name()
}

if opts.Strategy != "" {
found := false
var strategies []string
for _, strategy := range packmanager.MergeStrategies() {
strategies = append(strategies, strategy.String())
if strategy.String() == opts.Strategy {
found = true
}
}

if !found {
return fmt.Errorf("unknown merge strategy '%s': choice from %v", opts.Strategy, strategies)
}
} else {
opts.Strategy = packmanager.StrategyMerge.String()
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions tools/github-action/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (opts *GithubAction) packAndPush(ctx context.Context) error {
packmanager.PackInitrd(opts.initrdPath),
packmanager.PackKConfig(true),
packmanager.PackName(output),
packmanager.PackMergeStrategy(packmanager.MergeStrategy(opts.Strategy)),
}

if ukversion, ok := opts.target.KConfig().Get(unikraft.UK_FULLVERSION); ok {
Expand Down

0 comments on commit 19a6f5e

Please sign in to comment.