{"id":13492354,"url":"https://github.com/blang/semver","last_synced_at":"2025-05-14T00:07:22.552Z","repository":{"id":18248341,"uuid":"21400970","full_name":"blang/semver","owner":"blang","description":"Semantic Versioning (semver) library written in golang","archived":false,"fork":false,"pushed_at":"2023-01-15T12:58:59.000Z","size":87,"stargazers_count":1026,"open_issues_count":19,"forks_count":101,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-10T02:17:04.447Z","etag":null,"topics":["go","golang","semantic-versioning","semantic-versions","semver"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-01T20:08:15.000Z","updated_at":"2025-04-09T17:29:55.000Z","dependencies_parsed_at":"2023-01-16T21:45:35.476Z","dependency_job_id":null,"html_url":"https://github.com/blang/semver","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blang%2Fsemver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blang%2Fsemver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blang%2Fsemver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blang%2Fsemver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blang","download_url":"https://codeload.github.com/blang/semver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142907,"owners_count":21054672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","semantic-versioning","semantic-versions","semver"],"created_at":"2024-07-31T19:01:05.259Z","updated_at":"2025-04-10T02:17:29.530Z","avatar_url":"https://github.com/blang.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"semver for golang [![Build Status](https://travis-ci.org/blang/semver.svg?branch=master)](https://travis-ci.org/blang/semver) [![GoDoc](https://godoc.org/github.com/blang/semver/v4?status.svg)](https://godoc.org/github.com/blang/semver/v4) [![Coverage Status](https://img.shields.io/coveralls/blang/semver.svg)](https://coveralls.io/r/blang/semver?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/blang/semver)](https://goreportcard.com/report/github.com/blang/semver)\n======\n\nsemver is a [Semantic Versioning](http://semver.org/) library written in golang. It fully covers spec version `2.0.0`.\n\nVersioning\n----------\nOld v1-v3 versions exist in the root of the repository for compatiblity reasons and will only receive bug fixes.\n\nThe current stable version is [*v4*](v4/) and is fully go-mod compatible.\n\nUsage\n-----\n```bash\n$ go get github.com/blang/semver/v4\n# Or use fixed versions\n$ go get github.com/blang/semver/v4@v4.0.0\n```\nNote: Always vendor your dependencies or fix on a specific version tag.\n\n```go\nimport github.com/blang/semver/v4\nv1, err := semver.Make(\"1.0.0-beta\")\nv2, err := semver.Make(\"2.0.0-beta\")\nv1.Compare(v2)\n```\n\nAlso check the [GoDocs](http://godoc.org/github.com/blang/semver/v4).\n\nWhy should I use this lib?\n-----\n\n- Fully spec compatible\n- No reflection\n- No regex\n- Fully tested (Coverage \u003e99%)\n- Readable parsing/validation errors\n- Fast (See [Benchmarks](#benchmarks))\n- Only Stdlib\n- Uses values instead of pointers\n- Many features, see below\n\n\nFeatures\n-----\n\n- Parsing and validation at all levels\n- Comparator-like comparisons\n- Compare Helper Methods\n- InPlace manipulation\n- Ranges `\u003e=1.0.0 \u003c2.0.0 || \u003e=3.0.0 !3.0.1-beta.1`\n- Wildcards `\u003e=1.x`, `\u003c=2.5.x`\n- Sortable (implements sort.Interface)\n- database/sql compatible (sql.Scanner/Valuer)\n- encoding/json compatible (json.Marshaler/Unmarshaler)\n\nRanges\n------\n\nA `Range` is a set of conditions which specify which versions satisfy the range.\n\nA condition is composed of an operator and a version. The supported operators are:\n\n- `\u003c1.0.0` Less than `1.0.0`\n- `\u003c=1.0.0` Less than or equal to `1.0.0`\n- `\u003e1.0.0` Greater than `1.0.0`\n- `\u003e=1.0.0` Greater than or equal to `1.0.0`\n- `1.0.0`, `=1.0.0`, `==1.0.0` Equal to `1.0.0`\n- `!1.0.0`, `!=1.0.0` Not equal to `1.0.0`. Excludes version `1.0.0`.\n\nNote that spaces between the operator and the version will be gracefully tolerated.\n\nA `Range` can link multiple `Ranges` separated by space:\n\nRanges can be linked by logical AND:\n\n  - `\u003e1.0.0 \u003c2.0.0` would match between both ranges, so `1.1.1` and `1.8.7` but not `1.0.0` or `2.0.0`\n  - `\u003e1.0.0 \u003c3.0.0 !2.0.3-beta.2` would match every version between `1.0.0` and `3.0.0` except `2.0.3-beta.2`\n\nRanges can also be linked by logical OR:\n\n  - `\u003c2.0.0 || \u003e=3.0.0` would match `1.x.x` and `3.x.x` but not `2.x.x`\n\nAND has a higher precedence than OR. It's not possible to use brackets.\n\nRanges can be combined by both AND and OR\n\n  - `\u003e1.0.0 \u003c2.0.0 || \u003e3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1`\n\nRange usage:\n\n```\nv, err := semver.Parse(\"1.2.3\")\nexpectedRange, err := semver.ParseRange(\"\u003e1.0.0 \u003c2.0.0 || \u003e=3.0.0\")\nif expectedRange(v) {\n    //valid\n}\n\n```\n\nExample\n-----\n\nHave a look at full examples in [v4/examples/main.go](v4/examples/main.go)\n\n```go\nimport github.com/blang/semver/v4\n\nv, err := semver.Make(\"0.0.1-alpha.preview+123.github\")\nfmt.Printf(\"Major: %d\\n\", v.Major)\nfmt.Printf(\"Minor: %d\\n\", v.Minor)\nfmt.Printf(\"Patch: %d\\n\", v.Patch)\nfmt.Printf(\"Pre: %s\\n\", v.Pre)\nfmt.Printf(\"Build: %s\\n\", v.Build)\n\n// Prerelease versions array\nif len(v.Pre) \u003e 0 {\n    fmt.Println(\"Prerelease versions:\")\n    for i, pre := range v.Pre {\n        fmt.Printf(\"%d: %q\\n\", i, pre)\n    }\n}\n\n// Build meta data array\nif len(v.Build) \u003e 0 {\n    fmt.Println(\"Build meta data:\")\n    for i, build := range v.Build {\n        fmt.Printf(\"%d: %q\\n\", i, build)\n    }\n}\n\nv001, err := semver.Make(\"0.0.1\")\n// Compare using helpers: v.GT(v2), v.LT, v.GTE, v.LTE\nv001.GT(v) == true\nv.LT(v001) == true\nv.GTE(v) == true\nv.LTE(v) == true\n\n// Or use v.Compare(v2) for comparisons (-1, 0, 1):\nv001.Compare(v) == 1\nv.Compare(v001) == -1\nv.Compare(v) == 0\n\n// Manipulate Version in place:\nv.Pre[0], err = semver.NewPRVersion(\"beta\")\nif err != nil {\n    fmt.Printf(\"Error parsing pre release version: %q\", err)\n}\n\nfmt.Println(\"\\nValidate versions:\")\nv.Build[0] = \"?\"\n\nerr = v.Validate()\nif err != nil {\n    fmt.Printf(\"Validation failed: %s\\n\", err)\n}\n```\n\n\nBenchmarks\n-----\n\n    BenchmarkParseSimple-4           5000000    390    ns/op    48 B/op   1 allocs/op\n    BenchmarkParseComplex-4          1000000   1813    ns/op   256 B/op   7 allocs/op\n    BenchmarkParseAverage-4          1000000   1171    ns/op   163 B/op   4 allocs/op\n    BenchmarkStringSimple-4         20000000    119    ns/op    16 B/op   1 allocs/op\n    BenchmarkStringLarger-4         10000000    206    ns/op    32 B/op   2 allocs/op\n    BenchmarkStringComplex-4         5000000    324    ns/op    80 B/op   3 allocs/op\n    BenchmarkStringAverage-4         5000000    273    ns/op    53 B/op   2 allocs/op\n    BenchmarkValidateSimple-4      200000000      9.33 ns/op     0 B/op   0 allocs/op\n    BenchmarkValidateComplex-4       3000000    469    ns/op     0 B/op   0 allocs/op\n    BenchmarkValidateAverage-4       5000000    256    ns/op     0 B/op   0 allocs/op\n    BenchmarkCompareSimple-4       100000000     11.8  ns/op     0 B/op   0 allocs/op\n    BenchmarkCompareComplex-4       50000000     30.8  ns/op     0 B/op   0 allocs/op\n    BenchmarkCompareAverage-4       30000000     41.5  ns/op     0 B/op   0 allocs/op\n    BenchmarkSort-4                  3000000    419    ns/op   256 B/op   2 allocs/op\n    BenchmarkRangeParseSimple-4      2000000    850    ns/op   192 B/op   5 allocs/op\n    BenchmarkRangeParseAverage-4     1000000   1677    ns/op   400 B/op  10 allocs/op\n    BenchmarkRangeParseComplex-4      300000   5214    ns/op  1440 B/op  30 allocs/op\n    BenchmarkRangeMatchSimple-4     50000000     25.6  ns/op     0 B/op   0 allocs/op\n    BenchmarkRangeMatchAverage-4    30000000     56.4  ns/op     0 B/op   0 allocs/op\n    BenchmarkRangeMatchComplex-4    10000000    153    ns/op     0 B/op   0 allocs/op\n\nSee benchmark cases at [semver_test.go](semver_test.go)\n\n\nMotivation\n-----\n\nI simply couldn't find any lib supporting the full spec. Others were just wrong or used reflection and regex which i don't like.\n\n\nContribution\n-----\n\nFeel free to make a pull request. For bigger changes create a issue first to discuss about it.\n\n\nLicense\n-----\n\nSee [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblang%2Fsemver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblang%2Fsemver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblang%2Fsemver/lists"}