Skip to content

Commit

Permalink
fix: Use versioning comparison for release lookup filtering (#30059)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored Jul 7, 2024
1 parent 06349b9 commit 5eacc5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/workers/repository/process/lookup/filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,34 @@ describe('workers/repository/process/lookup/filter', () => {

expect(filteredVersions).toEqual([{ version: '1.2.3-beta' }]);
});

it('ignores version insufficient prefixes', () => {
const releases = [
{ version: '1.0.1' },
{ version: '1.2.0' },
{ version: '2.0.0', isDeprecated: true },
{ version: '2.1.0' },
] satisfies Release[];

const config = partial<FilterConfig>({
ignoreUnstable: true,
ignoreDeprecated: true,
});
const currentVersion = 'v1.0.1';
const latestVersion = 'v2.0.0';

const filteredVersions = filterVersions(
config,
currentVersion,
latestVersion,
releases,
versioning,
);

expect(filteredVersions).toEqual([
{ version: '1.2.0' },
{ version: '2.1.0' },
]);
});
});
});
9 changes: 8 additions & 1 deletion lib/workers/repository/process/lookup/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ export function filterVersions(
versioning.isGreaterThan(r.version, currentVersion),
);

const currentRelease = releases.find((r) => r.version === currentVersion);
const currentRelease = releases.find(
(r) =>
versioning.isValid(r.version) &&
versioning.isVersion(r.version) &&
versioning.isValid(currentVersion) &&
versioning.isVersion(currentVersion) &&
versioning.equals(r.version, currentVersion),
);

// Don't upgrade from non-deprecated to deprecated
if (ignoreDeprecated && currentRelease && !currentRelease.isDeprecated) {
Expand Down

0 comments on commit 5eacc5e

Please sign in to comment.