diff --git a/lib/index.ts b/lib/index.ts index dff7cdc..41077f2 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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 ( diff --git a/tests/01-actions.spec.ts b/tests/01-actions.spec.ts index b76cf22..0bd7a70 100644 --- a/tests/01-actions.spec.ts +++ b/tests/01-actions.spec.ts @@ -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', () => { @@ -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( diff --git a/tests/02-validations.spec.ts b/tests/02-validations.spec.ts index 41ed334..bf9d986 100644 --- a/tests/02-validations.spec.ts +++ b/tests/02-validations.spec.ts @@ -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); }); @@ -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(