From 38346c679a8cb7ce328a9584a18529110f641325 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 17 Oct 2024 10:17:25 +0200 Subject: [PATCH] Feature (release-tools): Created a new util exposed as `getNextInternal()` to generate an internal release version, e.g. `0.0.0-internal-20240102.0`. --- .../ckeditor5-dev-release-tools/lib/index.js | 1 + .../lib/utils/versions.js | 32 +++++++++++++++---- .../tests/index.js | 8 +++++ .../tests/utils/versions.js | 30 +++++++++++++++++ 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/packages/ckeditor5-dev-release-tools/lib/index.js b/packages/ckeditor5-dev-release-tools/lib/index.js index d547988d8..7ea9bb078 100644 --- a/packages/ckeditor5-dev-release-tools/lib/index.js +++ b/packages/ckeditor5-dev-release-tools/lib/index.js @@ -20,6 +20,7 @@ export { getNextPreRelease, getLastNightly, getNextNightly, + getNextInternal, getCurrent, getLastTagFromGit } from './utils/versions.js'; diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/versions.js b/packages/ckeditor5-dev-release-tools/lib/utils/versions.js index adca5e36c..50ec2c066 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/versions.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/versions.js @@ -93,16 +93,24 @@ export async function getNextPreRelease( releaseIdentifier, cwd = process.cwd() * @returns {Promise} */ 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} + */ +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. * @@ -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 (".."), a hyphen ("-"), and a pre-release identifier name (e.g. "alpha"). diff --git a/packages/ckeditor5-dev-release-tools/tests/index.js b/packages/ckeditor5-dev-release-tools/tests/index.js index dd4bb16b2..95a386969 100644 --- a/packages/ckeditor5-dev-release-tools/tests/index.js +++ b/packages/ckeditor5-dev-release-tools/tests/index.js @@ -24,6 +24,7 @@ import { getNextPreRelease, getLastNightly, getNextNightly, + getNextInternal, getCurrent, getLastTagFromGit } from '../lib/utils/versions.js'; @@ -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' ); diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/versions.js b/packages/ckeditor5-dev-release-tools/tests/utils/versions.js index c774e54a1..2b1d7105e 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/versions.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/versions.js @@ -15,6 +15,7 @@ import { getLastNightly, getNextPreRelease, getNextNightly, + getNextInternal, getLastTagFromGit, getCurrent } from '../../lib/utils/versions.js'; @@ -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' );