Skip to content

Commit

Permalink
fix: Do not leak step env in composite
Browse files Browse the repository at this point in the history
See #1585 for a test
  • Loading branch information
ChristopherHX committed Jan 26, 2023
1 parent 9c69677 commit 7df1125
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
11 changes: 7 additions & 4 deletions pkg/runner/action_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func newCompositeRunContext(ctx context.Context, parent *RunContext, step action
JobContainer: parent.JobContainer,
ActionPath: actionPath,
Env: env,
GlobalEnv: parent.GlobalEnv,
Masks: parent.Masks,
ExtraPath: parent.ExtraPath,
Parent: parent,
Expand Down Expand Up @@ -99,11 +100,13 @@ func execAsComposite(step actionStep) common.Executor {

rc.Masks = append(rc.Masks, compositeRC.Masks...)
rc.ExtraPath = compositeRC.ExtraPath
// Drop INPUT_... envs, otherwise could just assign rc.Env = compositeRC.Env
for k, v := range compositeRC.Env {
if !strings.HasPrefix(k, "INPUT_") {
rc.Env[k] = v
// compositeRC.Env is dirty, contains INPUT_ and merged step env, only rely on compositeRC.GlobalEnv
for k, v := range compositeRC.GlobalEnv {
rc.Env[k] = v
if rc.GlobalEnv == nil {
rc.GlobalEnv = map[string]string{}
}
rc.GlobalEnv[k] = v
}

return err
Expand Down
10 changes: 8 additions & 2 deletions pkg/runner/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
}

func (rc *RunContext) setEnv(ctx context.Context, kvPairs map[string]string, arg string) {
common.Logger(ctx).Infof(" \U00002699 ::set-env:: %s=%s", kvPairs["name"], arg)
name := kvPairs["name"]
common.Logger(ctx).Infof(" \U00002699 ::set-env:: %s=%s", name, arg)
if rc.Env == nil {
rc.Env = make(map[string]string)
}
rc.Env[kvPairs["name"]] = arg
rc.Env[name] = arg
// for composite action GITHUB_ENV and set-env passing
if rc.GlobalEnv == nil {
rc.GlobalEnv = map[string]string{}
}
rc.GlobalEnv[name] = arg
}
func (rc *RunContext) setOutput(ctx context.Context, kvPairs map[string]string, arg string) {
logger := common.Logger(ctx)
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type RunContext struct {
Run *model.Run
EventJSON string
Env map[string]string
GlobalEnv map[string]string // to pass env changes of GITHUB_ENV and set-env correctly, due to dirty Env field
ExtraPath []string
CurrentStep string
StepResults map[string]*model.StepResult
Expand Down

0 comments on commit 7df1125

Please sign in to comment.