Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(version-checker): Use latest semantic version #18085

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,46 @@ describe('versionCheckerLogic', () => {
await expectLogic(logic).toFinishAllListeners()
expectLogic(logic).toMatchValues({ versionWarning: options.expectation })
})

it.each([
{
usedVersions: [
{ version: '1.9.0', timestamp: '2023-01-01T12:00:00Z' },
{ version: '1.83.1', timestamp: '2023-01-01T10:00:00Z' },
],
expectation: {
currentVersion: '1.83.1',
latestVersion: '1.84.0',
diff: 1,
level: 'info',
},
},
{
usedVersions: [
{ version: '1.80.0', timestamp: '2023-01-01T12:00:00Z' },
{ version: '1.83.1', timestamp: '2023-01-01T10:00:00Z' },
{ version: '1.20.1', timestamp: '2023-01-01T10:00:00Z' },
{ version: '1.0.890', timestamp: '2023-01-01T10:00:00Z' },
{ version: '0.89.5', timestamp: '2023-01-01T10:00:00Z' },
{ version: '0.0.5', timestamp: '2023-01-01T10:00:00Z' },
{ version: '1.84.0', timestamp: '2023-01-01T08:00:00Z' },
],
expectation: null,
},
{
usedVersions: [
{ version: '1.80.0', timestamp: '2023-01-01T12:00:00Z' },
{ version: '1.83.1-beta', timestamp: '2023-01-01T10:00:00Z' },
{ version: '1.84.0-delta', timestamp: '2023-01-01T08:00:00Z' },
],
expectation: { currentVersion: '1.84.0-delta', diff: 1, latestVersion: '1.84.0', level: 'info' },
},
])('when having multiple versions used, should match with the latest one', async (options) => {
useMockedVersions([{ version: '1.84.0' }], options.usedVersions)

logic.mount()

await expectLogic(logic).toFinishAllListeners()
expectLogic(logic).toMatchValues({ versionWarning: options.expectation })
})
})
14 changes: 10 additions & 4 deletions frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,24 @@ export const versionCheckerLogic = kea<versionCheckerLogicType>([
}

const latestVersion = values.availableVersions[0].version
const currentVersion = values.usedVersions[0].version

if (latestVersion === currentVersion) {
// reverse sort, hence reversed arguments to localeCompare.
// We want the highest semantic version to be the latest used one, rather than
// the one with the latest timestamp, because secondary installations can spew old versions
const latestUsedVersion = [...values.usedVersions].sort((a, b) =>
b.version.localeCompare(a.version, undefined, { numeric: true })
)[0].version

if (latestVersion === latestUsedVersion) {
actions.setVersionWarning(null)
return
}

let diff = values.availableVersions.findIndex((v) => v.version === currentVersion)
let diff = values.availableVersions.findIndex((v) => v.version === latestUsedVersion)
diff = diff === -1 ? values.availableVersions.length : diff

const warning: SDKVersionWarning = {
currentVersion,
currentVersion: latestUsedVersion,
latestVersion,
diff,
level: diff > 20 ? 'error' : diff > 10 ? 'warning' : 'info',
Expand Down
Loading