From e987069a3aa392183c64a4ff8c4845d124762239 Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Sun, 26 Jun 2022 13:31:52 +0300
Subject: [PATCH] fix(helm): Use `semver-coerced` for determining latest
 release (#16229)

---
 lib/modules/datasource/helm/index.ts | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/modules/datasource/helm/index.ts b/lib/modules/datasource/helm/index.ts
index 2d719d5ebd..81372fe73b 100644
--- a/lib/modules/datasource/helm/index.ts
+++ b/lib/modules/datasource/helm/index.ts
@@ -1,6 +1,5 @@
 import is from '@sindresorhus/is';
 import { load } from 'js-yaml';
-import { gt } from 'semver';
 import { logger } from '../../../logger';
 import { cache } from '../../../util/cache/package/decorator';
 import { ensureTrailingSlash } from '../../../util/url';
@@ -63,9 +62,17 @@ export class HelmDatasource extends Datasource {
       }
       const result: HelmRepositoryData = {};
       for (const [name, releases] of Object.entries(doc.entries)) {
-        const latestRelease = releases.sort((r0, r1) =>
-          gt(r0.version, r1.version) ? -1 : 1
-        )[0];
+        let latestRelease = releases[releases.length - 1];
+        const sortedReleases = releases
+          .filter(({ version }) => helmVersioning.api.isValid(version))
+          .sort((r0, r1) =>
+            helmVersioning.api.sortVersions(r0.version, r1.version)
+          );
+        const latestSortedRelease = sortedReleases[sortedReleases.length - 1];
+        if (latestSortedRelease) {
+          latestRelease = latestSortedRelease;
+        }
+
         const { sourceUrl, sourceDirectory } = findSourceUrl(latestRelease);
         result[name] = {
           homepage: latestRelease.home,
-- 
GitLab