Skip to content

ext: upstream semver library from Kubernetes - #1632

Open
itzPranshul wants to merge 1 commit into
cel-expr:masterfrom
itzPranshul:upstream-semver-lib
Open

itzPranshul wants to merge 1 commit into
cel-expr:masterfrom
itzPranshul:upstream-semver-lib

Conversation

@itzPranshul

@itzPranshul itzPranshul commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #1510

This PR upstreams the CEL semantic versioning library from Kubernetes into cel-go as a standalone sub-module under ext/semver, keeping core cel-go dependencies unchanged.

Changes

  • ext/semver/semver.go: Adds Library(Version(v)) (with SemverLib / SemverVersion aliases) providing:
    • semver(...) and isSemver(...) with optional normalization (v1+).
    • Component accessors: .major(), .minor(), .patch().
    • Comparisons: .compareTo(), .isGreaterThan(), .isLessThan(), ==.
    • String conversion: string(semver(...)).
    • Compile-time AST literal validation (cel.validator.semver).
    • Cost models matching Kubernetes cost accounting (ResultSize of 1).
    • Custom type adapter for semver.Version, *semver.Version, and []semver.Version.
  • ext/semver/semver_test.go: Added unit tests, compile/runtime error tests, type conversion/adapter tests, and TestK8sCostParity to enforce 1:1 cost parity against Kubernetes test cases across model versions.
  • Build & Docs: Added ext/semver/go.mod, ext/semver/go.sum, ext/semver/BUILD.bazel, ext/semver/README.md, and registered github.com/blang/semver/v4 in MODULE.bazel.

Testing

  • Sub-module tests: cd ext/semver && go test -count=1 ./...
  • Core & vendor checks: ./scripts/verify-vendor.sh && go test -count=1 ./ext/... ./cel/...

@TristonianJones

Copy link
Copy Markdown
Collaborator

@itzPranshul thanks for the contribution. Could you perhaps place this extension under a new sub-module ext/semver? I'm not sure if SemVer for K8s is universal in terms of its capabilities, and I'd like to keep most of the core CEL deps the same if we can.

Upstream the semantic versioning library from Kubernetes into cel-go under the ext package, following the precedent set by the network (IP/CIDR) library.
@itzPranshul

Copy link
Copy Markdown
Author

@TristonianJones Makes total sense, i've moved the semVer extension into its own sub-module under ext/semver, keeps the core dependencies and the root vendor tree completely clean.

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.

Upstream semver library from Kubernetes into cel-go

2 participants