-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new task to verify if package was published correctly to npm. #965
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8dfa0bc
Added new task to verify if package was published correctly to npm.
martnpaneq a50f594
Added tests for `verifyPackagesPublishedCorrectly`.
martnpaneq 889dd43
Addressed PR comments.
martnpaneq c6c8449
Removed unused mock `chalk`.
martnpaneq cd65e99
Fixed eslint.
martnpaneq 8a7f479
Addressed PR comments.
martnpaneq 5c1f640
Fixed eslint.
martnpaneq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 50 additions & 0 deletions
50
packages/ckeditor5-dev-release-tools/lib/tasks/verifypackagespublishedcorrectly.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,50 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const upath = require( 'upath' ); | ||
const { glob } = require( 'glob' ); | ||
const fs = require( 'fs-extra' ); | ||
const { checkVersionAvailability } = require( '../utils/checkversionavailability' ); | ||
|
||
/** | ||
* Npm sometimes throws incorrect error 409 while publishing, while the package uploads correctly. | ||
* The purpose of the script is to validate if packages that threw 409 are uploaded correctly to npm. | ||
* | ||
* @param {Object} options | ||
* @param {String} options.packagesDirectory Relative path to a location of packages to release. | ||
* @param {String} options.version Version of the current release. | ||
* @param {Function} options.onSuccess Callback fired when function is successful. | ||
* @returns {Promise} | ||
*/ | ||
module.exports = async function verifyPackagesPublishedCorrectly( options ) { | ||
const { packagesDirectory, version, onSuccess } = options; | ||
const packagesToVerify = await glob( upath.join( packagesDirectory, '*' ), { absolute: true } ); | ||
const errors = []; | ||
|
||
if ( !packagesToVerify.length ) { | ||
onSuccess( '✅ No packages found to check for upload error 409.' ); | ||
|
||
return; | ||
} | ||
|
||
for ( const packageToVerify of packagesToVerify ) { | ||
const packageJson = await fs.readJson( upath.join( packageToVerify, 'package.json' ) ); | ||
|
||
try { | ||
await checkVersionAvailability( version, packageJson.name ); | ||
await fs.remove( packageToVerify ); | ||
} catch { | ||
errors.push( packageJson.name ); | ||
} | ||
} | ||
|
||
if ( errors.length ) { | ||
throw new Error( 'Packages that were uploaded incorrectly, and need manual verification:\n' + errors.join( '\n' ) ); | ||
} | ||
|
||
onSuccess( '✅ All packages that returned 409 were uploaded correctly.' ); | ||
}; |
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
116 changes: 116 additions & 0 deletions
116
packages/ckeditor5-dev-release-tools/tests/tasks/verifypackagespublishedcorrectly.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,116 @@ | ||
/** | ||
* @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/utils', () => { | ||
describe( 'verifyPackagesPublishedCorrectly()', () => { | ||
let verifyPackagesPublishedCorrectly, sandbox, stubs; | ||
|
||
beforeEach( () => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
stubs = { | ||
fs: { | ||
remove: sandbox.stub().resolves(), | ||
readJson: sandbox.stub().resolves() | ||
}, | ||
devUtils: { | ||
checkVersionAvailability: sandbox.stub().resolves() | ||
}, | ||
glob: { | ||
glob: sandbox.stub().resolves( [] ) | ||
} | ||
}; | ||
|
||
mockery.enable( { | ||
useCleanCache: true, | ||
warnOnReplace: false, | ||
warnOnUnregistered: false | ||
} ); | ||
|
||
mockery.registerMock( 'fs-extra', stubs.fs ); | ||
mockery.registerMock( '../utils/checkversionavailability', stubs.devUtils ); | ||
mockery.registerMock( 'glob', stubs.glob ); | ||
|
||
verifyPackagesPublishedCorrectly = require( '../../lib/tasks/verifypackagespublishedcorrectly' ); | ||
} ); | ||
|
||
afterEach( () => { | ||
mockery.deregisterAll(); | ||
mockery.disable(); | ||
sandbox.restore(); | ||
} ); | ||
|
||
it( 'should not verify packages if there are no packages in the release directory', async () => { | ||
stubs.glob.glob.resolves( [] ); | ||
|
||
const packagesDirectory = '/workspace/ckeditor5/release/npm'; | ||
const version = 'latest'; | ||
const onSuccess = sandbox.stub(); | ||
|
||
await verifyPackagesPublishedCorrectly( { packagesDirectory, version, onSuccess } ); | ||
|
||
expect( onSuccess.firstCall.args[ 0 ] ).to.equal( '✅ No packages found to check for upload error 409.' ); | ||
expect( stubs.devUtils.checkVersionAvailability.callCount ).to.equal( 0 ); | ||
} ); | ||
|
||
it( 'should verify packages and remove them from the release directory on "npm show" command success', async () => { | ||
stubs.glob.glob.resolves( [ 'package1', 'package2' ] ); | ||
stubs.fs.readJson | ||
.onCall( 0 ).resolves( { name: '@namespace/package1' } ) | ||
.onCall( 1 ).resolves( { name: '@namespace/package2' } ); | ||
|
||
const packagesDirectory = '/workspace/ckeditor5/release/npm'; | ||
const version = 'latest'; | ||
const onSuccess = sandbox.stub(); | ||
|
||
await verifyPackagesPublishedCorrectly( { packagesDirectory, version, onSuccess } ); | ||
|
||
expect( stubs.devUtils.checkVersionAvailability.firstCall.args[ 0 ] ).to.equal( 'latest' ); | ||
expect( stubs.devUtils.checkVersionAvailability.firstCall.args[ 1 ] ).to.equal( '@namespace/package1' ); | ||
expect( stubs.fs.remove.firstCall.args[ 0 ] ).to.equal( 'package1' ); | ||
|
||
expect( stubs.devUtils.checkVersionAvailability.secondCall.args[ 0 ] ).to.equal( 'latest' ); | ||
expect( stubs.devUtils.checkVersionAvailability.secondCall.args[ 1 ] ).to.equal( '@namespace/package2' ); | ||
expect( stubs.fs.remove.secondCall.args[ 0 ] ).to.equal( 'package2' ); | ||
|
||
expect( onSuccess.firstCall.args[ 0 ] ).to.equal( '✅ All packages that returned 409 were uploaded correctly.' ); | ||
} ); | ||
|
||
it( 'should not remove package from release directory on on error', async () => { | ||
stubs.glob.glob.resolves( [ 'package1', 'package2' ] ); | ||
stubs.fs.readJson | ||
.onCall( 0 ).resolves( { name: '@namespace/package1' } ) | ||
.onCall( 1 ).resolves( { name: '@namespace/package2' } ); | ||
stubs.devUtils.checkVersionAvailability | ||
.onCall( 0 ).rejects() | ||
.onCall( 1 ).resolves(); | ||
|
||
const packagesDirectory = '/workspace/ckeditor5/release/npm'; | ||
const version = 'latest'; | ||
const onSuccess = sandbox.stub(); | ||
|
||
await verifyPackagesPublishedCorrectly( { packagesDirectory, version, onSuccess } ) | ||
.then( | ||
() => { | ||
throw new Error( 'this should not be thrown!' ); | ||
}, | ||
e => { | ||
expect( e.message ).to.equal( | ||
'Packages that were uploaded incorrectly, and need manual verification:\n@namespace/package1' | ||
); | ||
} | ||
); | ||
|
||
expect( stubs.fs.remove.callCount ).to.equal( 1 ); | ||
expect( stubs.fs.remove.firstCall.args[ 0 ] ).to.equal( 'package2' ); | ||
} ); | ||
} ); | ||
} ); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkVersionAvailability()
returns a promise that resolves totrue
if the provided version does not exist or resolves the promise tofalse
otherwise.We should check the returned value here.