From f8caf158c9344d89d55660801acd85225c82eece Mon Sep 17 00:00:00 2001 From: Yevhen Polyanichko Date: Wed, 10 Feb 2021 17:06:38 +0200 Subject: [PATCH] Fix helm version extraction Helm (as of 3.5) doesn't print 'Client: v' in helm version output. Use RegExp to match helm version which is more reliable and make sure to throw an error if version is wrong or there is a parsing error. --- lib/helm.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/helm.js b/lib/helm.js index bfd6eab..186f455 100644 --- a/lib/helm.js +++ b/lib/helm.js @@ -69,10 +69,16 @@ module.exports = function Helm(exec) { 3: 'helm template --namespace default release-name .' }; - const helmVersion = exec.commandSync('helm version --client --short').stdout - let version = 2 - if (helmVersion && helmVersion.startsWith('Client: v')) { - version = parseInt(helmVersion.replace('Client: v', '')[0]) + let version = -1; + + const helmVersion = exec.commandSync('helm version --client --short').stdout; + const helmVersionRegExp = new RegExp('v(?[0-9])+\.[0-9]+\.[0-9]+'); + const helmVersionRegExpMatches = helmVersion ? helmVersion.match(helmVersionRegExp) : null; + + if (helmVersionRegExpMatches) { + version = parseInt(helmVersionRegExpMatches.groups.major); + } else { + throw new Error(`Cannot parse helm version: ${helmVersion}`); } if (version !== 2 && version !== 3) {