mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-29 21:31:02 +00:00
use semver for version comparsion (#3042)
close #3041 close #3043 --------- Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
parent
9c066c237a
commit
38cf248e41
3 changed files with 14 additions and 3 deletions
|
@ -27,6 +27,7 @@
|
||||||
"node-emoji": "^2.0.0",
|
"node-emoji": "^2.0.0",
|
||||||
"pinia": "^2.1.4",
|
"pinia": "^2.1.4",
|
||||||
"prismjs": "^1.29.0",
|
"prismjs": "^1.29.0",
|
||||||
|
"semver": "^7.5.4",
|
||||||
"vue": "^3.3.4",
|
"vue": "^3.3.4",
|
||||||
"vue-i18n": "^9.2.2",
|
"vue-i18n": "^9.2.2",
|
||||||
"vue-router": "^4.2.2"
|
"vue-router": "^4.2.2"
|
||||||
|
@ -37,6 +38,7 @@
|
||||||
"@types/node": "^20.0.0",
|
"@types/node": "^20.0.0",
|
||||||
"@types/node-emoji": "^1.8.2",
|
"@types/node-emoji": "^1.8.2",
|
||||||
"@types/prismjs": "^1.26.0",
|
"@types/prismjs": "^1.26.0",
|
||||||
|
"@types/semver": "^7.5.6",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
||||||
"@typescript-eslint/parser": "^6.8.0",
|
"@typescript-eslint/parser": "^6.8.0",
|
||||||
"@vitejs/plugin-vue": "^5.0.0",
|
"@vitejs/plugin-vue": "^5.0.0",
|
||||||
|
|
|
@ -38,6 +38,9 @@ dependencies:
|
||||||
prismjs:
|
prismjs:
|
||||||
specifier: ^1.29.0
|
specifier: ^1.29.0
|
||||||
version: 1.29.0
|
version: 1.29.0
|
||||||
|
semver:
|
||||||
|
specifier: ^7.5.4
|
||||||
|
version: 7.5.4
|
||||||
vue:
|
vue:
|
||||||
specifier: ^3.3.4
|
specifier: ^3.3.4
|
||||||
version: 3.3.10(typescript@5.3.3)
|
version: 3.3.10(typescript@5.3.3)
|
||||||
|
@ -64,6 +67,9 @@ devDependencies:
|
||||||
'@types/prismjs':
|
'@types/prismjs':
|
||||||
specifier: ^1.26.0
|
specifier: ^1.26.0
|
||||||
version: 1.26.3
|
version: 1.26.3
|
||||||
|
'@types/semver':
|
||||||
|
specifier: ^7.5.6
|
||||||
|
version: 7.5.6
|
||||||
'@typescript-eslint/eslint-plugin':
|
'@typescript-eslint/eslint-plugin':
|
||||||
specifier: ^6.8.0
|
specifier: ^6.8.0
|
||||||
version: 6.13.2(@typescript-eslint/parser@6.13.2)(eslint@8.55.0)(typescript@5.3.3)
|
version: 6.13.2(@typescript-eslint/parser@6.13.2)(eslint@8.55.0)(typescript@5.3.3)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import semverCoerce from 'semver/functions/coerce';
|
||||||
|
import semverGt from 'semver/functions/gt';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import useAuthentication from './useAuthentication';
|
import useAuthentication from './useAuthentication';
|
||||||
|
@ -39,6 +41,7 @@ export function useVersion() {
|
||||||
|
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
const current = config.version as string;
|
const current = config.version as string;
|
||||||
|
const currentSemver = semverCoerce(current);
|
||||||
const usesNext = current.startsWith('next');
|
const usesNext = current.startsWith('next');
|
||||||
|
|
||||||
const { user } = useAuthentication();
|
const { user } = useAuthentication();
|
||||||
|
@ -72,9 +75,9 @@ export function useVersion() {
|
||||||
if (usesNext) {
|
if (usesNext) {
|
||||||
latest = versionInfo.next;
|
latest = versionInfo.next;
|
||||||
} else if (current.includes('rc')) {
|
} else if (current.includes('rc')) {
|
||||||
latest = versionInfo.rc.replace(/^v/, '');
|
latest = versionInfo.rc;
|
||||||
} else {
|
} else {
|
||||||
latest = versionInfo.latest.replace(/^v/, '');
|
latest = versionInfo.latest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +85,7 @@ export function useVersion() {
|
||||||
latest,
|
latest,
|
||||||
current,
|
current,
|
||||||
currentShort: usesNext ? 'next' : current,
|
currentShort: usesNext ? 'next' : current,
|
||||||
needsUpdate: latest !== undefined && latest !== current,
|
needsUpdate: latest !== undefined && currentSemver !== null && semverGt(latest, currentSemver),
|
||||||
usesNext,
|
usesNext,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue