From caa0fce0402fc6253d7c429ea7017735a1bfdf9d Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Tue, 8 Oct 2024 12:00:50 +0200 Subject: [PATCH] Removed the "verifyPackagesPublishedCorrectly()" task. --- .../ckeditor5-dev-release-tools/lib/index.js | 1 - .../tasks/verifypackagespublishedcorrectly.js | 49 ------------- .../tests/index.js | 8 -- .../tasks/verifypackagespublishedcorrectly.js | 73 ------------------- scripts/publishpackages.js | 16 ---- 5 files changed, 147 deletions(-) delete mode 100644 packages/ckeditor5-dev-release-tools/lib/tasks/verifypackagespublishedcorrectly.js delete mode 100644 packages/ckeditor5-dev-release-tools/tests/tasks/verifypackagespublishedcorrectly.js diff --git a/packages/ckeditor5-dev-release-tools/lib/index.js b/packages/ckeditor5-dev-release-tools/lib/index.js index 43fc56853..13c83ea46 100644 --- a/packages/ckeditor5-dev-release-tools/lib/index.js +++ b/packages/ckeditor5-dev-release-tools/lib/index.js @@ -29,7 +29,6 @@ export { default as saveChangelog } from './utils/savechangelog.js'; export { default as executeInParallel } from './utils/executeinparallel.js'; export { default as validateRepositoryToRelease } from './utils/validaterepositorytorelease.js'; export { default as checkVersionAvailability } from './utils/checkversionavailability.js'; -export { default as verifyPackagesPublishedCorrectly } from './tasks/verifypackagespublishedcorrectly.js'; export { default as getNpmTagFromVersion } from './utils/getnpmtagfromversion.js'; export { default as isVersionPublishableForTag } from './utils/isversionpublishablefortag.js'; export { default as provideToken } from './utils/providetoken.js'; diff --git a/packages/ckeditor5-dev-release-tools/lib/tasks/verifypackagespublishedcorrectly.js b/packages/ckeditor5-dev-release-tools/lib/tasks/verifypackagespublishedcorrectly.js deleted file mode 100644 index a72137535..000000000 --- a/packages/ckeditor5-dev-release-tools/lib/tasks/verifypackagespublishedcorrectly.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. - * For licensing, see LICENSE.md. - */ - -import upath from 'upath'; -import { glob } from 'glob'; -import fs from 'fs-extra'; -import checkVersionAvailability from '../utils/checkversionavailability.js'; - -/** - * 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} - */ -export default 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' ) ); - - const isPackageVersionAvailable = await checkVersionAvailability( version, packageJson.name ); - - if ( isPackageVersionAvailable ) { - errors.push( packageJson.name ); - } else { - await fs.remove( packageToVerify ); - } - } - - 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.' ); -} diff --git a/packages/ckeditor5-dev-release-tools/tests/index.js b/packages/ckeditor5-dev-release-tools/tests/index.js index b483a9b17..eeb234fc8 100644 --- a/packages/ckeditor5-dev-release-tools/tests/index.js +++ b/packages/ckeditor5-dev-release-tools/tests/index.js @@ -30,7 +30,6 @@ import { import executeInParallel from '../lib/utils/executeinparallel.js'; import validateRepositoryToRelease from '../lib/utils/validaterepositorytorelease.js'; import checkVersionAvailability from '../lib/utils/checkversionavailability.js'; -import verifyPackagesPublishedCorrectly from '../lib/tasks/verifypackagespublishedcorrectly.js'; import getNpmTagFromVersion from '../lib/utils/getnpmtagfromversion.js'; import isVersionPublishableForTag from '../lib/utils/isversionpublishablefortag.js'; import provideToken from '../lib/utils/providetoken.js'; @@ -239,13 +238,6 @@ describe( 'dev-release-tools/index', () => { } ); } ); - describe( 'verifyPackagesPublishedCorrectly()', () => { - it( 'should be a function', () => { - expect( verifyPackagesPublishedCorrectly ).to.be.a( 'function' ); - expect( index.verifyPackagesPublishedCorrectly ).to.equal( verifyPackagesPublishedCorrectly ); - } ); - } ); - describe( 'provideToken()', () => { it( 'should be a function', () => { expect( provideToken ).to.be.a( 'function' ); diff --git a/packages/ckeditor5-dev-release-tools/tests/tasks/verifypackagespublishedcorrectly.js b/packages/ckeditor5-dev-release-tools/tests/tasks/verifypackagespublishedcorrectly.js deleted file mode 100644 index dae050086..000000000 --- a/packages/ckeditor5-dev-release-tools/tests/tasks/verifypackagespublishedcorrectly.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. - * For licensing, see LICENSE.md. - */ - -import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { glob } from 'glob'; -import fs from 'fs-extra'; -import verifyPackagesPublishedCorrectly from '../../lib/tasks/verifypackagespublishedcorrectly.js'; -import checkVersionAvailability from '../../lib/utils/checkversionavailability.js'; - -vi.mock( 'fs-extra' ); -vi.mock( '../../lib/utils/checkversionavailability' ); -vi.mock( 'glob' ); - -describe( 'verifyPackagesPublishedCorrectly()', () => { - beforeEach( () => { - vi.mocked( fs ).remove.mockResolvedValue(); - vi.mocked( fs ).readJson.mockResolvedValue(); - vi.mocked( glob ).mockResolvedValue( [] ); - vi.mocked( checkVersionAvailability ).mockResolvedValue(); - } ); - - it( 'should not verify packages if there are no packages in the release directory', async () => { - const packagesDirectory = '/workspace/ckeditor5/release/npm'; - const version = 'latest'; - const onSuccess = vi.fn(); - - await verifyPackagesPublishedCorrectly( { packagesDirectory, version, onSuccess } ); - - expect( onSuccess ).toHaveBeenCalledExactlyOnceWith( 'No packages found to check for upload error 409.' ); - expect( vi.mocked( checkVersionAvailability ) ).not.toHaveBeenCalled(); - } ); - - it( 'should verify packages and remove them from the release directory on if their version are already taken', async () => { - vi.mocked( glob ).mockResolvedValue( [ 'package1', 'package2' ] ); - vi.mocked( fs ).readJson - .mockResolvedValueOnce( { name: '@namespace/package1' } ) - .mockResolvedValueOnce( { name: '@namespace/package2' } ); - - const packagesDirectory = '/workspace/ckeditor5/release/npm'; - const version = 'latest'; - const onSuccess = vi.fn(); - - await verifyPackagesPublishedCorrectly( { packagesDirectory, version, onSuccess } ); - - expect( vi.mocked( checkVersionAvailability ) ).toHaveBeenCalledWith( 'latest', '@namespace/package1' ); - expect( vi.mocked( checkVersionAvailability ) ).toHaveBeenCalledWith( 'latest', '@namespace/package2' ); - expect( vi.mocked( fs ).remove ).toHaveBeenCalledWith( 'package1' ); - expect( vi.mocked( fs ).remove ).toHaveBeenCalledWith( 'package2' ); - - expect( onSuccess ).toHaveBeenCalledExactlyOnceWith( 'All packages that returned 409 were uploaded correctly.' ); - } ); - - it( 'should not remove package from release directory when package is not available on npm', async () => { - vi.mocked( glob ).mockResolvedValue( [ 'package1', 'package2' ] ); - vi.mocked( fs ).readJson - .mockResolvedValueOnce( { name: '@namespace/package1' } ) - .mockResolvedValueOnce( { name: '@namespace/package2' } ); - vi.mocked( checkVersionAvailability ) - .mockResolvedValueOnce( true ) - .mockResolvedValueOnce( false ); - - const packagesDirectory = '/workspace/ckeditor5/release/npm'; - const version = 'latest'; - const onSuccess = vi.fn(); - - await expect( verifyPackagesPublishedCorrectly( { packagesDirectory, version, onSuccess } ) ) - .rejects.toThrow( 'Packages that were uploaded incorrectly, and need manual verification:\n@namespace/package1' ); - - expect( vi.mocked( fs ).remove ).toHaveBeenCalledExactlyOnceWith( 'package2' ); - } ); -} ); diff --git a/scripts/publishpackages.js b/scripts/publishpackages.js index d7439bc3e..dc3af8af9 100644 --- a/scripts/publishpackages.js +++ b/scripts/publishpackages.js @@ -43,22 +43,6 @@ const tasks = new Listr( [ .run( confirm, { message: 'Do you want to continue?' } ); } } ); - }, - retry: 3 - }, - { - title: 'Checking if packages that returned E409 error code were uploaded correctly.', - task: async ( _, task ) => { - return releaseTools.verifyPackagesPublishedCorrectly( { - packagesDirectory: RELEASE_DIRECTORY, - version: latestVersion, - onSuccess: text => { - task.output = text; - } - } ); - }, - options: { - persistentOutput: true } }, {