Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable OS Updates to pre-release versions of higher base semver #34

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ export class HUPActionHelper {
throw new HUPActionError('Invalid target balenaOS version');
}

if (
currentVersionParsed.prerelease.length > 0 ||
targetVersionParsed.prerelease.length > 0
) {
throw new HUPActionError(
'Updates cannot be performed on pre-release balenaOS versions',
);
}

const currentVariant = getVariant(currentVersionParsed);
const targetVariant = getVariant(targetVersionParsed);
if (
Expand Down
65 changes: 54 additions & 11 deletions tests/01-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,51 @@ describe('BalenaHupActionUtils', () => {
).to.equal('balenahup');
});

it('Should not allow pre-release versions', () => {
expect(() =>
it('Should allow upgrades from a finalized to a pre-release version', () => {
expect(
hupActionHelper.getHUPActionType(
'raspberry-pi',
'2.9.6-rc1.rev1',
'2.9.6+rev2.prod',
'2.29.2-1234+rev1',
),
).to.equal('balenahup');
});

it('Should allow upgrades from a pre-release to a finalized version', () => {
expect(
hupActionHelper.getHUPActionType(
'raspberry-pi',
'2.9.6-1234+rev1',
'2.29.2+rev1.prod',
),
).to.throw(
'Updates cannot be performed on pre-release balenaOS versions',
);
).to.equal('balenahup');
});

it('Should allow upgrades from a pre-release to a newer pre-release version', () => {
expect(
hupActionHelper.getHUPActionType(
'raspberry-pi',
'2.29.2-1234+rev1',
'2.29.2-1234+rev2',
),
).to.equal('balenahup');
expect(
hupActionHelper.getHUPActionType(
'raspberry-pi',
'2.29.2-1234+rev1',
'2.29.3-1234+rev1',
),
).to.equal('balenahup');
});

it('Should not allow upgrades from a finalized to a pre-release version of the same base semver', () => {
expect(() =>
hupActionHelper.getHUPActionType(
'raspberry-pi',
'2.9.6+rev2.prod',
'2.29.2-rc1.rev1',
'2.29.2+rev1',
'2.29.2-1234+rev2',
),
).to.throw(
'Updates cannot be performed on pre-release balenaOS versions',
);
).to.throw('OS downgrades are not allowed');
});

it('Should not allow downgrades', () => {
Expand All @@ -127,6 +153,23 @@ describe('BalenaHupActionUtils', () => {
).to.throw('OS downgrades are not allowed');
});

it('Should not allow downgrades between pre-release versions', () => {
expect(() =>
hupActionHelper.getHUPActionType(
'raspberry-pi',
'2.29.2-1234+rev1.prod',
'2.9.6-1234+rev2.prod',
),
).to.throw('OS downgrades are not allowed');
expect(() =>
hupActionHelper.getHUPActionType(
'raspberry-pi',
'2.29.2-1234+rev2.prod',
'2.29.2-1234+rev1.prod',
),
).to.throw('OS downgrades are not allowed');
});

it('Should error when the versions are the same', () => {
expect(() =>
hupActionHelper.getHUPActionType(
Expand Down
57 changes: 52 additions & 5 deletions tests/02-validations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,49 @@ describe('BalenaHupActionUtils', () => {
).to.equal(false);
});

it('Should not allow pre-release versions', () => {
it('Should allow upgrades from a finalized to a pre-release version', () => {
expect(
hupActionHelper.isSupportedOsUpdate(
'raspberry-pi',
'2.9.6-rc1.rev1',
'2.9.6+rev2.prod',
'2.29.2-1234+rev1',
),
).to.equal(true);
});

it('Should allow upgrades from a pre-release to a finalized version', () => {
expect(
hupActionHelper.isSupportedOsUpdate(
'raspberry-pi',
'2.9.6-1234+rev1',
'2.29.2+rev1.prod',
),
).to.equal(false);
).to.equal(true);
});

it('Should allow upgrades from a pre-release to a newer pre-release version', () => {
expect(
hupActionHelper.isSupportedOsUpdate(
'raspberry-pi',
'2.9.6+rev2.prod',
'2.29.2-rc1.rev1',
'2.29.2-1234+rev1',
'2.29.2-1234+rev2',
),
).to.equal(true);
expect(
hupActionHelper.isSupportedOsUpdate(
'raspberry-pi',
'2.29.2-1234+rev1',
'2.29.3-1234+rev1',
),
).to.equal(true);
});

it('Should not allow upgrades from a finalized to a pre-release version of the same base semver', () => {
expect(
hupActionHelper.isSupportedOsUpdate(
'raspberry-pi',
'2.29.2+rev1',
'2.29.2-1234+rev2',
),
).to.equal(false);
});
Expand All @@ -76,6 +106,23 @@ describe('BalenaHupActionUtils', () => {
).to.equal(false);
});

it('Should not allow downgrades between pre-release versions', () => {
expect(
hupActionHelper.isSupportedOsUpdate(
'raspberry-pi',
'2.29.2-1234+rev1.prod',
'2.9.6-1234+rev2.prod',
),
).to.equal(false);
expect(
hupActionHelper.isSupportedOsUpdate(
'raspberry-pi',
'2.29.2-1234+rev2.prod',
'2.29.2-1234+rev1.prod',
),
).to.equal(false);
});

it('Should return false when the versions are the same', () => {
expect(
hupActionHelper.isSupportedOsUpdate(
Expand Down
Loading