From 29c7716168c2a6feb4b9346e1720acbedc2e7ec5 Mon Sep 17 00:00:00 2001 From: mukulmishra18 Date: Thu, 28 Dec 2023 20:59:45 +0530 Subject: [PATCH] Refactor defineVersion to remove prereleaseTag --- .github/scripts/defineVersion.js | 27 +++--------------------- spec/release/defineVersion.spec.ts | 33 +++++++++++++----------------- 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/.github/scripts/defineVersion.js b/.github/scripts/defineVersion.js index c8b486a8c..bd2ea068d 100644 --- a/.github/scripts/defineVersion.js +++ b/.github/scripts/defineVersion.js @@ -1,24 +1,5 @@ const semver = require('semver'); -function determinePreReleaseTag(existingVersion, targetReleaseLevel) { - const existingPreReleaseVersion = semver.prerelease(existingVersion); - if (existingPreReleaseVersion && existingPreReleaseVersion.length > 0) { - return `prerelease`; - } - - return `pre${targetReleaseLevel}`; -} - -function defineNewVersion(targetReleaseLevel, existingVersion, prereleaseTag) { - let releaseTag = targetReleaseLevel; - - if (prereleaseTag) { - releaseTag = determinePreReleaseTag(existingVersion, targetReleaseLevel); - } - - return semver.inc(existingVersion, releaseTag, prereleaseTag, undefined); -} - function getPlayerUiVersion(versionInput) { let targetVersion = versionInput ?? process.env.CI_BRANCH; @@ -42,12 +23,10 @@ function getPlayerUiVersion(versionInput) { }; } -function defineReleaseVersion({ core }, targetReleaseLevel, prereleaseTag, givenVersion) { - core.info( - `Defining new release version for level ${targetReleaseLevel} and prereleaseTag ${prereleaseTag} given the version ${givenVersion}`, - ); +function defineReleaseVersion({ core }, targetReleaseLevel, givenVersion) { + core.info(`Defining new release version for level ${targetReleaseLevel} and version ${givenVersion}`); - const newVersion = defineNewVersion(targetReleaseLevel, givenVersion, prereleaseTag); + const newVersion = semver.inc(givenVersion, targetReleaseLevel); const parsedPlayerVersion = getPlayerUiVersion(newVersion); core.info(`Using release version ${parsedPlayerVersion.full}`); diff --git a/spec/release/defineVersion.spec.ts b/spec/release/defineVersion.spec.ts index 5ca7cd0fd..2ca1fc6aa 100644 --- a/spec/release/defineVersion.spec.ts +++ b/spec/release/defineVersion.spec.ts @@ -2,28 +2,23 @@ const { defineReleaseVersion } = require('../../.github/scripts/defineVersion'); describe('defineReleaseVersion', () => { test.each` - existingVersion | desiredReleaseLevel | preReleaseTag | expectedVersion - ${'1.0.0'} | ${'major'} | ${undefined} | ${'2.0.0'} - ${'1.0.0'} | ${'minor'} | ${undefined} | ${'1.1.0'} - ${'1.1.0'} | ${'minor'} | ${undefined} | ${'1.2.0'} - ${'1.0.0'} | ${'patch'} | ${undefined} | ${'1.0.1'} - ${'1.1.0'} | ${'patch'} | ${undefined} | ${'1.1.1'} - ${'1.0.4'} | ${'patch'} | ${undefined} | ${'1.0.5'} - ${'1.0.0'} | ${'minor'} | ${'rc'} | ${'1.1.0-rc.0'} - ${'1.1.0-rc.0'} | ${'minor'} | ${undefined} | ${'1.1.0'} - ${'1.0.0'} | ${'minor'} | ${'beta'} | ${'1.1.0-beta.0'} - ${'1.1.0-beta.0'} | ${'minor'} | ${'beta'} | ${'1.1.0-beta.1'} - ${'1.1.0-beta.5'} | ${'minor'} | ${'beta'} | ${'1.1.0-beta.6'} - ${'1.0.0'} | ${'major'} | ${'beta'} | ${'2.0.0-beta.0'} - ${'1.5.0'} | ${'major'} | ${'beta'} | ${'2.0.0-beta.0'} - ${'1.5.0'} | ${'major'} | ${'rc'} | ${'2.0.0-rc.0'} - ${'2.0.0-beta.0'} | ${'major'} | ${'rc'} | ${'2.0.0-rc.0'} - ${'2.0.0-rc.1'} | ${'major'} | ${undefined} | ${'2.0.0'} + existingVersion | desiredReleaseLevel | expectedVersion + ${'1.0.0'} | ${'major'} | ${'2.0.0'} + ${'1.0.0'} | ${'minor'} | ${'1.1.0'} + ${'1.1.0'} | ${'minor'} | ${'1.2.0'} + ${'1.0.0'} | ${'patch'} | ${'1.0.1'} + ${'1.1.0'} | ${'patch'} | ${'1.1.1'} + ${'1.0.4'} | ${'patch'} | ${'1.0.5'} + ${'1.0.0'} | ${'minor'} | ${'1.1.0'} + ${'1.0.0'} | ${'minor'} | ${'1.1.0'} + ${'1.0.0'} | ${'major'} | ${'2.0.0'} + ${'1.5.0'} | ${'major'} | ${'2.0.0'} + ${'2.0.0'} | ${'major'} | ${'3.0.0'} `( 'should return version $expectedVersion with version $existingVersion and $desiredReleaseLevel release level', - ({ existingVersion, desiredReleaseLevel, preReleaseTag, expectedVersion }) => { + ({ existingVersion, desiredReleaseLevel, expectedVersion }) => { const core = { info() {} }; - const result = defineReleaseVersion({ core }, desiredReleaseLevel, preReleaseTag, existingVersion); + const result = defineReleaseVersion({ core }, desiredReleaseLevel, existingVersion); expect(result.full).toEqual(expectedVersion); },