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

Merged
merged 2 commits into from
Feb 11, 2025
Merged

⭐ epoch support in version #5106

merged 2 commits into from
Feb 11, 2025

Conversation

arlimus
Copy link
Member

@arlimus arlimus commented Jan 21, 2025

Add support for epochs in MQL's semver type.

> version("1:1.2.3") < version("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
> version("5:1.2.3").epoch
5

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

You can compare versions with and without epochs as well:

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

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

Copy link
Contributor

github-actions bot commented Jan 21, 2025

Test Results

3 317 tests  +27   3 313 ✅ +27   1m 40s ⏱️ -12s
  385 suites ± 0       4 💤 ± 0 
   29 files   ± 0       0 ❌ ± 0 

Results for commit 1ab8c5c. ± Comparison against base commit be323a1.

This pull request removes 8 and adds 35 tests. Note that renamed tests count towards both.
go.mondoo.com/cnquery/v11/llx ‑ TestRawData_Semver_Result
go.mondoo.com/cnquery/v11/llx ‑ TestSemver_Conversions
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestSemver
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/llx ‑ TestRawData_Version_Result
go.mondoo.com/cnquery/v11/llx ‑ TestVersion_Conversions
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion/deb/rpm_epochs
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion/deb/rpm_epochs/version('1.2.3').epoch
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion/deb/rpm_epochs/version('7:1.2.3').epoch
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion/different_epochs
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion/different_epochs/version('2:1.10')_>=_version('4:1.2.3')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion/different_epochs/version('2:1.2')_<=_version('3:1.0.2')
go.mondoo.com/cnquery/v11/providers/core/resources ‑ TestVersion/different_epochs/version('2:1.2.3')_==_version('1:1.2.3')
…

♻️ This comment has been updated with latest results.

@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.

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]>
The soft part of this deprecation is that we don't show a deprecation
warning anywhere at all. So semver is still technically included, since
we released it in v9.x, but we will deprecate it formally with the next
major release.
@arlimus
Copy link
Member Author

arlimus commented Feb 11, 2025

Planning on 2 follow-ups:

  1. Add type="semver" to version call
  2. Add inRange as outlined above

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @arlimus Great improvement.

@chris-rock chris-rock merged commit d48ae6e into main Feb 11, 2025
17 checks passed
@chris-rock chris-rock deleted the dom/version-epoch branch February 11, 2025 17:10
@github-actions github-actions bot locked and limited conversation to collaborators Feb 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants