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

fix: handle General/Complex Versioning in --bump #2889

Merged
merged 6 commits into from
Nov 29, 2024
Merged

Conversation

liskin
Copy link
Contributor

@liskin liskin commented Nov 1, 2024

fix: handle General/Complex Versioning in --bump

The previous fix to handle non-semver versions in --bump used a crude heuristic - a check whether there's a "." in the version string - to decide whether to attempt to chunkify or just fall back to returning the new version unmodified. This, however, resulted in no bump happening (None returned from check_semver_bump) when either of the old/new versions looked like "v1.2.3".

Additionally, versions like "1.2a1" and "1.2a2" were considered the same, because: a) the heuristic failed to recognise they won't be parsed/chunkified correctly, and b) chunkify used nth that silently throws parts of the version away.

I'm proposing to fix this by reimplementing chunkify using the much more generic versions::Mess format, which simply splits the version number into chunks and separators. We then convert it into a simpler format of just chunks (first chunk as is, further chunks with a separator prepended).

This design has an issue: we don't recognise a change in the versioning scheme. A bump from "<commit sha>" to "v1.2.3" will result in just "v1", because the commit sha is parsed as a single chunk. The most obvious case of this, "latest" being parsed as a single chunk, is handled explicitly in the code, as it would just be a mess otherwise.

A potential workaround for this issue would be to add a flag (e.g. --pin) that would make --bump skip the check_semver_bump logic and always use the full new version (as suggested in #2704 (comment)). This would also help in the following case: a project using variable length version numbers instead of the full 3-chunk semver. Trying to follow this sequence of bumps: "20.0", "20.0.1", "20.1" isn't possible with the current logic.

Related: 0b2c2aa ("fix: upgrade --bump with non-semver versions (#2809)")

fix: Allow --bump from 20.0.1 to 20.1

It's weird so we still warn, but returning None from check_semver_bump only makes sense if the versions are deemed to be the same. Otherwise it's just confusion for the user — the UI presents this as an upgrade, proceeds to uninstall the old version, but fails to do the actual bump and no new version is installed.

@liskin
Copy link
Contributor Author

liskin commented Nov 1, 2024

This design has an issue: we don't recognise a change in the versioning scheme. A bump from "<commit sha>" to "v1.2.3" will result in just "v1", because the commit sha is parsed as a single chunk. The most obvious case of this, "latest" being parsed as a single chunk, is handled explicitly in the code, as it would just be a mess otherwise.

The tests caught this, precisely because it now tries to bump dummy from "ref:master" to "2.0" (the new/latest version being "2.0.0").

I suspect that a proper solution would require us to detect whether the two versions follow the same/similar versioning scheme, and don't try to do check_semver_bump if old is something like "ref:4a2d75f…" or "prefix:20". It's not trivial, though, as there's some inconsistency here – the pipx/uv backend doesn't support ref: or rev: at all, for example, it expects to just get the commit sha directly. And also, list_outdated_versions tries to some prefix stripping magic—although maybe that's not necessary now that we handle non-semver versions?

Any ideas?

@jdx
Copy link
Owner

jdx commented Nov 1, 2024

I think right now it probably doesn't work right with ref: or prefix: so we should probably just ignore those in mise up altogether, maybe with a warning, until we have a better solution for them.

check_semver_bump("20.0a1", "20.0a2"),
Some("20.0a2".to_string())
);
std::assert_eq!(check_semver_bump("v20", "v20.0.0"), None);
Copy link
Owner

Choose a reason for hiding this comment

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

are you actually seeing v prefixed versions somewhere? we should be removing that prefix everywhere we can by this point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're in my config so I thought it'd be nice if mise upgrade --bump didn't choke on them. I can remove them manually but it'd be nice if others didn't need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But you've got a point that the test cases don't reflect reality. There might be a "v" in old but not in new.

@liskin
Copy link
Contributor Author

liskin commented Nov 1, 2024

I think right now it probably doesn't work right with ref: or prefix: so we should probably just ignore those in mise up altogether, maybe with a warning, until we have a better solution for them.

Actually, the code already kinda tries to ignore them:

mise/src/toolset/mod.rs

Lines 402 to 420 in 9bedf17

match out.tool_request.clone() {
ToolRequest::Version {
backend,
version: _version,
options,
source,
} => {
out.tool_request = ToolRequest::Version {
backend,
options,
source,
version: out.bump.clone().unwrap(),
};
}
_ => {
warn!("upgrading non-version tool requests");
out.bump = None;
}
}

But it's half-assed — only skips the bump, but still performs the uninstall. And then, as I mentioned earlier in #2704 (comment), the dry-run output doesn't match what's actually going to happen, so the output in the failing test is "Would install dummy@2.0.0" but that's not what would happen in practice, as there'd be no bump.

Oh, what a can of worms. I think I give up for today :-D

@jdx
Copy link
Owner

jdx commented Nov 16, 2024

I did some work around prefix: in #3054

The previous fix to handle non-semver versions in `--bump` used a crude
heuristic - a check whether there's a "." in the version string - to
decide whether to attempt to `chunkify` or just fall back to returning
the new version unmodified. This, however, resulted in no bump happening
(`None` returned from `check_semver_bump`) when either of the old/new
versions looked like "v1.2.3".

Additionally, versions like "1.2a1" and "1.2a2" were considered the
same, because: a) the heuristic failed to recognise they won't be
parsed/chunkified correctly, and b) `chunkify` used `nth` that silently
throws parts of the version away.

I'm proposing to fix this by reimplementing `chunkify` using the much
more generic versions::Mess format, which simply splits the version
number into chunks and separators. We then convert it into a simpler
format of just chunks (first chunk as is, further chunks with a
separator prepended).

This design has an issue: we don't recognise a change in the versioning
scheme. A bump from "<commit sha>" to "v1.2.3" will result in just "v1",
because the commit sha is parsed as a single chunk. The most obvious
case of this, "latest" being parsed as a single chunk, is handled
explicitly in the code, as it would just be a mess otherwise.

A potential workaround for this issue would be to add a flag (e.g.
`--pin`) that would make `--bump` skip the `check_semver_bump` logic and
always use the full new version (as suggested in
jdx#2704 (comment)).
This would also help in the following case: a project using variable
length version numbers instead of the full 3-chunk semver. Trying to
follow this sequence of bumps: "20.0", "20.0.1", "20.1" isn't possible
with the current logic.

Related: 0b2c2aa ("fix: upgrade --bump with non-semver versions (jdx#2809)")
It's weird so we still warn, but returning `None` from
`check_semver_bump` only makes sense if the versions are deemed to be
the same. Otherwise it's just confusion for the user — the UI presents
this as an upgrade, proceeds to uninstall the old version, but fails to
do the actual bump and no new version is installed.
@jdx jdx enabled auto-merge (squash) November 29, 2024 10:31
@jdx jdx merged commit e5efc7f into jdx:main Nov 29, 2024
19 checks passed
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Dec 10, 2024
## [2024.12.2](https://github.com/jdx/mise/compare/v2024.12.1..v2024.12.2) - 2024-12-07

### 🚀 Features

- **(registry)** add zls to registry by [@hverlin](https://github.com/hverlin) in [#3392](jdx/mise#3392)
- Add --json-extended option to mise env by [@hverlin](https://github.com/hverlin) in [#3389](jdx/mise#3389)

### 🐛 Bug Fixes

- **(config)** set config_root for tasks defined in included toml files by [@risu729](https://github.com/risu729) in [#3388](jdx/mise#3388)
- global hooks by [@jdx](https://github.com/jdx) in [#3393](jdx/mise#3393)
- only run watch_file hook when it has changed file by [@jdx](https://github.com/jdx) in [#3394](jdx/mise#3394)
- bug with aliasing core tools by [@jdx](https://github.com/jdx) in [#3395](jdx/mise#3395)
- remove shims directory before activating by [@jdx](https://github.com/jdx) in [#3396](jdx/mise#3396)

### 🚜 Refactor

- use github crate to list zig releases by [@risu729](https://github.com/risu729) in [#3386](jdx/mise#3386)

### 📚 Documentation

- add zig to core tools by [@risu729](https://github.com/risu729) in [#3385](jdx/mise#3385)

### 🔍 Other Changes

- debug log by [@jdx](https://github.com/jdx) in [0075db0](jdx/mise@0075db0)

## [2024.12.1](https://github.com/jdx/mise/compare/v2024.12.0..v2024.12.1) - 2024-12-06

### 🚀 Features

- **(registry)** use aqua for some tools by [@risu729](https://github.com/risu729) in [#3375](jdx/mise#3375)
- allow filtering `mise bin-paths` on tools by [@jdx](https://github.com/jdx) in [#3367](jdx/mise#3367)
- added aws-cli from aqua by [@jdx](https://github.com/jdx) in [#3370](jdx/mise#3370)
- multiple MISE_ENV environments by [@jdx](https://github.com/jdx) in [#3371](jdx/mise#3371)
- add mise-task.json schema by [@hverlin](https://github.com/hverlin) in [#3374](jdx/mise#3374)
- automatically call `hook-env` by [@jdx](https://github.com/jdx) in [#3373](jdx/mise#3373)

### 🐛 Bug Fixes

- **(docs)** correct syntax error in IDE integration examples by [@EricGusmao](https://github.com/EricGusmao) in [#3360](jdx/mise#3360)
- ensure version check message is displayed by [@jdx](https://github.com/jdx) in [#3358](jdx/mise#3358)
- show warning if no precompiled pythons found by [@jdx](https://github.com/jdx) in [#3359](jdx/mise#3359)
- allow compilation not on macOS, Linux, or Windows by [@avysk](https://github.com/avysk) in [#3363](jdx/mise#3363)
- make hook-env compatible with zsh auto_name_dirs by [@jdx](https://github.com/jdx) in [#3366](jdx/mise#3366)
- skip optional env._.file files by [@jdx](https://github.com/jdx) in [#3381](jdx/mise#3381)
- .terraform-version by [@jdx](https://github.com/jdx) in [#3380](jdx/mise#3380)

### 📚 Documentation

- update auto-completion docs by [@hverlin](https://github.com/hverlin) in [#3355](jdx/mise#3355)
- fix `Environment variables passed to tasks` section by [@hverlin](https://github.com/hverlin) in [#3378](jdx/mise#3378)

### 🧪 Testing

- try to fix coverage rate limits by [@jdx](https://github.com/jdx) in [#3384](jdx/mise#3384)

### 🔍 Other Changes

- Update shims.md by [@jdx](https://github.com/jdx) in [2d48109](jdx/mise@2d48109)
- Update hooks.md by [@jdx](https://github.com/jdx) in [2693f94](jdx/mise@2693f94)

### New Contributors

- @avysk made their first contribution in [#3363](jdx/mise#3363)
- @EricGusmao made their first contribution in [#3360](jdx/mise#3360)

## [2024.12.0](https://github.com/jdx/mise/compare/v2024.11.37..v2024.12.0) - 2024-12-04

### 🚀 Features

- **(erlang)** use precompiled binaries for macos by [@jdx](https://github.com/jdx) in [#3353](jdx/mise#3353)
- add upctl by [@scop](https://github.com/scop) in [#3309](jdx/mise#3309)
- Add `json-with-sources` option to settings ls by [@hverlin](https://github.com/hverlin) in [#3307](jdx/mise#3307)
- add ripsecrets to registry.toml by [@boris-smidt-klarrio](https://github.com/boris-smidt-klarrio) in [#3334](jdx/mise#3334)
- Add kyverno-cli by [@boris-smidt-klarrio](https://github.com/boris-smidt-klarrio) in [#3336](jdx/mise#3336)

### 🐛 Bug Fixes

- add exec to `mise g git-pre-commit` by [@jdx](https://github.com/jdx) in [27a3aef](jdx/mise@27a3aef)
- bake gpg keys in by [@jdx](https://github.com/jdx) in [#3318](jdx/mise#3318)
- deprecate `mise local|global` by [@jdx](https://github.com/jdx) in [#3350](jdx/mise#3350)

### 🚜 Refactor

- use aqua for ruff by [@scop](https://github.com/scop) in [#3316](jdx/mise#3316)

### 📚 Documentation

- add terraform recipe to the cookbook by [@AliSajid](https://github.com/AliSajid) in [#3305](jdx/mise#3305)
- fix git examples for cargo backend by [@tmeijn](https://github.com/tmeijn) in [#3335](jdx/mise#3335)

### 🧪 Testing

- remove non-working maven test by [@jdx](https://github.com/jdx) in [5a3ed16](jdx/mise@5a3ed16)
- remove gleam by [@jdx](https://github.com/jdx) in [fdfe20b](jdx/mise@fdfe20b)
- use latest golang in e2e test by [@jdx](https://github.com/jdx) in [#3349](jdx/mise#3349)

### 🔍 Other Changes

- Update tips-and-tricks.md by [@jdx](https://github.com/jdx) in [5071419](jdx/mise@5071419)
- Update tips-and-tricks.md by [@jdx](https://github.com/jdx) in [fcc6b59](jdx/mise@fcc6b59)
- Update tips-and-tricks.md by [@jdx](https://github.com/jdx) in [039b19d](jdx/mise@039b19d)
- Update configuration.md by [@jdx](https://github.com/jdx) in [b0cac9e](jdx/mise@b0cac9e)
- Update tips-and-tricks.md by [@jdx](https://github.com/jdx) in [9347be8](jdx/mise@9347be8)
- Update tips-and-tricks.md by [@jdx](https://github.com/jdx) in [1cfc822](jdx/mise@1cfc822)
- Update registry.toml by [@jdx](https://github.com/jdx) in [5a28860](jdx/mise@5a28860)
- upgrade usage-lib by [@jdx](https://github.com/jdx) in [554d533](jdx/mise@554d533)
- add rust to core tools list by [@gurgelio](https://github.com/gurgelio) in [#3341](jdx/mise#3341)
- use asdf:mise-plugins/mise-nim by [@jdx](https://github.com/jdx) in [#3352](jdx/mise#3352)

### New Contributors

- @gurgelio made their first contribution in [#3341](jdx/mise#3341)
- @tmeijn made their first contribution in [#3335](jdx/mise#3335)
- @boris-smidt-klarrio made their first contribution in [#3336](jdx/mise#3336)
- @AliSajid made their first contribution in [#3305](jdx/mise#3305)

## [2024.11.37](https://github.com/jdx/mise/compare/v2024.11.36..v2024.11.37) - 2024-11-30

### 🚀 Features

- add black by [@scop](https://github.com/scop) in [#3292](jdx/mise#3292)
- migrate more tools away from asdf by [@jdx](https://github.com/jdx) in [40f92c6](jdx/mise@40f92c6)

### 🐛 Bug Fixes

- handle General/Complex Versioning in --bump by [@liskin](https://github.com/liskin) in [#2889](jdx/mise#2889)
- broken path example by [@minddust](https://github.com/minddust) in [#3296](jdx/mise#3296)
- swift path on macos by [@jdx](https://github.com/jdx) in [#3299](jdx/mise#3299)
- do not auto-install on `mise x` if some tools are passed by [@jdx](https://github.com/jdx) in [35d31a1](jdx/mise@35d31a1)
- fix: also make certain we are not auto installing inside shims by checking by [@jdx](https://github.com/jdx) in [b0c4a74](jdx/mise@b0c4a74)
- cache github release information for 24 hours by [@jdx](https://github.com/jdx) in [#3300](jdx/mise#3300)

### 🚜 Refactor

- use aqua for snyk by [@scop](https://github.com/scop) in [#3290](jdx/mise#3290)

### 🔍 Other Changes

- Revert "fix: always prefer glibc to musl in mise run " by [@jdx](https://github.com/jdx) in [#3298](jdx/mise#3298)
- bump expr-lang by [@jdx](https://github.com/jdx) in [#3297](jdx/mise#3297)
- mise up --bump by [@jdx](https://github.com/jdx) in [6872b54](jdx/mise@6872b54)
- update mise.lock by [@jdx](https://github.com/jdx) in [4c12502](jdx/mise@4c12502)
- disable tool tests until I can sort out gh rate limit issues by [@jdx](https://github.com/jdx) in [f42f010](jdx/mise@f42f010)

### New Contributors

- @minddust made their first contribution in [#3296](jdx/mise#3296)

## [2024.11.36](https://github.com/jdx/mise/compare/v2024.11.35..v2024.11.36) - 2024-11-29

### 🔍 Other Changes

- mise i by [@jdx](https://github.com/jdx) in [8150732](jdx/mise@8150732)

## [2024.11.35](https://github.com/jdx/mise/compare/v2024.11.34..v2024.11.35) - 2024-11-29

### 🚀 Features

- migrate more tools away from asdf by [@jdx](https://github.com/jdx) in [#3279](jdx/mise#3279)

### 🐛 Bug Fixes

- remove conflicting MISE_SHELL setting by [@jdx](https://github.com/jdx) in [#3284](jdx/mise#3284)

### 🚜 Refactor

- simplify __MISE_WATCH variable to only contain the most recent timestamp by [@jdx](https://github.com/jdx) in [#3282](jdx/mise#3282)

### 🧪 Testing

- remove unnecessary cargo-binstall test by [@jdx](https://github.com/jdx) in [0a4da7a](jdx/mise@0a4da7a)

### 🔍 Other Changes

- dont require build-windows before unit-windows by [@jdx](https://github.com/jdx) in [c85e2ec](jdx/mise@c85e2ec)
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.

2 participants