Skip to content

Commit

Permalink
Only run files through the template engine if they match the suffix
Browse files Browse the repository at this point in the history
The default suffix is the empty string so it always matches.
  • Loading branch information
Ilkka Poutanen committed Nov 30, 2023
1 parent 5cdfae9 commit e5703a8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/recipe/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
"maps"
"strings"

"github.com/gofrs/uuid"
Expand Down Expand Up @@ -31,12 +32,27 @@ func (re *Recipe) Execute(engine RenderEngine, values VariableValues, id uuid.UU
"Variables": values,
}

files, err := engine.Render(re.Templates, context)
// Filter out templates we might not want to render
templates := make(map[string][]byte)
plainFiles := make(map[string][]byte)
for filename, content := range re.Templates {
if strings.HasSuffix(filename, re.TemplateExtension) {
templates[filename] = content
} else {
plainFiles[filename] = content
}
}

files, err := engine.Render(templates, context)
if err != nil {
return nil, err
}

sauce.Files = make(map[string]File, len(files))
// Add the plain files
maps.Copy(files, plainFiles)

sauce.Files = make(map[string]File, len(re.Templates))

idx := 0
for filename, content := range files {
// Skip empty files
Expand All @@ -49,6 +65,8 @@ func (re *Recipe) Execute(engine RenderEngine, values VariableValues, id uuid.UU
continue
}

filename = strings.TrimSuffix(filename, re.TemplateExtension)

sum := sha256.Sum256(content)
sauce.Files[filename] = File{Content: content, Checksum: fmt.Sprintf("sha256:%x", sum)}
idx += 1
Expand Down

0 comments on commit e5703a8

Please sign in to comment.