Skip to content

Commit

Permalink
Feature (release-tools): Created a new util exposed as `getNextIntern…
Browse files Browse the repository at this point in the history
…al()` to generate an internal release version, e.g. `0.0.0-internal-20240102.0`.
  • Loading branch information
pomek committed Oct 17, 2024
1 parent c532699 commit 38346c6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/ckeditor5-dev-release-tools/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
getNextPreRelease,
getLastNightly,
getNextNightly,
getNextInternal,
getCurrent,
getLastTagFromGit
} from './utils/versions.js';
Expand Down
32 changes: 26 additions & 6 deletions packages/ckeditor5-dev-release-tools/lib/utils/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,24 @@ export async function getNextPreRelease( releaseIdentifier, cwd = process.cwd()
* @returns {Promise<string>}
*/
export async function getNextNightly( cwd = process.cwd() ) {
const today = new Date();
const year = today.getFullYear().toString();
const month = ( today.getMonth() + 1 ).toString().padStart( 2, '0' );
const day = today.getDate().toString().padStart( 2, '0' );

const nextNightlyReleaseIdentifier = `0.0.0-nightly-${ year }${ month }${ day }`;
const nextNightlyReleaseIdentifier = `0.0.0-nightly-${ getDateIdentifier() }`;

return getNextPreRelease( nextNightlyReleaseIdentifier, cwd );
}

/**
* Returns the next available internal version in the format of "0.0.0-internal-YYYYMMDD.X", where the "YYYYMMDD" is the current date for
* the internal release and the "X" is the sequential number starting from 0.
*
* @param {string} [cwd=process.cwd()]
* @returns {Promise<string>}
*/
export async function getNextInternal( cwd = process.cwd() ) {
const nextInternalReleaseIdentifier = `0.0.0-internal-${ getDateIdentifier() }`;

return getNextPreRelease( nextInternalReleaseIdentifier, cwd );
}

/**
* Returns a name of the last created tag.
*
Expand All @@ -129,6 +137,18 @@ export function getCurrent( cwd = process.cwd() ) {
return getPackageJson( cwd ).version;
}

/**
* @returns {string}
*/
function getDateIdentifier() {
const today = new Date();
const year = today.getFullYear().toString();
const month = ( today.getMonth() + 1 ).toString().padStart( 2, '0' );
const day = today.getDate().toString().padStart( 2, '0' );

return `${ year }${ month }${ day }`;
}

/**
* @typedef {string} ReleaseIdentifier The pre-release identifier without the last dynamic part (the pre-release sequential number).
* It consists of the core base version ("<major>.<minor>.<path>"), a hyphen ("-"), and a pre-release identifier name (e.g. "alpha").
Expand Down
8 changes: 8 additions & 0 deletions packages/ckeditor5-dev-release-tools/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getNextPreRelease,
getLastNightly,
getNextNightly,
getNextInternal,
getCurrent,
getLastTagFromGit
} from '../lib/utils/versions.js';
Expand Down Expand Up @@ -179,6 +180,13 @@ describe( 'dev-release-tools/index', () => {
} );
} );

describe( 'getNextInternal()', () => {
it( 'should be a function', () => {
expect( getNextInternal ).to.be.a( 'function' );
expect( index.getNextInternal ).to.equal( getNextInternal );
} );
} );

describe( 'getLastTagFromGit()', () => {
it( 'should be a function', () => {
expect( getLastTagFromGit ).to.be.a( 'function' );
Expand Down
30 changes: 30 additions & 0 deletions packages/ckeditor5-dev-release-tools/tests/utils/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getLastNightly,
getNextPreRelease,
getNextNightly,
getNextInternal,
getLastTagFromGit,
getCurrent
} from '../../lib/utils/versions.js';
Expand Down Expand Up @@ -355,6 +356,35 @@ describe( 'versions', () => {
} );
} );

describe( 'getNextInternal()', () => {
beforeEach( () => {
vi.mocked( getPackageJson ).mockReturnValue( { name: 'ckeditor5' } );

vi.useFakeTimers();
vi.setSystemTime( new Date( '2023-06-15 12:00:00' ) );
} );

afterEach( () => {
vi.useRealTimers();
} );

it( 'asks for a last internal pre-release version', () => {
vi.mocked( pacote ).packument.mockResolvedValue( {
name: 'ckeditor5',
versions: {
'0.0.0-internal-20230615.0': {},
'37.0.0-alpha.0': {},
'42.0.0': {}
}
} );

return getNextInternal()
.then( result => {
expect( result ).to.equal( '0.0.0-internal-20230615.1' );
} );
} );
} );

describe( 'getLastTagFromGit()', () => {
it( 'returns last tag if exists', () => {
vi.mocked( tools.shExec ).mockReturnValue( 'v1.0.0' );
Expand Down

0 comments on commit 38346c6

Please sign in to comment.