-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #974 from ckeditor/ci/3710-release-via-ci
Feature (release-tools): Create a util for extracting an npm tag from the specified version. Feature (release-tools): Add util to check if a given package and its version are available on npm. Internal: Support for releasing the repository for prereleases.
- Loading branch information
Showing
9 changed files
with
217 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/ckeditor5-dev-release-tools/lib/utils/getnpmtagfromversion.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const semver = require( 'semver' ); | ||
|
||
/** | ||
* @param {String} version | ||
* @returns {String} | ||
*/ | ||
module.exports = function getNpmTagFromVersion( version ) { | ||
const [ versionTag ] = semver.prerelease( version ) || [ 'latest' ]; | ||
|
||
return versionTag; | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
const { tools } = require( '@ckeditor/ckeditor5-dev-utils' ); | ||
const semver = require( 'semver' ); | ||
|
||
/** | ||
* This util aims to verify if the given `packageName` can be published with the given `version` on the `npmTag`. | ||
* | ||
* @param {String} packageName | ||
* @param {String} version | ||
* @param {String} npmTag | ||
* @return {Promise.<Boolean>} | ||
*/ | ||
module.exports = async function isVersionPublishableForTag( packageName, version, npmTag ) { | ||
const npmVersion = await tools.shExec( `npm view ${ packageName }@${ npmTag } version --silent`, { async: true, verbosity: 'silent' } ) | ||
.then( value => value.trim() ) | ||
// An `npmTag` does not exist. | ||
.catch( () => null ); | ||
|
||
if ( npmVersion && semver.lte( version, npmVersion ) ) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/ckeditor5-dev-release-tools/tests/utils/getnpmtagfromversion.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const expect = require( 'chai' ).expect; | ||
const sinon = require( 'sinon' ); | ||
const mockery = require( 'mockery' ); | ||
|
||
describe( 'dev-release-tools/getNpmTagFromVersion', () => { | ||
let stub, getNpmTagFromVersion; | ||
|
||
beforeEach( () => { | ||
stub = { | ||
semver: { | ||
prerelease: sinon.stub() | ||
} | ||
}; | ||
|
||
mockery.enable( { | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
} ); | ||
|
||
mockery.registerMock( 'semver', stub.semver ); | ||
|
||
getNpmTagFromVersion = require( '../../lib/utils/getnpmtagfromversion' ); | ||
} ); | ||
|
||
afterEach( () => { | ||
mockery.deregisterAll(); | ||
mockery.disable(); | ||
} ); | ||
|
||
it( 'should return "latest" when processing a X.Y.Z version', () => { | ||
expect( getNpmTagFromVersion( '1.0.0' ) ).to.equal( 'latest' ); | ||
expect( getNpmTagFromVersion( '2.1.0' ) ).to.equal( 'latest' ); | ||
expect( getNpmTagFromVersion( '3.2.1' ) ).to.equal( 'latest' ); | ||
} ); | ||
|
||
it( 'should return "alpha" when processing a X.Y.Z-alpha.X version', () => { | ||
stub.semver.prerelease.returns( [ 'alpha', 0 ] ); | ||
|
||
expect( getNpmTagFromVersion( '1.0.0-alpha.0' ) ).to.equal( 'alpha' ); | ||
expect( getNpmTagFromVersion( '2.1.0-alpha.0' ) ).to.equal( 'alpha' ); | ||
expect( getNpmTagFromVersion( '3.2.1-alpha.0' ) ).to.equal( 'alpha' ); | ||
} ); | ||
} ); |
80 changes: 80 additions & 0 deletions
80
packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const expect = require( 'chai' ).expect; | ||
const sinon = require( 'sinon' ); | ||
const mockery = require( 'mockery' ); | ||
|
||
describe( 'dev-release-tools/isVersionPublishableForTag', () => { | ||
let stub, isVersionPublishableForTag; | ||
|
||
beforeEach( () => { | ||
stub = { | ||
semver: { | ||
lte: sinon.stub() | ||
}, | ||
devUtils: { | ||
tools: { | ||
shExec: sinon.stub() | ||
} | ||
} | ||
}; | ||
|
||
mockery.enable( { | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
} ); | ||
|
||
mockery.registerMock( 'semver', stub.semver ); | ||
mockery.registerMock( '@ckeditor/ckeditor5-dev-utils', stub.devUtils ); | ||
|
||
isVersionPublishableForTag = require( '../../lib/utils/isversionpublishablefortag' ); | ||
} ); | ||
|
||
afterEach( () => { | ||
mockery.deregisterAll(); | ||
mockery.disable(); | ||
} ); | ||
|
||
it( 'should return true if given version is available', async () => { | ||
stub.semver.lte.returns( false ); | ||
stub.devUtils.tools.shExec.resolves( '1.0.0\n' ); | ||
|
||
const result = await isVersionPublishableForTag( 'package-name', '1.0.1', 'latest' ); | ||
|
||
expect( result ).to.equal( true ); | ||
expect( stub.semver.lte.callCount ).to.equal( 1 ); | ||
expect( stub.semver.lte.firstCall.args ).to.deep.equal( [ '1.0.1', '1.0.0' ] ); | ||
expect( stub.devUtils.tools.shExec.callCount ).to.equal( 1 ); | ||
expect( stub.devUtils.tools.shExec.firstCall.firstArg ).to.equal( 'npm view package-name@latest version --silent' ); | ||
} ); | ||
|
||
it( 'should return false if given version is not available', async () => { | ||
stub.semver.lte.returns( true ); | ||
stub.devUtils.tools.shExec.resolves( '1.0.0\n' ); | ||
|
||
const result = await isVersionPublishableForTag( 'package-name', '1.0.0', 'latest' ); | ||
|
||
expect( result ).to.equal( false ); | ||
expect( stub.semver.lte.callCount ).to.equal( 1 ); | ||
expect( stub.semver.lte.firstCall.args ).to.deep.equal( [ '1.0.0', '1.0.0' ] ); | ||
expect( stub.devUtils.tools.shExec.callCount ).to.equal( 1 ); | ||
expect( stub.devUtils.tools.shExec.firstCall.firstArg ).to.equal( 'npm view package-name@latest version --silent' ); | ||
} ); | ||
|
||
it( 'should return true if given npm tag is not published yet', async () => { | ||
stub.devUtils.tools.shExec.rejects( 'E404' ); | ||
|
||
const result = await isVersionPublishableForTag( 'package-name', '1.0.0', 'alpha' ); | ||
|
||
expect( result ).to.equal( true ); | ||
expect( stub.semver.lte.callCount ).to.equal( 0 ); | ||
expect( stub.devUtils.tools.shExec.callCount ).to.equal( 1 ); | ||
expect( stub.devUtils.tools.shExec.firstCall.firstArg ).to.equal( 'npm view package-name@alpha version --silent' ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters