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

⭐ epoch support in version #5106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

⭐ epoch support in version #5106

wants to merge 1 commit into from

Conversation

arlimus
Copy link
Member

@arlimus arlimus commented Jan 21, 2025

Add support for epochs in MQL's semver type.

> semver("1:1.2.3") < semver("2:1.0.0")
true

This works for both deb/rpm-style epochs ("NN:version") and python-style epochs (PEP440).

Additionally you can access the epoch:

# deb/rpm-style epoch
> semver("5:1.2.3").epoch
5

# python-style epoch
> semver("3!2.1").epoch
3

You can compare versions with and without epochs as well:

> semver("1:1.0") > semver("2009.12.03")
true

Note: Technically epochs aren't semver, so the name semver is hitting its limit here. We could introduce the version type as a replacement or as a temporary holdover (because we also don't want to clutter the global namespace too much).

Internal note: This required a new wrapper around the version, which can now be extended with more metadata. Currently we have the epoch stored.

Add support for epochs in MQL's `semver` type.

```mql
> semver("1:1.2.3") < semver("2:1.0.0")
true
```

This works for both deb/rpm-style epochs ("NN:version") and python-style
epochs ([PEP440](https://peps.python.org/pep-0440/)).

Additionally you can access the epoch:

```mql
> semver("5:1.2.3").epoch
5

> semver("3!2.1").epoch
3
```

You can compare versions with and without epochs as well:

```mql
> semver("1:1.0") > semver("2009.12.03")
true
```

Note: Technically epochs aren't semver, so the name `semver` is hitting
its limit here. We could introduce the `version` type as a replacement
or as a temporary holdover (because we also don't want to clutter the
global namespace too much).

Internal note: This required a new wrapper around the version, which can
now be extended with more metadata. Currently we have the epoch stored.

Signed-off-by: Dominik Richter <[email protected]>
Copy link
Contributor

Test Results

3 235 tests  +27   3 231 ✅ +27   1m 48s ⏱️ +8s
  379 suites ± 0       4 💤 ± 0 
   29 files   ± 0       0 ❌ ± 0 

Results for commit ef4f6db. ± Comparison against base commit e165637.

This pull request removes 5 and adds 32 tests. Note that renamed tests count towards both.
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/semver('1.10')_>=_'1.2'
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/semver('1.10')_>=_semver('1.2.3')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/semver('1.2')_<_semver('1.10.2')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/semver('1.2.3')_==_semver('1.2')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/semver('1.2.3')_==_semver('1.2.3')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/deb/rpm_epochs
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/deb/rpm_epochs/semver('1.2.3').epoch
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/deb/rpm_epochs/semver('7:1.2.3').epoch
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/different_epochs
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/different_epochs/semver('2:1.10')_>=_semver('4:1.2.3')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/different_epochs/semver('2:1.2')_<=_semver('3:1.0.2')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/different_epochs/semver('2:1.2.3')_==_semver('1:1.2.3')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/different_epochs/semver('2:1.2.3')_==_semver('3:1.2.3')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/different_epochs/semver('3:1.2')_<_semver('1:1.10.2')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver/different_epochs/semver('4:1.1')_>_semver('1:1.2.3')
…

@arlimus
Copy link
Member Author

arlimus commented Jan 22, 2025

Update after discussion with @chris-rock:

> version("1.2.3")

> version("1.2.3", type="semver")

> version("1.2.3").inRange(">=1.0.0", "<2.0.0" )

> version("1.2.3").inRange("1.0.0", "2.0.0")   # ==> >=1.0.0 <=2.0.0

Introduce version as the successor to semver and move to deprecate semver in the next major release.

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.

1 participant