1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix beta->latest->beta upgrade loop

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-09-06 13:48:51 -04:00
parent 60c5af7520
commit a2c591f580
6 changed files with 83 additions and 27 deletions

View File

@ -3,22 +3,16 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import appSemanticVersionInjectable from "../../vars/app-semantic-version.injectable";
import type { UpdateChannelId } from "../update-channels";
import currentReleaseIdInjectable from "../../vars/release-channel.injectable";
import { updateChannels } from "../update-channels";
const defaultUpdateChannelInjectable = getInjectable({
id: "default-update-channel",
instantiate: (di) => {
const appSemanticVersion = di.inject(appSemanticVersionInjectable);
const currentReleaseChannel = appSemanticVersion.prerelease[0]?.toString();
const currentReleaseId = di.inject(currentReleaseIdInjectable);
if (currentReleaseChannel in updateChannels) {
return updateChannels[currentReleaseChannel as UpdateChannelId];
}
return updateChannels.latest;
return updateChannels[currentReleaseId ?? "latest"];
},
});

View File

@ -24,7 +24,7 @@ const alphaChannel: UpdateChannel = {
moreStableUpdateChannel: betaChannel,
};
export const updateChannels: Record<UpdateChannelId, UpdateChannel> = {
export const updateChannels = {
latest: latestChannel,
beta: betaChannel,
alpha: alphaChannel,

View File

@ -0,0 +1,26 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { UpdateChannelId } from "../application-update/update-channels";
import appSemanticVersionInjectable from "./app-semantic-version.injectable";
const currentReleaseIdInjectable = getInjectable({
id: "release-channel",
instantiate: (di): UpdateChannelId | undefined => {
const appSemanticVersion = di.inject(appSemanticVersionInjectable);
const currentReleaseChannel = appSemanticVersion.prerelease[0];
switch (currentReleaseChannel) {
case "latest":
case "beta":
case "alpha":
return currentReleaseChannel;
default:
return undefined;
}
},
});
export default currentReleaseIdInjectable;

View File

@ -40,6 +40,36 @@ describe("downgrading version update", () => {
});
[
{
updateChannel: updateChannels.latest,
appVersion: "4.0.0",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.beta,
appVersion: "4.0.0",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.alpha,
appVersion: "4.0.0",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.latest,
appVersion: "4.0.0-latest",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.beta,
appVersion: "4.0.0-latest",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.alpha,
appVersion: "4.0.0-latest",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.latest,
appVersion: "4.0.0-beta",
@ -50,16 +80,21 @@ describe("downgrading version update", () => {
appVersion: "4.0.0-beta",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.beta,
appVersion: "4.0.0-beta.1",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.alpha,
appVersion: "4.0.0-beta",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.latest,
appVersion: "4.0.0-alpha",
downgradeIsAllowed: true,
},
{
updateChannel: updateChannels.beta,
appVersion: "4.0.0-alpha",
downgradeIsAllowed: false,
},
{
updateChannel: updateChannels.alpha,
appVersion: "4.0.0-alpha",

View File

@ -19,10 +19,7 @@ const checkForUpdatesStartingFromChannelInjectable = getInjectable({
id: "check-for-updates-starting-from-channel",
instantiate: (di) => {
const checkForPlatformUpdates = di.inject(
checkForPlatformUpdatesInjectable,
);
const checkForPlatformUpdates = di.inject(checkForPlatformUpdatesInjectable);
const updateCanBeDowngraded = di.inject(updateCanBeDowngradedInjectable);
const _recursiveCheck = async (

View File

@ -5,23 +5,27 @@
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import selectedUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable";
import appVersionInjectable from "../../../common/vars/app-version.injectable";
import { SemVer } from "semver";
import currentReleaseIdInjectable from "../../../common/vars/release-channel.injectable";
const updateCanBeDowngradedInjectable = getInjectable({
id: "update-can-be-downgraded",
instantiate: (di) => {
const selectedUpdateChannel = di.inject(selectedUpdateChannelInjectable);
const appVersion = di.inject(appVersionInjectable);
const releaseChannel = di.inject(currentReleaseIdInjectable);
return computed(() => {
const semVer = new SemVer(appVersion);
if (!releaseChannel) {
return false;
}
return (
semVer.prerelease[0] !==
selectedUpdateChannel.value.get().id
);
const currentSelectedChannel = selectedUpdateChannel.value.get().id;
if (currentSelectedChannel !== "latest") {
return false;
}
return releaseChannel !== "latest";
});
},
});