Skip to content

Commit

Permalink
fix(compiler): track templates in compileInline so CLI validate comma…
Browse files Browse the repository at this point in the history
…nd works for nested (#1067)

* fix(compiler): track templates in compileInline so CLI validate command works for nested

* fix tests
  • Loading branch information
ecrupper authored Feb 23, 2024
1 parent 4a5ce4a commit ba609c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func (c *client) CompileLite(v interface{}, substitute bool) (*yaml.Build, *libr
// compileInline parses and expands out inline pipelines.
func (c *client) compileInline(p *yaml.Build, depth int) (*yaml.Build, error) {
newPipeline := *p
newPipeline.Templates = yaml.TemplateSlice{}

// return if max template depth has been reached
if depth == 0 {
Expand Down Expand Up @@ -203,6 +202,8 @@ func (c *client) compileInline(p *yaml.Build, depth int) (*yaml.Build, error) {
if err != nil {
return nil, err
}

newPipeline.Templates = append(newPipeline.Templates, parsed.Templates...)
}

switch {
Expand Down
33 changes: 31 additions & 2 deletions compiler/native/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3228,7 +3228,22 @@ func Test_CompileLite(t *testing.T) {
RenderInline: true,
Environment: []string{"steps", "services", "secrets"},
},
Templates: []*yaml.Template{},
Templates: []*yaml.Template{
{
Name: "golang",
Source: "github.example.com/github/octocat/golang_inline_stages.yml",
Format: "golang",
Type: "github",
Variables: map[string]any{"image": string("golang:latest")},
},
{
Name: "starlark",
Source: "github.example.com/github/octocat/starlark_inline_stages.star",
Format: "starlark",
Type: "github",
},
},
Environment: raw.StringSliceMap{},
Stages: []*yaml.Stage{
{
Name: "test",
Expand Down Expand Up @@ -3357,7 +3372,21 @@ func Test_CompileLite(t *testing.T) {
Pull: "not_present",
},
},
Templates: yaml.TemplateSlice{},
Environment: raw.StringSliceMap{},
Templates: yaml.TemplateSlice{
{
Name: "golang",
Source: "github.example.com/github/octocat/golang_inline_steps.yml",
Format: "golang",
Type: "github",
},
{
Name: "starlark",
Source: "github.example.com/github/octocat/starlark_inline_steps.star",
Format: "starlark",
Type: "github",
},
},
},
wantErr: false,
},
Expand Down

0 comments on commit ba609c1

Please sign in to comment.