From 5c40c8d51f16db9f9e28e4286f4c2c277a993f37 Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Thu, 9 Dec 2021 17:34:52 +0000 Subject: [PATCH] os download: Assume '.prod' suffix by default for all balenaOS versions Resolves: #2387 Change-type: patch --- lib/utils/cloud.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/utils/cloud.ts b/lib/utils/cloud.ts index 3e29d158..a0b01a12 100644 --- a/lib/utils/cloud.ts +++ b/lib/utils/cloud.ts @@ -199,14 +199,27 @@ async function resolveOSVersion( deviceType: string, version: string, ): Promise { - if (!['menu', 'menu-esr'].includes(version)) { - if (version[0] === 'v') { - version = version.slice(1); - } - return version; + if (['menu', 'menu-esr'].includes(version)) { + return await selectOSVersionFromMenu(deviceType, version === 'menu-esr'); } + if (version[0] === 'v') { + version = version.slice(1); + } + // The version must end with either '.dev' or '.prod', as expected + // by `balena-image-manager` and the balena SDK. Note that something + // like '2.88.4.prod' is not valid semver (https://semver.org/), + // so we don't even attempt semver parsing here. + if (!version.endsWith('.dev') && !version.endsWith('.prod')) { + version += '.prod'; + } + return version; +} - const vs = await getFormattedOsVersions(deviceType, version === 'menu-esr'); +async function selectOSVersionFromMenu( + deviceType: string, + esr: boolean, +): Promise { + const vs = await getFormattedOsVersions(deviceType, esr); const choices = vs.map((v) => ({ value: v.rawVersion,