Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
internal/config: Remove redundant context append for parsing
Browse files Browse the repository at this point in the history
Prior to this commit, if a config had many pipeline stanzas, say more
than 6, each time we would parse a pipeline via the hcl EvalContext we
would append that context to the current one to capture any additional
parts of the config. Given that we are evaluating the entire config file
and not parts of it, this action was redundant. Additionally, it made
parsing many pipeline configs slow for each appended context.

This fixes it by removing the append. We don't need to append this,
given we have the full config context each time we parse pipelines.
  • Loading branch information
briancain committed May 25, 2023
1 parent 1d79cb5 commit e364197
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
2 changes: 0 additions & 2 deletions internal/config/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ func (c *Config) Pipelines() []string {
// Note that currently this parsing function does not attempt to detect cycles
// between embedded pipelines.
func (c *Config) Pipeline(id string, ctx *hcl.EvalContext) (*Pipeline, error) {
ctx = appendContext(c.ctx, ctx)

// Find the pipeline by progressively decoding
var rawPipeline *hclPipeline
for _, p := range c.hclConfig.Pipelines {
Expand Down
14 changes: 14 additions & 0 deletions internal/config/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,20 @@ func TestPipelineProtos(t *testing.T) {
},
},

{
"pipelines_many_many_many.hcl",
func(t *testing.T, c *Config) {
require := require.New(t)

pipelines, err := c.PipelineProtos()
require.NoError(err)
require.Len(pipelines, 7)

require.Equal(pipelines[0].Name, "foo")
require.Equal(pipelines[1].Name, "bar")
},
},

{
"pipeline_nested_pipes.hcl",
func(t *testing.T, c *Config) {
Expand Down
84 changes: 84 additions & 0 deletions internal/config/testdata/pipelines/pipelines_many_many_many.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
project = "foo"

pipeline "foo" {
step "test" {
image_url = "example.com/test"

use "test" {
foo = "bar"
}
}
}


pipeline "bar" {
step "test2" {
image_url = "example.com/test"

use "test" {
foo = "bar"
}
}
}

pipeline "foofoo" {
step "test2" {
image_url = "example.com/test"

use "test" {
foo = "bar"
}
}
}

pipeline "barbar" {
step "test2" {
image_url = "example.com/test"

use "test" {
foo = "bar"
}
}
}

pipeline "foobar" {
step "test2" {
image_url = "example.com/test"

use "test" {
foo = "bar"
}
}
}

pipeline "naming-is-hard" {
step "test2" {
image_url = "example.com/test"

use "test" {
foo = "bar"
}
}
}

pipeline "hey-we-made-it" {
step "test2" {
image_url = "example.com/test"

use "test" {
foo = "bar"
}
}
}

app "web" {
config {
env = {
static = "hello"
}
}

build {}

deploy {}
}

0 comments on commit e364197

Please sign in to comment.