Skip to content

Commit

Permalink
fix(version-checker): Use latest semantic version (#18085)
Browse files Browse the repository at this point in the history
* fix(version-checker): Use latest semantic version

* elaborate

* more version nums for funsies
  • Loading branch information
neilkakkar authored Oct 19, 2023
1 parent e968091 commit b5c1ed6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
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

0 comments on commit b5c1ed6

Please sign in to comment.