From ba609c16aaf9bba7381fede6ab386df1acad80e5 Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:11:04 -0500 Subject: [PATCH] fix(compiler): track templates in compileInline so CLI validate command works for nested (#1067) * fix(compiler): track templates in compileInline so CLI validate command works for nested * fix tests --- compiler/native/compile.go | 3 ++- compiler/native/compile_test.go | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/compiler/native/compile.go b/compiler/native/compile.go index 08d1c8f11..9768d90bb 100644 --- a/compiler/native/compile.go +++ b/compiler/native/compile.go @@ -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 { @@ -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 { diff --git a/compiler/native/compile_test.go b/compiler/native/compile_test.go index 3db17730f..e71956306 100644 --- a/compiler/native/compile_test.go +++ b/compiler/native/compile_test.go @@ -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", @@ -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, },