Skip to content

feat(file): add templating file path#7591

Merged
olblak merged 14 commits intoupdatecli:mainfrom
mallendem:add-templating-file
Jan 28, 2026
Merged

feat(file): add templating file path#7591
olblak merged 14 commits intoupdatecli:mainfrom
mallendem:add-templating-file

Conversation

@mallendem
Copy link
Contributor

@mallendem mallendem commented Jan 21, 2026

This PR adds a templating option to the file target so we can avoid messy escaping. It should fix:

https://github.com/orgs/updatecli/discussions/1243
#1280
#1329

Test

cd pkg/plugins/resources/file/ && go test -v .

Additional Information

Checklist

  • I have updated the documentation via pull request in website repository.

Potential improvement

It allows more fine tuned templating bypassing the initial loading done by updatecli, so templating rendering is supported. Something like:

targets:
  useTemplate:
    kind: file
    sourceid: blablabla
    spec:
      file: version-info.txt
      template: version.tmpl

version.tmpl:

{{- $versions := .source }}
{{- range $versions }}
version installed: {{ . }}
{{- end}}

should work

Copilot AI review requested due to automatic review settings January 21, 2026 16:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a templating feature to the file target resource, allowing users to specify a Go template file that will be rendered with the source value, avoiding the need for messy escaping in YAML configurations. This addresses issue #1280 and discussion #1243.

Changes:

  • Added a new Template field to the file resource spec that accepts a path to a Go template file
  • Implemented template rendering using Go's text/template with Sprig functions support
  • Added validation to ensure Template is mutually exclusive with Content, MatchPattern, ReplacePattern, and Line
  • Added comprehensive test coverage for various templating scenarios

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/plugins/resources/file/main.go Added Template field to Spec struct with documentation and validation logic
pkg/plugins/resources/file/target.go Implemented template reading and rendering logic using text/template and Sprig functions
pkg/plugins/resources/file/main_test.go Added validation tests for Template field mutual exclusivity rules
pkg/plugins/resources/file/target_test.go Added comprehensive test cases covering template rendering with various scenarios
e2e/updatecli.d/success.d/templates/version.tmpl Added e2e test template demonstrating basic template usage
e2e/updatecli.d/success.d/templates/config.tmpl Added e2e test template demonstrating Sprig function usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mallendem
Copy link
Contributor Author

Doc PR: #7591

@olblak
Copy link
Member

olblak commented Jan 21, 2026

Thank you for the pull request, it's an interesting approach that I never thought about.
I need to think about it

@olblak olblak added enhancement New feature or request resource-file Resource of kind File labels Jan 21, 2026
@mallendem mallendem requested a review from olblak January 26, 2026 11:19
olblak
olblak previously approved these changes Jan 26, 2026
Copy link
Member

@olblak olblak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request

@olblak olblak enabled auto-merge (squash) January 26, 2026 19:25
@olblak
Copy link
Member

olblak commented Jan 27, 2026

@mallendem could you have a look about this e2e tests is not passing?

2026-01-26T20:05:26.5485274Z ERROR: Error while templating "e2e/updatecli.d/success.d/templates/config.tmpl":
2026-01-26T20:05:26.5485657Z ---
2026-01-26T20:05:26.5485889Z version: {{ .source | quote }}
2026-01-26T20:05:26.5486182Z versionUpper: {{ .source | upper }}
2026-01-26T20:05:26.5486358Z 
2026-01-26T20:05:26.5486425Z ---
2026-01-26T20:05:26.5486880Z 	template: cfg:2:27: executing "cfg" at <upper>: invalid value; expected string

auto-merge was automatically disabled January 27, 2026 10:07

Head branch was pushed to by a user without write access

@olblak olblak enabled auto-merge (squash) January 28, 2026 20:27
Signed-off-by: Olblak <[email protected]>
@olblak olblak merged commit 0610ca8 into updatecli:main Jan 28, 2026
5 checks passed
@olblak olblak changed the title Add templating file path feat(file): add templating file path Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request resource-file Resource of kind File

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants