Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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 @@
if err != nil {
return nil, err
}

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

switch {
Expand Down Expand Up @@ -255,7 +256,7 @@

// compileSteps executes the workflow for converting a YAML pipeline into an executable struct.
//
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical

Check failure on line 259 in compiler/native/compile.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile.go#L259

directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
Raw output
compiler/native/compile.go:259:1: directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical
^
func (c *client) compileSteps(p *yaml.Build, _pipeline *library.Pipeline, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, *library.Pipeline, error) {
var err error

Expand Down Expand Up @@ -352,7 +353,7 @@

// compileStages executes the workflow for converting a YAML pipeline into an executable struct.
//
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical

Check failure on line 356 in compiler/native/compile.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile.go#L356

directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
Raw output
compiler/native/compile.go:356:1: directive `//nolint:dupl,lll // linter thinks the steps and stages workflows are identical` is unused for linter "dupl" (nolintlint)
//nolint:dupl,lll // linter thinks the steps and stages workflows are identical
^
func (c *client) compileStages(p *yaml.Build, _pipeline *library.Pipeline, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, *library.Pipeline, error) {
var err error

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 @@ -1815,7 +1815,7 @@
}

compiler.WithMetadata(m)
compiler.WithRepo(&library.Repo{PipelineType: &tt.args.pipelineType})

Check failure on line 1818 in compiler/native/compile_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile_test.go#L1818

G601: Implicit memory aliasing in for loop. (gosec)
Raw output
compiler/native/compile_test.go:1818:50: G601: Implicit memory aliasing in for loop. (gosec)
			compiler.WithRepo(&library.Repo{PipelineType: &tt.args.pipelineType})
			                                              ^

got, _, err := compiler.Compile(yaml)
if err != nil {
Expand Down Expand Up @@ -3126,7 +3126,7 @@
compiler.WithMetadata(m)

if tt.args.pipelineType != "" {
compiler.WithRepo(&library.Repo{PipelineType: &tt.args.pipelineType})

Check failure on line 3129 in compiler/native/compile_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile_test.go#L3129

G601: Implicit memory aliasing in for loop. (gosec)
Raw output
compiler/native/compile_test.go:3129:51: G601: Implicit memory aliasing in for loop. (gosec)
				compiler.WithRepo(&library.Repo{PipelineType: &tt.args.pipelineType})
				                                              ^
}

got, _, err := compiler.Compile(yaml)
Expand Down Expand Up @@ -3228,7 +3228,22 @@
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 @@
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
Loading