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 (#6189)

This commit is contained in:
Sebastian Malton 2022-09-15 08:02:14 -04:00 committed by GitHub
parent b428518857
commit a784ca70b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 39 deletions

View File

@ -3,23 +3,12 @@
* 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 releaseChannelInjectable 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();
if (currentReleaseChannel in updateChannels) {
return updateChannels[currentReleaseChannel as UpdateChannelId];
}
return updateChannels.latest;
},
instantiate: (di) => updateChannels[di.inject(releaseChannelInjectable)],
});
export default defaultUpdateChannelInjectable;

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 releaseChannelInjectable = getInjectable({
id: "release-channel",
instantiate: (di): UpdateChannelId => {
const appSemanticVersion = di.inject(appSemanticVersionInjectable);
const currentReleaseChannel = appSemanticVersion.prerelease[0];
switch (currentReleaseChannel) {
case "latest":
case "beta":
case "alpha":
return currentReleaseChannel;
default:
return "latest";
}
},
});
export default releaseChannelInjectable;

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

@ -91,7 +91,7 @@ describe("installing update", () => {
it("checks for updates", () => {
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
expect.any(Object),
{ allowDowngrade: true },
{ allowDowngrade: false },
);
});

View File

@ -105,7 +105,7 @@ describe("selection of update stability", () => {
it('checks updates from update channel "alpha"', () => {
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
updateChannels.alpha,
{ allowDowngrade: true },
{ allowDowngrade: false },
);
});
@ -132,7 +132,7 @@ describe("selection of update stability", () => {
it('checks updates from update channel "beta"', () => {
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
updateChannels.beta,
{ allowDowngrade: true },
{ allowDowngrade: false },
);
});
@ -159,7 +159,7 @@ describe("selection of update stability", () => {
it('finally checks updates from update channel "latest"', () => {
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
updateChannels.latest,
{ allowDowngrade: true },
{ allowDowngrade: false },
);
});
@ -279,7 +279,7 @@ describe("selection of update stability", () => {
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
updateChannels.latest,
{ allowDowngrade: true },
{ allowDowngrade: false },
);
});

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,24 +5,19 @@
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 releaseChannelInjectable 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(releaseChannelInjectable);
return computed(() => {
const semVer = new SemVer(appVersion);
return (
semVer.prerelease[0] !==
selectedUpdateChannel.value.get().id
);
});
return computed(() => (
selectedUpdateChannel.value.get().id === "latest"
&& releaseChannel !== "latest"
));
},
});