Cli - can't pass in version as expected

I’m using the resin cli to configure devices with resin device init. When I pass in --version v2.3.0+rev1.prod it works, but when I then try to use --version v2.3.0+rev1.dev it doesn’t work.

It also seems that it could be related to how the cli caches images, as I’ve tried manually downloading the dev and prod versions. It seems that no matter which one I download first the name of the cached image (in ~/.resin/cache// is suffixed with prod. And then I have to delete that image to be able to download either the dev or prod images.

This is what I ran to determine that:

$ resin os download raspberrypi3 --version v2.2.0+rev1.dev -o /tmp/v2.2.0+rev1.dev
Getting device operating system for raspberrypi3
The image was downloaded successfully

$ ls ~/.resin/cache/raspberrypi3-v2.2.0+rev1.prod.img
/Users/pguelpa/.resin/cache/raspberrypi3-v2.2.0+rev1.prod.img

$ resin os download raspberrypi3 --version v2.2.0+rev1.dev -o /tmp/v2.2.0+rev1.dev
Getting device operating system for raspberrypi3
The image was downloaded successfully

This is on resin-cli version 6.6.11.

Hey, I’ve dug into this and it appears to be due to allowing version ranges being allowed in the version specifier (eg ^2.0.0), so what happens is that the version is compared as a semver range to get the max version of the range and due to .dev being part of the build metadata it gets ignored so both ‘2.2.0+rev1.prod’ and ‘2.2.0+rev1.dev’ are matches, but ‘2.2.0+rev1.prod’ takes priority due to being higher in lexicographical order. I’ve filed an issue at https://github.com/resin-io/resin-sdk/issues/422 and I expect @pimterry to get it sorted soon but I wasn’t able to find a workaround for the meantime so I’d recommend tracking that issue and updating as soon as it’s published

Amazing! Thanks so the quick reply as well as making it into a more useful bug report in the relevant repo. That makes it much easier for me to track and update when the fix comes out.

No problem, thanks for bringing attention to it

@pguelpa the SDK bug now has a fix in review, but note that a fix at the SDK level won’t immediately solve it in the CLI, even once that’s released (there’s a little work required to ensure the change propagates up).

If you want to follow the progress on the CLI-facing part of this bug, you can track it here: https://github.com/resin-io/resin-cli/issues/688