Skip to content

Commit

Permalink
Refactor defineVersion to remove prereleaseTag
Browse files Browse the repository at this point in the history
  • Loading branch information
mukulmishra18 committed Dec 28, 2023
1 parent ef2b9b5 commit 29c7716
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
27 changes: 3 additions & 24 deletions .github/scripts/defineVersion.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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}`);
Expand Down
33 changes: 14 additions & 19 deletions spec/release/defineVersion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down

0 comments on commit 29c7716

Please sign in to comment.