feat: support for forgejo-exec --var (#645)
Refs forgejo/runner#387 https://code.forgejo.org/forgejo/runner/actions/runs/4284/jobs/1#jobstep-6-25  Co-authored-by: lautriva <lautriva@noreply.gitea.com> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/645 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
d871b38c8d
commit
51e0bc0e53
3 changed files with 36 additions and 1 deletions
|
|
@ -40,6 +40,7 @@ type executeArgs struct {
|
|||
envs []string
|
||||
envfile string
|
||||
secrets []string
|
||||
vars []string
|
||||
defaultActionsURL string
|
||||
insecureSecrets bool
|
||||
privileged bool
|
||||
|
|
@ -132,6 +133,22 @@ func (i *executeArgs) LoadEnvs() map[string]string {
|
|||
return envs
|
||||
}
|
||||
|
||||
func (i *executeArgs) LoadVars() map[string]string {
|
||||
vars := make(map[string]string)
|
||||
if i.vars != nil {
|
||||
for _, runVar := range i.vars {
|
||||
e := strings.SplitN(runVar, `=`, 2)
|
||||
if len(e) == 2 {
|
||||
vars[e[0]] = e[1]
|
||||
} else {
|
||||
vars[e[0]] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vars
|
||||
}
|
||||
|
||||
// Workdir returns path to workdir
|
||||
func (i *executeArgs) Workdir() string {
|
||||
return i.resolve(".")
|
||||
|
|
@ -384,6 +401,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
|
|||
LogOutput: true,
|
||||
JSONLogger: execArgs.jsonLogger,
|
||||
Env: execArgs.LoadEnvs(),
|
||||
Vars: execArgs.LoadVars(),
|
||||
Secrets: execArgs.LoadSecrets(),
|
||||
InsecureSecrets: execArgs.insecureSecrets,
|
||||
Privileged: execArgs.privileged,
|
||||
|
|
@ -471,6 +489,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command {
|
|||
execCmd.Flags().StringArrayVarP(&execArg.envs, "env", "", []string{}, "env to make available to actions with optional value (e.g. --env myenv=foo or --env myenv)")
|
||||
execCmd.PersistentFlags().StringVarP(&execArg.envfile, "env-file", "", ".env", "environment file to read and use as env in the containers")
|
||||
execCmd.Flags().StringArrayVarP(&execArg.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)")
|
||||
execCmd.Flags().StringArrayVarP(&execArg.vars, "var", "", []string{}, "variable to make available to actions with optional value (e.g. --var myvar=foo or --var myvar)")
|
||||
execCmd.PersistentFlags().BoolVarP(&execArg.insecureSecrets, "insecure-secrets", "", false, "NOT RECOMMENDED! Doesn't hide secrets while printing logs.")
|
||||
execCmd.Flags().BoolVar(&execArg.privileged, "privileged", false, "use privileged mode")
|
||||
execCmd.Flags().StringVar(&execArg.usernsMode, "userns", "", "user namespace to use")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue