Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Masterminds/semver
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e06051f
Choose a base ref
...
head repository: Masterminds/semver
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e6e3d4d
Choose a head ref

Commits on Apr 10, 2023

  1. Updated changelog for 3.2.1

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed Apr 10, 2023
    Copy the full SHA
    2f39fdc View commit details

Commits on Jul 28, 2023

  1. feat: nil version equality

    This changes the Equal method to return true for 2 nil values and false if any one of the values is nil. Previously passing a nil value would have resulted in a panic.
    KnutZuidema committed Jul 28, 2023
    Copy the full SHA
    441ff8e View commit details

Commits on Aug 29, 2023

  1. Copy the full SHA
    878c2c0 View commit details

Commits on Oct 28, 2023

  1. Fix spelling in README

    robinschneider committed Oct 28, 2023
    Copy the full SHA
    e7596aa View commit details

Commits on Nov 16, 2023

  1. Fix: bad package in README

    This PR fixes the bad package name in the README file.
    sdelicata authored Nov 16, 2023
    Copy the full SHA
    e481cee View commit details

Commits on Dec 11, 2023

  1. Merge pull request #226 from sdelicata/patch-1

    Fix: bad package in README
    mattfarina authored Dec 11, 2023
    Copy the full SHA
    98fc853 View commit details

Commits on Feb 19, 2024

  1. Updating the GitHub Actions and versions of Go used

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed Feb 19, 2024
    Copy the full SHA
    ad79e44 View commit details
  2. Merge pull request #229 from mattfarina/bump-actions-go

    Updating the GitHub Actions and versions of Go used
    mattfarina authored Feb 19, 2024
    Copy the full SHA
    10ab64a View commit details

Commits on May 6, 2024

  1. Merge pull request #222 from robinschneider/fix-readme-spelling

    Fix spelling in README
    mattfarina authored May 6, 2024
    Copy the full SHA
    afc280a View commit details
  2. Adding go build cache to fuzz output

    This is to capture the location in CI in order to cache across fuzz runs
    
    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed May 6, 2024
    Copy the full SHA
    4ea5ce9 View commit details
  3. Merge pull request #232 from mattfarina/show-build-cache

    Adding go build cache to fuzz output
    mattfarina authored May 6, 2024
    Copy the full SHA
    4afef01 View commit details

Commits on May 8, 2024

  1. Add caching to fuzz testing

    This makes fuzz testing additive to previous scans
    
    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed May 8, 2024
    Copy the full SHA
    2a7536d View commit details
  2. Merge pull request #234 from mattfarina/cache-fuzz

    Add caching to fuzz testing
    mattfarina authored May 8, 2024
    Copy the full SHA
    7a8e81a View commit details

Commits on May 14, 2024

  1. updating github actions

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed May 14, 2024
    Copy the full SHA
    4539eca View commit details
  2. Merge pull request #235 from mattfarina/update-actions

    updating github actions
    mattfarina authored May 14, 2024
    Copy the full SHA
    3d240d7 View commit details
  3. Merge pull request #213 from KnutZuidema/feat/nil_equal

    feat: nil version equality
    mattfarina authored May 14, 2024
    Copy the full SHA
    347f541 View commit details

Commits on May 21, 2024

  1. add >= and <=

    grosser committed May 21, 2024
    Copy the full SHA
    be924f5 View commit details

Commits on Jun 4, 2024

  1. Merge pull request #238 from grosser/grosser/lte

    add >= and <=
    mattfarina authored Jun 4, 2024
    Copy the full SHA
    9ec6f29 View commit details
  2. Merge pull request #216 from johnnychen94/patch-1

    doc: hyphen range constraint without whitespace
    mattfarina authored Jun 4, 2024
    Copy the full SHA
    f4a4d83 View commit details

Commits on Jun 5, 2024

  1. simplify StrictNewVersion

    grosser committed Jun 5, 2024
    Copy the full SHA
    d07450b View commit details

Commits on Aug 27, 2024

  1. Removing reference to vert

    vert is not longer using a supported version of this lib.
    
    Closes #244
    
    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed Aug 27, 2024
    Copy the full SHA
    b55476a View commit details
  2. Merge pull request #245 from mattfarina/remove-vert

    Removing reference to vert
    mattfarina authored Aug 27, 2024
    Copy the full SHA
    2cf1b16 View commit details
  3. Merge pull request #241 from grosser/grosser/validate

    simplify StrictNewVersion
    mattfarina authored Aug 27, 2024
    Copy the full SHA
    29f94c1 View commit details
  4. Updating the testing version of Go used

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed Aug 27, 2024
    Copy the full SHA
    7c178cf View commit details
  5. Merge pull request #246 from mattfarina/bump-go-1.23

    Updating the testing version of Go used
    mattfarina authored Aug 27, 2024
    Copy the full SHA
    a4cccd8 View commit details
  6. bumping min version in go.mod based on what's tested

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed Aug 27, 2024
    Copy the full SHA
    b610837 View commit details
  7. Merge pull request #248 from mattfarina/bump-min-version

    bumping min version in go.mod based on what's tested
    mattfarina authored Aug 27, 2024
    Copy the full SHA
    80427ad View commit details
  8. Updating changelog for 3.3.0

    Signed-off-by: Matt Farina <matt@mattfarina.com>
    mattfarina committed Aug 27, 2024
    Copy the full SHA
    e80c4ea View commit details
  9. Merge pull request #249 from mattfarina/update-changelog-3.3.0

    Updating changelog for 3.3.0
    mattfarina authored Aug 27, 2024
    Copy the full SHA
    e6e3d4d View commit details
Showing with 192 additions and 71 deletions.
  1. +4 −4 .github/workflows/codeql.yaml
  2. +36 −3 .github/workflows/fuzz.yaml
  3. +5 −5 .github/workflows/golangci-lint.yml
  4. +3 −3 .github/workflows/test.yaml
  5. +28 −0 CHANGELOG.md
  6. +2 −1 Makefile
  7. +14 −14 README.md
  8. +1 −1 constraints_test.go
  9. +1 −1 go.mod
  10. +32 −32 version.go
  11. +66 −7 version_test.go
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -17,15 +17,15 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: go

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
39 changes: 36 additions & 3 deletions .github/workflows/fuzz.yaml
Original file line number Diff line number Diff line change
@@ -9,12 +9,45 @@ on:
jobs:
test:
runs-on: ubuntu-latest
env:
cache-key: fuzzing
steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
# There are no dependencies so there is no go.sum file. This is needed
# for the cache key generation. So, caching doesn't happen and a
# warning is presented on each run. Disabling the Go cache and caching
# the go-build cache separately for fuzzing.
cache: false
go-version: "1.23"
# The cache path may be different on different runners. GitHub may change
# this in the future. So, we dynamically fetch it.
- name: Get Go Cache Paths
id: go-cache-paths
run: echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Restore Cache
id: cache-restore
uses: actions/cache/restore@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ env.cache-key }}
- name: Fuzz
run: make fuzz
# Cannot overwrite the existing cache (id's are immutable) so we delete it.
- name: Delete Previous Cache
if: ${{ steps.cache-restore.outputs.cache-hit }}
continue-on-error: true
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete "${{ env.cache-key }}" --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Saving the cache so that Fuzz testing can be additive to previous fuzz testing.
- name: Save Cache
uses: actions/cache/save@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ env.cache-key }}
10 changes: 5 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.23"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
uses: golangci/golangci-lint-action@v4
with:
version: v1.52
version: v1.60
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -4,16 +4,16 @@ jobs:
test:
strategy:
matrix:
go-version: [1.18.x, 1.19.x, 1.20.x]
go-version: [1.21.x, 1.22.x, 1.23.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Test
env:
GO111MODULE: on
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## 3.3.0 (2024-08-27)

### Added

- #238: Add LessThanEqual and GreaterThanEqual functions (thanks @grosser)
- #213: nil version equality checking (thanks @KnutZuidema)

### Changed

- #241: Simplify StrictNewVersion parsing (thanks @grosser)
- Testing support up through Go 1.23
- Minimum version set to 1.21 as this is what's tested now
- Fuzz testing now supports caching

## 3.2.1 (2023-04-10)

### Changed

- #198: Improved testing around pre-release names
- #200: Improved code scanning with addition of CodeQL
- #201: Testing now includes Go 1.20. Go 1.17 has been dropped
- #202: Migrated Fuzz testing to Go built-in Fuzzing. CI runs daily
- #203: Docs updated for security details

### Fixed

- #199: Fixed issue with range transformations

## 3.2.0 (2022-11-28)

### Added
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ test-cover:
.PHONY: fuzz
fuzz:
@echo "==> Running Fuzz Tests"
go env GOCACHE
go test -fuzz=FuzzNewVersion -fuzztime=15s .
go test -fuzz=FuzzStrictNewVersion -fuzztime=15s .
go test -fuzz=FuzzNewConstraint -fuzztime=15s .
@@ -27,4 +28,4 @@ $(GOLANGCI_LINT):
# Install golangci-lint. The configuration for it is in the .golangci.yml
# file in the root of the repository
echo ${GOPATH}
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.17.1
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.56.2
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -13,12 +13,9 @@ Active](https://masterminds.github.io/stability/active.svg)](https://masterminds
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/Masterminds/semver/v3)
[![Go Report Card](https://goreportcard.com/badge/github.com/Masterminds/semver)](https://goreportcard.com/report/github.com/Masterminds/semver)

If you are looking for a command line tool for version comparisons please see
[vert](https://github.com/Masterminds/vert) which uses this library.

## Package Versions

Note, import `github.com/github.com/Masterminds/semver/v3` to use the latest version.
Note, import `github.com/Masterminds/semver/v3` to use the latest version.

There are three major versions fo the `semver` package.

@@ -80,12 +77,12 @@ There are two methods for comparing versions. One uses comparison methods on
differences to notes between these two methods of comparison.

1. When two versions are compared using functions such as `Compare`, `LessThan`,
and others it will follow the specification and always include prereleases
and others it will follow the specification and always include pre-releases
within the comparison. It will provide an answer that is valid with the
comparison section of the spec at https://semver.org/#spec-item-11
2. When constraint checking is used for checks or validation it will follow a
different set of rules that are common for ranges with tools like npm/js
and Rust/Cargo. This includes considering prereleases to be invalid if the
and Rust/Cargo. This includes considering pre-releases to be invalid if the
ranges does not include one. If you want to have it include pre-releases a
simple solution is to include `-0` in your range.
3. Constraint ranges can have some complex rules including the shorthand use of
@@ -113,7 +110,7 @@ v, err := semver.NewVersion("1.3")
if err != nil {
// Handle version not being parsable.
}
// Check if the version meets the constraints. The a variable will be true.
// Check if the version meets the constraints. The variable a will be true.
a := c.Check(v)
```

@@ -137,20 +134,20 @@ The basic comparisons are:
### Working With Prerelease Versions

Pre-releases, for those not familiar with them, are used for software releases
prior to stable or generally available releases. Examples of prereleases include
development, alpha, beta, and release candidate releases. A prerelease may be
prior to stable or generally available releases. Examples of pre-releases include
development, alpha, beta, and release candidate releases. A pre-release may be
a version such as `1.2.3-beta.1` while the stable release would be `1.2.3`. In the
order of precedence, prereleases come before their associated releases. In this
order of precedence, pre-releases come before their associated releases. In this
example `1.2.3-beta.1 < 1.2.3`.

According to the Semantic Version specification prereleases may not be
According to the Semantic Version specification, pre-releases may not be
API compliant with their release counterpart. It says,

> A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version.
SemVer comparisons using constraints without a prerelease comparator will skip
prerelease versions. For example, `>=1.2.3` will skip prereleases when looking
at a list of releases while `>=1.2.3-0` will evaluate and find prereleases.
SemVer's comparisons using constraints without a pre-release comparator will skip
pre-release versions. For example, `>=1.2.3` will skip pre-releases when looking
at a list of releases while `>=1.2.3-0` will evaluate and find pre-releases.

The reason for the `0` as a pre-release version in the example comparison is
because pre-releases can only contain ASCII alphanumerics and hyphens (along with
@@ -171,6 +168,9 @@ These look like:
* `1.2 - 1.4.5` which is equivalent to `>= 1.2 <= 1.4.5`
* `2.3.4 - 4.5` which is equivalent to `>= 2.3.4 <= 4.5`

Note that `1.2-1.4.5` without whitespace is parsed completely differently; it's
parsed as a single constraint `1.2.0` with _prerelease_ `1.4.5`.

### Wildcards In Comparisons

The `x`, `X`, and `*` characters can be used as a wildcard character. This works
2 changes: 1 addition & 1 deletion constraints_test.go
Original file line number Diff line number Diff line change
@@ -805,7 +805,7 @@ func FuzzNewConstraint(f *testing.F) {
f.Add(tc)
}

f.Fuzz(func(t *testing.T, a string) {
f.Fuzz(func(_ *testing.T, a string) {
_, _ = NewConstraint(a)
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/Masterminds/semver/v3

go 1.18
go 1.21
64 changes: 32 additions & 32 deletions version.go
Original file line number Diff line number Diff line change
@@ -83,22 +83,23 @@ func StrictNewVersion(v string) (*Version, error) {
original: v,
}

// check for prerelease or build metadata
var extra []string
if strings.ContainsAny(parts[2], "-+") {
// Start with the build metadata first as it needs to be on the right
extra = strings.SplitN(parts[2], "+", 2)
if len(extra) > 1 {
// build metadata found
sv.metadata = extra[1]
parts[2] = extra[0]
// Extract build metadata
if strings.Contains(parts[2], "+") {
extra := strings.SplitN(parts[2], "+", 2)
sv.metadata = extra[1]
parts[2] = extra[0]
if err := validateMetadata(sv.metadata); err != nil {
return nil, err
}
}

extra = strings.SplitN(parts[2], "-", 2)
if len(extra) > 1 {
// prerelease found
sv.pre = extra[1]
parts[2] = extra[0]
// Extract build prerelease
if strings.Contains(parts[2], "-") {
extra := strings.SplitN(parts[2], "-", 2)
sv.pre = extra[1]
parts[2] = extra[0]
if err := validatePrerelease(sv.pre); err != nil {
return nil, err
}
}

@@ -114,7 +115,7 @@ func StrictNewVersion(v string) (*Version, error) {
}
}

// Extract the major, minor, and patch elements onto the returned Version
// Extract major, minor, and patch
var err error
sv.major, err = strconv.ParseUint(parts[0], 10, 64)
if err != nil {
@@ -131,23 +132,6 @@ func StrictNewVersion(v string) (*Version, error) {
return nil, err
}

// No prerelease or build metadata found so returning now as a fastpath.
if sv.pre == "" && sv.metadata == "" {
return sv, nil
}

if sv.pre != "" {
if err = validatePrerelease(sv.pre); err != nil {
return nil, err
}
}

if sv.metadata != "" {
if err = validateMetadata(sv.metadata); err != nil {
return nil, err
}
}

return sv, nil
}

@@ -381,15 +365,31 @@ func (v *Version) LessThan(o *Version) bool {
return v.Compare(o) < 0
}

// LessThanEqual tests if one version is less or equal than another one.
func (v *Version) LessThanEqual(o *Version) bool {
return v.Compare(o) <= 0
}

// GreaterThan tests if one version is greater than another one.
func (v *Version) GreaterThan(o *Version) bool {
return v.Compare(o) > 0
}

// GreaterThanEqual tests if one version is greater or equal than another one.
func (v *Version) GreaterThanEqual(o *Version) bool {
return v.Compare(o) >= 0
}

// Equal tests if two versions are equal to each other.
// Note, versions can be equal with different metadata since metadata
// is not considered part of the comparable version.
func (v *Version) Equal(o *Version) bool {
if v == o {
return true
}
if v == nil || o == nil {
return false
}
return v.Compare(o) == 0
}

Loading