semver

A fast, spec-compliant Go library for parsing, comparing, and sorting semantic versions with npm-style range constraints.

Library
Go
vv3.5.0
1,442 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
63 /100 Good
Development Activity 40
Maintenance 44
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
77 /100 Good
Architecture 78
Code Quality 92
Innovation 74
Learning Curve 65

Masterminds/semver is a pure Go package for working with Semantic Versions: parsing version strings, sorting them, and checking whether they satisfy a constraint expression. It supports both strict RFC-compliant parsing via StrictNewVersion and a coercive NewVersion that tolerates partial or non-compliant version strings (like CalVer-style values with leading zeros), making it useful for real-world version strings that don’t perfectly follow the spec.

Constraint checking follows the range conventions popularized by npm and Cargo rather than a from-scratch design, supporting comparison operators (=, !=, >, <, >=, <=), hyphen ranges, wildcards (x, X, *), and the tilde (~) and caret (^) shorthand operators for patch- and major-level ranges. The library is widely used as the versioning engine inside dependency-management and package-manager tooling across the Go ecosystem, including Helm and dep.

What You Get

  • A Version type with strict (StrictNewVersion) and coercive (NewVersion) parsing
  • A Constraints type supporting =, !=, >, <, >=, <=, hyphen ranges, wildcards, ~, and ^ operators
  • A Collection type implementing sort.Interface for sorting slices of versions
  • JSON, text, and database/sql (Scan/Value) marshaling support on Version
  • Safe increment helpers (IncMajorE, IncMinorE, IncPatchE) that return errors on uint64 overflow instead of panicking

Common Use Cases

  • Validating that a dependency’s installed version satisfies a version range declared in a manifest file
  • Sorting a list of Git tags or release versions into semantic order
  • Implementing update-policy logic (e.g. “only auto-upgrade patch releases”) using tilde/caret constraints
  • Storing and retrieving parsed version values directly from a SQL database column

Under The Hood

Architecture

The package is a single flat semver package with no internal layering: version.go defines the Version type and its parsing/comparison/marshaling methods, constraints.go defines Constraints/constraint and the regex-driven range grammar (rewriteRange, findConstraintRegex, validConstraintRegex), and collection.go is a small adapter implementing sort.Interface. There is no dependency injection or multi-layer design because the surface area is intentionally narrow: parse a string into a Version, evaluate a Constraints against it. Data flows one direction — string in, typed struct out, boolean/int out of comparisons — with no external I/O and no state beyond two package-level regexes compiled once in init(). Because the type is small and consumers only ever touch exported methods, changes to the core struct stay contained to this one file.

Tech Stack

go.mod declares the module for Go 1.21 with zero third-party dependencies — the implementation relies solely on the standard library (regexp, strings, strconv, encoding/json, database/sql/driver). Build tooling is a plain Makefile wrapping go test/go vet, CI runs through GitHub Actions (test, golangci-lint, CodeQL, and a native Go fuzz job) against current Go releases, and golangci-lint v2 is configured with a strict linter set including gosec, gocyclo, errcheck, staticcheck, revive, and unparam. As a dependency-free leaf library it’s built to be vendored into other Go binaries — notably Helm and dep — and it implements database/sql/driver.Valuer/Scanner purely so consuming applications can persist Version values without extra glue code.

Code Quality

Testing is extensive: version_test.go and constraints_test.go each carry roughly 1,200 lines of table-driven tests covering parsing edge cases, comparison ordering, and marshaling, alongside a dedicated benchmark suite and a CI fuzz job exercising the parser continuously. Error handling is idiomatic Go — exported sentinel errors (ErrInvalidSemVer, ErrEmptyString, ErrIncrementOverflow) are returned rather than panicking, and ...E-suffixed increment variants were added specifically to replace silent-overflow behavior with explicit, wrappable errors. Naming is consistent and idiomatic, the codebase is gofmt/goimports-formatted, and CI enforces a strict golangci-lint v2 profile plus CodeQL static analysis. Bounded-input constants (MaxVersionLen, MaxConstraintLen, MaxConstraintGroups) show deliberate hardening against oversized or adversarial input.

API Design The public API is deliberately minimal: NewVersion offers permissive coercion while StrictNewVersion enforces spec compliance, letting callers opt into exactly the leniency they need, and MustParse gives a panic-on-error convenience for tests and constants. Constraint syntax intentionally mirrors what developers already know from npm and Cargo (~, ^, hyphen ranges, wildcards) instead of inventing new range grammar, lowering the learning curve for anyone coming from another ecosystem’s version ranges. Zero-boilerplate integration is a deliberate goal — Version implements fmt.Stringer, JSON, text, and SQL driver interfaces so it drops directly into JSON APIs, config structs, and database columns without adapter code, and package-level toggles (CoerceNewVersion, DetailedNewVersionErrors) let callers tune strictness and performance trade-offs globally.

Used by 22 apps in this directory

Go
62%
Apache 2.0

Harness Open Source

Code Editors · Developer Tools · Devops

38,684

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
90
Repo Health
79
Technical
64
Dependency
Built with
Go 62%
TypeScript 33%
Updated 1 weeks ago
Go
87%
MIT

Hatchet

AI Development · Automation · Developer Tools

8,174

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
67
Dependency
Built with
Go 87%
Updated 1 weeks ago
TypeScript
51%
Other

Mattermost

Collaboration · Devops · Team Chat

39,418

Open core, self-hosted team collaboration with chat, AI agents, voice calling, and deep DevOps integrations — all under your control.

View details
96
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 51%
Go 40%
Updated 1 weeks ago
Go
97%
Other

Netmaker

Automation · Security

11,836

Automate secure WireGuard mesh networks from homelab to enterprise scale without manual configuration.

View details
92
Repo Health
79
Technical
70
Dependency
Built with
Go 97%
Updated 1 weeks ago
Go
99%
Apache 2.0

Okteto

Developer Tools · Devops

3,554

Develop applications directly inside your Kubernetes cluster with real-time file sync and instant hot-reload — no more docker build/redeploy cycles.

View details
91
Repo Health
79
Technical
69
Dependency
Built with
Go 99%
Updated 1 weeks ago
Go
52%
Apache 2.0

opencloud

File Storage

6,218

Open source file management and collaboration platform that keeps your data under your control, no database required.

View details
86
Repo Health
80
Technical
68
Dependency
Built with
Go 52%
Gherkin 33%
PHP 11%
Updated 1 weeks ago
TypeScript
54%
Other

OpenReplay

Analytics

13,042

Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.

View details
91
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 54%
Go 13%
Updated 1 weeks ago
Go
93%
MIT

Plandex

AI Code Assistants

15,777

An open-source, terminal-based AI coding agent built for large tasks and real codebases — with its own version control for plans, a 2M-token effective context window, and self-hosted or cloud deployment.

View details
50
Repo Health
70
Technical
67
Dependency
Built with
Go 93%
Updated 1 years ago
TypeScript
51%
ZLIB

Portainer

Devops

38,707

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
93
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers