From 635e78c38aa1cb0f31efff7f5cb0eecfe93f505c Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Sat, 25 Nov 2023 00:21:01 +0800 Subject: feat(funcs): add semver functions (#1829) * feat(funcs): add semver functions - semver.Version: new a SemVer struct. - semver.MatchConstraint: match in arg with semver constraint string. refer to: https://github.com/Masterminds/sprig/blob/master/semver.go * docs(functions): add documents for semver functions * Update docs-src/content/functions/semver.yaml Co-authored-by: Dave Henderson * fix(funcs,docs,docs-src): fix the reviewing issues --------- Co-authored-by: Dave Henderson --- docs-src/content/functions/semver.yml | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docs-src/content/functions/semver.yml (limited to 'docs-src') diff --git a/docs-src/content/functions/semver.yml b/docs-src/content/functions/semver.yml new file mode 100644 index 00000000..08710afa --- /dev/null +++ b/docs-src/content/functions/semver.yml @@ -0,0 +1,49 @@ +ns: semver +preamble: | + These functions allow user you to parse a [semantic version](http://semver.org/) string or test it with constraint. + + It's implemented with the https://github.com/Masterminds/semver library. +funcs: + - name: semver.Semver + description: | + Returns a semantic version struct holding the `input` version string. + + The returned struct are defined at: [`semver.Version`](https://pkg.go.dev/github.com/Masterminds/semver/v3#Version). + pipeline: true + arguments: + - name: input + required: true + description: The input to parse + examples: + - | + $ gomplate -i '{{ semver.Semver "v1.1.1"}}' + 1.1.1 + - | + $ gomplate -i '{{ (semver.Semver "v1.1.1").Major }}' + 1 + - | + $ gomplate -i 'the pre release version is {{ ("v1.1.1" | semver.Semver).SetPrerelease "beta.1" }}' + the pre release version is 1.1.1-beta.1 + - name: semver.CheckConstraint + description: | + Test whether the input version matchs the constraint. + + Ref: https://github.com/Masterminds/semver#checking-version-constraints + pipeline: true + arguments: + - name: constraint + required: true + description: The constraints expression to test. + - name: input + required: true + description: The input semantic version string to test. + examples: + - | + $ gomplate -i '{{ semver.CheckConstraint "> 1.0" "v1.1.1" }}' + true + - | + $ gomplate -i '{{ semver.CheckConstraint "> 1.0, <1.1" "v1.1.1" }}' + false + - | + $ gomplate -i '{{ "v1.1.1" | semver.CheckConstraint "> 1.0" }}' + true -- cgit v1.2.3