Skip to content

Commit

Permalink
Merge pull request #3938 from mathesar-foundation/3919_semver
Browse files Browse the repository at this point in the history
Use a semver library to parse our version strings on the front end
  • Loading branch information
pavish authored Oct 8, 2024
2 parents 884d417 + b41295b commit 979ecc9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
6 changes: 6 additions & 0 deletions mathesar_ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mathesar_ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dependencies": {
"@fortawesome/free-solid-svg-icons": "^6.2.0",
"@popperjs/core": "^2.11.6",
"compare-versions": "^6.1.1",
"dayjs": "^1.11.5",
"fast-diff": "^1.2.0",
"flatpickr": "^4.6.13",
Expand Down
24 changes: 4 additions & 20 deletions mathesar_ui/src/stores/releases.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compare } from 'compare-versions';
import { getContext, setContext } from 'svelte';

import {
Expand Down Expand Up @@ -31,20 +32,6 @@ function buildRelease(gh: GitHubRelease | undefined): Release | undefined {
};
}

function orderableTag(tagName: string): number | undefined {
try {
const [major, minor, patch] = tagName
.split('.')
.map((s) => parseInt(s, 10));
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) {
return undefined;
}
return major * 1000000 + minor * 1000 + patch;
} catch (e) {
return undefined;
}
}

type UpgradeStatus = 'upgradable' | 'up-to-date';

function getUpgradeStatus(
Expand All @@ -54,12 +41,9 @@ function getUpgradeStatus(
if (current === undefined || latest === undefined) {
return undefined;
}
const currentNum = orderableTag(current.tagName);
const LatestNum = orderableTag(latest.tagName);
if (currentNum && LatestNum && LatestNum > currentNum) {
return 'upgradable';
}
return 'up-to-date';
return compare(latest.tagName, current.tagName, '>')
? 'upgradable'
: 'up-to-date';
}

export class ReleaseData {
Expand Down

0 comments on commit 979ecc9

Please sign in to comment.