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

Add slim-sprig functions to template language #451

Merged
merged 2 commits into from
Dec 31, 2023

Conversation

obbardc
Copy link
Member

@obbardc obbardc commented Nov 24, 2023

No description provided.

@obbardc obbardc requested a review from sjoerdsimons November 24, 2023 17:06
@obbardc obbardc self-assigned this Nov 24, 2023
Comment on lines 37 to 39
- decimal: Returns the integer argument as a decimal integer e.g. `{{ decimal 0x40 }} => 64`
- add: Returns the calculation of two integer arguments `a + b`, e.g. `{{ add 1 1 }} => 2`
- sub: Returns the calculation of two integer arguments `a - b`, e.g. `{{ sub 10 1 }} => 9`
Copy link
Member

Choose a reason for hiding this comment

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

If we go this route i'd rather pull in exist library with template functions; doing some google makes sprig come up (https://pkg.go.dev/github.com/go-task/slim-sprig/v3#section-readme) with includes those and many more integer operations etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep it seems to work; i have added that into the top commit.
it's in debian as https://packages.debian.org/sid/source/golang-github-masterminds-sprig

Copy link
Member

Choose a reason for hiding this comment

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

that's the full sprig mind ; slim-spring limits sprig to not depend on extra dependencies (which may avoid the CI failure you're seeing)..

Also can you clean up you branch so it doesn't have commits that get converted later and drop the decimal function ? that should be unneeded (int should do the trick there)

Copy link
Member Author

Choose a reason for hiding this comment

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

i added slim-sprig, it's not in debian yet though.
right I did that as a quick test, it wasnt of course meant to be final ;-)

Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a minimal test case to ensure the functions are available? Also it seems to fail to build on bullseye, though i'm ok to drop support for that assuming it's due to a golang version issue.

@obbardc obbardc changed the title Add decimal, add, sub functions to template language Add Sprig functions to template language Nov 27, 2023
@obbardc obbardc force-pushed the wip/obbardc/image-partition-hex branch 2 times, most recently from 7953f28 to 34ae5ee Compare November 28, 2023 18:44
@obbardc obbardc changed the title Add Sprig functions to template language Add slim-sprig functions to template language Nov 28, 2023
@obbardc obbardc force-pushed the wip/obbardc/image-partition-hex branch from 34ae5ee to 503694b Compare November 28, 2023 18:46
actions/recipe.go Outdated Show resolved Hide resolved
Comment on lines 37 to 39
- decimal: Returns the integer argument as a decimal integer e.g. `{{ decimal 0x40 }} => 64`
- add: Returns the calculation of two integer arguments `a + b`, e.g. `{{ add 1 1 }} => 2`
- sub: Returns the calculation of two integer arguments `a - b`, e.g. `{{ sub 10 1 }} => 9`
Copy link
Member Author

Choose a reason for hiding this comment

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

i added slim-sprig, it's not in debian yet though.
right I did that as a quick test, it wasnt of course meant to be final ;-)

@obbardc obbardc requested a review from sjoerdsimons November 29, 2023 09:31
@sjoerdsimons sjoerdsimons force-pushed the wip/obbardc/image-partition-hex branch from 503694b to 0a13528 Compare December 30, 2023 14:48
slim-sprig is a lightweight library containing a number of useful helper
functions which are useful to use in go templates. Include it in debos
so we can use the functions in recipes.

Signed-off-by: Christopher Obbard <[email protected]>
@sjoerdsimons sjoerdsimons force-pushed the wip/obbardc/image-partition-hex branch from aa282b0 to b7884de Compare December 30, 2023 18:25
Renaming the escaping test to a general templating test and add tests
for a selection of functions from sprig-slim as well as the builtin
sector function

Signed-off-by: Sjoerd Simons <[email protected]>
@sjoerdsimons sjoerdsimons added this pull request to the merge queue Dec 30, 2023
Merged via the queue into main with commit 94d0610 Dec 31, 2023
62 checks passed
@sjoerdsimons sjoerdsimons deleted the wip/obbardc/image-partition-hex branch January 19, 2024 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants