feat(file): add templating file path#7591
Conversation
There was a problem hiding this comment.
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
Templatefield 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
Templateis mutually exclusive withContent,MatchPattern,ReplacePattern, andLine - 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.
Co-authored-by: Copilot <[email protected]>
|
Doc PR: #7591 |
|
Thank you for the pull request, it's an interesting approach that I never thought about. |
olblak
left a comment
There was a problem hiding this comment.
Thank you for the pull request
|
@mallendem could you have a look about this e2e tests is not passing? |
Head branch was pushed to by a user without write access
Signed-off-by: Olblak <[email protected]>
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
Additional Information
Checklist
Potential improvement
It allows more fine tuned templating bypassing the initial loading done by updatecli, so templating rendering is supported. Something like:
version.tmpl:
should work