Skip to content

Commit

Permalink
Merge pull request #35 from buildkite/revert-precedence-of-runtime-va…
Browse files Browse the repository at this point in the history
…riables

Revert breaking change to precedence of variables
  • Loading branch information
patrobinson authored Apr 23, 2024
2 parents 01954f4 + a7f9892 commit c34b985
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
12 changes: 6 additions & 6 deletions interpolate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestInterpolator(t *testing.T) {
),
Steps: Steps{
&CommandStep{
Command: "echo hello upper_friend",
Command: "echo hello lower_friend",
},
},
},
Expand All @@ -127,7 +127,7 @@ func TestInterpolator(t *testing.T) {
),
Steps: Steps{
&CommandStep{
Command: "echo hello lower_friend",
Command: "echo hello upper_friend",
},
},
},
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestInterpolator(t *testing.T) {
),
Steps: Steps{
&CommandStep{
Command: "echo runtime_baz",
Command: "echo pipeline_baz",
},
},
},
Expand All @@ -202,7 +202,7 @@ func TestInterpolator(t *testing.T) {
),
Steps: Steps{
&CommandStep{
Command: "echo runtime_baz",
Command: "echo pipeline_baz",
},
},
},
Expand Down Expand Up @@ -250,11 +250,11 @@ func TestInterpolator(t *testing.T) {
expected: &Pipeline{
Env: ordered.MapFromItems(
ordered.TupleSS{Key: "FOO", Value: "pipeline_foo"},
ordered.TupleSS{Key: "BAR", Value: "runtime_foo"},
ordered.TupleSS{Key: "BAR", Value: "pipeline_foo"},
),
Steps: Steps{
&CommandStep{
Command: "echo runtime_foo",
Command: "echo pipeline_foo",
},
},
},
Expand Down
11 changes: 2 additions & 9 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ func (p *Pipeline) Interpolate(interpolationEnv InterpolationEnv) error {
// interpolating with the variables defined in interpolationEnv, and then adding the
// results back into p.Env. Since each environment variable in p.Env can
// be interpolated into later environment variables, we also add the results
// to interpolationEnv, but only if interpolationEnv does not already contain that variable
// as interpolationEnv has precedence over p.Env. For clarification, this means that
// if a variable name is interpolated to collide with a variable in the
// interpolationEnv, the interpolationEnv will take precedence.
// to interpolationEnv, making the input ordering of p.Env potentially important.
func (p *Pipeline) interpolateEnvBlock(interpolationEnv InterpolationEnv) error {
return p.Env.Range(func(k, v string) error {
// We interpolate both keys and values.
Expand All @@ -125,11 +122,7 @@ func (p *Pipeline) interpolateEnvBlock(interpolationEnv InterpolationEnv) error

p.Env.Replace(k, intk, intv)

// put it into the interpolationEnv for interpolation on a later iteration, but only if it is not
// already there, as interpolationEnv has precedence over p.Env
if _, exists := interpolationEnv.Get(intk); !exists {
interpolationEnv.Set(intk, intv)
}
interpolationEnv.Set(intk, intv)

return nil
})
Expand Down

0 comments on commit c34b985

Please sign in to comment.