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

@ytt:semver #750

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/integrating-with-ytt/internal-templating/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ replace github.com/vmware-tanzu/carvel-ytt => ../../../
require github.com/vmware-tanzu/carvel-ytt v0.40.1

require (
github.com/hashicorp/go-version v1.4.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 // indirect
)
746 changes: 16 additions & 730 deletions examples/integrating-with-ytt/internal-templating/go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ require (
github.com/aws/aws-lambda-go v1.34.1
github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72
github.com/cppforlife/go-cli-ui v0.0.0-20200505234325-512793797f05
github.com/google/go-cmp v0.5.9
github.com/google/gofuzz v1.2.0
github.com/hashicorp/go-version v1.6.0
github.com/k14s/difflib v0.0.0-20201117154628-0c031775bf57
github.com/k14s/semver/v4 v4.0.1-0.20210701191048-266d47ac6115
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
Expand All @@ -34,6 +36,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/k14s/difflib v0.0.0-20201117154628-0c031775bf57 h1:CwBRArr+BWBopnUJhDjJw86rPL/jGbEjfHWKzTasSqE=
github.com/k14s/difflib v0.0.0-20201117154628-0c031775bf57/go.mod h1:B0xN2MiNBGWOWi9CcfAo9LBI8IU4J1utlbOIJCsmKr4=
github.com/k14s/semver/v4 v4.0.1-0.20210701191048-266d47ac6115 h1:wKSifC/VbCaQMqXYn6/gSFqle82OX4bE3KYALDU9FlU=
github.com/k14s/semver/v4 v4.0.1-0.20210701191048-266d47ac6115/go.mod h1:mGrnmO5qnhJIaSiwMo05cvRL6Ww9ccYbTgNFcm6RHZQ=
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 h1:4bcRTTSx+LKSxMWibIwzHnDNmaN1x52oEpvnjCy+8vk=
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368/go.mod h1:lKGj1op99m4GtQISxoD2t+K+WO/q2NzEPKvfXFQfbCA=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#@ load("@ytt:semver", "semver")
#@ load("@ytt:template", "template")
#@ load("@ytt:assert", "assert")

---
got: #@ semver.from_str("1.2.3").dict()
---
got: #@ semver.from_str("1.2.3-pre.123+build.456").dict()
---
#@ got, err = assert.try_to(lambda: semver.from_str())
got: #@ got
err: #@ err
---
#@ got, err = assert.try_to(lambda: semver.from_str("hello"))
got: #@ got
err: #@ err
---
#@ got, err = assert.try_to(lambda: semver.from_str("1.2.3-illeg@l"))
got: #@ got
err: #@ err

+++

got:
major: 1
minor: 2
patch: 3
prerelease: ""
build: ""
---
got:
major: 1
minor: 2
patch: 3
prerelease: pre.123
build: build.456
---
got: null
err: 'semver.version: expected exactly one argument'
---
got: null
err: 'semver.version: No Major.Minor.Patch elements found'
---
got: null
err: 'semver.version: Invalid character(s) found in PreRelease "illeg@l"'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#@ load("@ytt:semver", "semver")
#@ load("@ytt:assert", "assert")

---
got: #@ semver.range("1.2.3").contains(semver.from_str("1.2.3"))
---
got: #@ semver.range("1.2.3").contains(semver.version())
---
got: #@ semver.range("1.2.3 || 2.0.0").contains(semver.from_str("2.0.0"))

+++

got: true
---
got: false
---
got: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#@ load("@ytt:semver", "semver")
#@ load("@ytt:assert", "assert")

---
#@ _, err = assert.try_to(lambda: semver.range("1.2.3"))
err: #@ err
---
#@ _, err = assert.try_to(lambda: semver.range())
err: #@ err

+++

err: null
---
err: 'semver.version: expected exactly one argument'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#@ load("@ytt:semver", "semver")

---
got: #@ semver.from_str("1.2.3").cmp(semver.from_str("1.2.3"))
---
got: #@ semver.from_str("1.2.3").cmp(semver.from_str("2.0.0"))
---
got: #@ semver.from_str("1.2.3").cmp(semver.from_str("1.0.0"))

+++

got: 0
---
got: -1
---
got: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#@ load("@ytt:semver", "semver")
#@ load("@ytt:template", "template")
#@ load("@ytt:assert", "assert")

---
description: "All defaults"
#@ got, _ = assert.try_to(lambda: semver.version())
got: #@ got.dict()
---
description: "Major arg"
#@ got, _ = assert.try_to(lambda: semver.version(1))
got: #@ got.dict()
---
description: "Major+minor args"
#@ got, _ = assert.try_to(lambda: semver.version(1, 2))
got: #@ got.dict()
---
description: "Major+minor+patch args"
#@ got, _ = assert.try_to(lambda: semver.version(1, 2, 3))
got: #@ got.dict()
---
description: "Major+minor+patch+prerelease args"
#@ got, _ = assert.try_to(lambda: semver.version(1, 2, 3, "pre.123"))
got: #@ got.dict()
---
description: "All args"
#@ got, _ = assert.try_to(lambda: semver.version(1, 2, 3, "pre.123", "build.456"))
got: #@ got.dict()
---
description: "Patch kwarg"
#@ got, _ = assert.try_to(lambda: semver.version(patch=333))
got: #@ got.dict()
---
description: "Patch+major kwargs"
#@ got, _ = assert.try_to(lambda: semver.version(patch=33, major=11))
got: #@ got.dict()
---
description: "Bad major"
#@ got, err = assert.try_to(lambda: semver.version("hello"))
err: #@ err
---
description: "Unknown kwarg"
#@ _, err = assert.try_to(lambda: semver.version(hello=11))
err: #@ err

+++

description: All defaults
got:
major: 0
minor: 0
patch: 0
prerelease: ""
build: ""
---
description: Major arg
got:
major: 1
minor: 0
patch: 0
prerelease: ""
build: ""
---
description: Major+minor args
got:
major: 1
minor: 2
patch: 0
prerelease: ""
build: ""
---
description: Major+minor+patch args
got:
major: 1
minor: 2
patch: 3
prerelease: ""
build: ""
---
description: Major+minor+patch+prerelease args
got:
major: 1
minor: 2
patch: 3
prerelease: pre.123
build: ""
---
description: All args
got:
major: 1
minor: 2
patch: 3
prerelease: pre.123
build: build.456
---
description: Patch kwarg
got:
major: 0
minor: 0
patch: 333
prerelease: ""
build: ""
---
description: Patch+major kwargs
got:
major: 11
minor: 0
patch: 33
prerelease: ""
build: ""
---
description: Bad major
err: 'semver.version: version: for parameter major: got string, want int'
---
description: Unknown kwarg
err: 'semver.version: unexpected kwarg "hello". expected kwargs are [major, minor, patch, prerelease, build]'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#@ load("@ytt:semver", "semver")
#@ load("@ytt:template", "template")
#@ load("@ytt:assert", "assert")

---
description: "All defaults"
#@ got, _ = assert.try_to(lambda: semver.version())
got:
major: #@ got.major
minor: #@ got.minor
patch: #@ got.patch
prerelease: #@ got.prerelease
build: #@ got.build

+++

description: All defaults
got:
major: 0
minor: 0
patch: 0
prerelease: ""
build: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#@ load("@ytt:semver", "semver")

#@ original = semver.from_str("1.2.3")
next_patch: #@ original.next_patch().string()
next_minor: #@ original.next_minor().string()
next_major: #@ original.next_major().string()
original: #@ original.string()

+++

next_patch: 1.2.4
next_minor: 1.3.0
next_major: 2.0.0
original: 1.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#@ load("@ytt:semver", "semver")
#@ load("@ytt:template", "template")
#@ load("@ytt:assert", "assert")

---
got: #@ semver.version().string()
---
got: #@ semver.version(1, 2, 3).string()
---
got: #@ semver.version(1, 2, 3, "pre.123").string()
---
got: #@ semver.version(1, 2, 3, "pre.123", "build.456").string()
---
got: #@ semver.version(prerelease="pre.123", build="build.456").string()

+++

got: 0.0.0
---
got: 1.2.3
---
got: 1.2.3-pre.123
---
got: 1.2.3-pre.123+build.456
---
got: 0.0.0-pre.123+build.456
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#@ load("@ytt:semver", "semver")

#@ version = semver.version(1, 2, 3)
version: #@ version

+++

ERR:
- __ytt_tplXXX_set_node: Unable to convert value: @ytt:semver.version does not automatically encode (hint: use .string())
in <toplevel>
stdin:4 | version: #@ version
1 change: 1 addition & 0 deletions pkg/yttlibrary/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func NewAPI(

// Versioning
"version": VersionAPI,
"semver": SemverAPI,

"library": libraryMod,
}
Expand Down