Przeglądaj źródła

Adjust scripts for releasing CKEditor5 and CKEditor5's packages to changes in ckeditor5-dev-env.

Kamil Piechaczek 7 lat temu
rodzic
commit
0b840410f8

+ 3 - 3
package.json

@@ -109,9 +109,9 @@
     "translations:download": "ckeditor5-dev-env-translations download",
     "translations:upload": "ckeditor5-dev-env-translations upload",
     "changelog": "node ./scripts/release/changelog.js",
-    "release": "bash ./scripts/release-ckeditor5.sh",
-    "release:dependencies": "node ./scripts/release/release-dependencies.js",
-    "release:update-dependencies": "node ./scripts/update-dependencies-versions.js",
+    "release:bump-version": "node ./scripts/release/bump-versions.js",
+    "release:publish": "node ./scripts/release/publish.js",
+    "release:stable-branches": "sh ./scripts/update-stable-branches.sh",
     "switch-to-dev-dev": "sh ./scripts/switch-to-dev-dev.sh"
   },
   "lint-staged": {

+ 31 - 0
scripts/release/bump-versions.js

@@ -0,0 +1,31 @@
+#!/usr/bin/env node
+
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* eslint-env node */
+
+'use strict';
+
+// This scripts preparing all packages to release:
+//   - checking what should be released,
+//   - updates version of all dependencies for all packages,
+//   - validates the whole process (whether the changes could be published),
+//   - tagging new versions.
+//
+// You can test the whole process using `dry-run` mode. It won't change anything in the project
+// and any repository.
+//
+// This task must be called before: `npm run release:publish`.
+//
+// Use:
+// npm run release:bump-version -- --dry-run
+
+require( '@ckeditor/ckeditor5-dev-env' )
+	.bumpVersions( {
+		cwd: process.cwd(),
+		packages: 'packages',
+		dryRun: process.argv.includes( '--dry-run' )
+	} );

+ 3 - 1
scripts/release/changelog.js

@@ -22,8 +22,10 @@ const commonOptions = {
 const editorBuildsGlob = '@ckeditor/ckeditor5-build-*';
 
 const optionsForDependencies = Object.assign( {}, commonOptions, {
-	skipPackages: editorBuildsGlob
+	skipPackages: editorBuildsGlob,
+	skipMainRepository: true
 } );
+
 const optionsForBuilds = Object.assign( {}, commonOptions, {
 	scope: editorBuildsGlob
 } );

+ 41 - 0
scripts/release/publish.js

@@ -0,0 +1,41 @@
+#!/usr/bin/env node
+
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* eslint-env node */
+
+'use strict';
+
+// This scripts publish changes.
+//
+// You can test the whole process using `dry-run` mode. It won't change anything in the project
+// and any repository. Nothing will be pushed. Instead of `npm publish`, the `npm pack` command will be called.
+//
+// Note: This task based on versions published on NPM and GitHub. If something went wrong, you can call this script one more time.
+//
+// This task should be executed after: `npm run release:bump-version`.
+//
+// Use:
+// npm run release:publish -- --dry-run
+
+/* eslint-disable max-len */
+
+require( '@ckeditor/ckeditor5-dev-env' )
+	.releaseSubRepositories( {
+		cwd: process.cwd(),
+		packages: 'packages',
+		emptyReleases: [
+			'ckeditor5'
+		],
+		packageJsonForEmptyReleases: {
+			ckeditor5: {
+				description: 'A set of ready-to-use rich text editors created with a powerful framework. Made with real-time collaborative editing in mind.'
+			}
+		},
+		dryRun: process.argv.includes( '--dry-run' )
+	} );
+
+/* eslint-enable max-len */

+ 0 - 139
scripts/release/release-ckeditor5.js

@@ -1,139 +0,0 @@
-#!/usr/bin/env node
-
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* eslint-env node */
-
-'use strict';
-
-const path = require( 'path' );
-const { tools, logger } = require( '@ckeditor/ckeditor5-dev-utils' );
-const versionUtils = require( '@ckeditor/ckeditor5-dev-env/lib/release-tools/utils/versions' );
-const cli = require( '@ckeditor/ckeditor5-dev-env/lib/release-tools/utils/cli' );
-const createGithubRelease = require( '@ckeditor/ckeditor5-dev-env/lib/release-tools/utils/creategithubrelease' );
-const validatePackageToRelease = require( '@ckeditor/ckeditor5-dev-env/lib/release-tools/utils/validatepackagetorelease' );
-const { getChangesForVersion } = require( '@ckeditor/ckeditor5-dev-env/lib/release-tools/utils/changelog' );
-
-const log = logger();
-const cke5Path = path.resolve( __dirname, '..', '..' );
-const packageJsonPath = path.resolve( cke5Path, 'package.json' );
-const templatePath = path.resolve( cke5Path, 'scripts', 'release', 'template' );
-const packageJsonTemplatePath = path.resolve( templatePath, 'package.json' );
-const packageJsonTemplateCopy = require( packageJsonTemplatePath );
-
-// That files will be copied from source to template directory and will be released too.
-const additionalFiles = [
-	'CHANGELOG.md',
-	'LICENSE.md',
-	'README.md'
-];
-
-cli.provideToken()
-	.then( token => {
-		const gitVersion = versionUtils.getLastTagFromGit();
-		const changelogVersion = versionUtils.getLastFromChangelog();
-
-		log.info( 'Checking whether there is anything to release...' );
-
-		// If the last tag is equal to version saved in changelog, we don't have new version for release.
-		if ( gitVersion === changelogVersion ) {
-			return reject( 'Before starting the release process, you should generate the changelog.' );
-		}
-
-		const releaseDescription = getChangesForVersion( changelogVersion );
-
-		log.info( 'Validating the repository for the release...' );
-
-		const errors = validatePackageToRelease( {
-			version: changelogVersion,
-			changes: releaseDescription
-		} );
-
-		// Abort due to errors during validation.
-		if ( errors.length ) {
-			const log = logger();
-
-			log.error( 'Unexpected errors occured:' );
-			errors.map( err => '* ' + err ).forEach( log.error.bind( log ) );
-
-			return reject( 'Releasing has been aborted due to errors.' );
-		}
-
-		log.info( 'Bumping the version...' );
-
-		// Bump the version.
-		tools.shExec(
-			`npm version ${ changelogVersion } --message "Release: v${ changelogVersion }." --allow-same-version`,
-			{ verbosity: 'error' }
-		);
-
-		tools.shExec( `git push origin master v${ changelogVersion }` );
-
-		const packageJson = require( packageJsonPath );
-
-		log.info( 'Copying the package.json...' );
-
-		// Update the template of `package.json`. We will use values from source `package.json`
-		// but only these ones which are defined in the template.
-		tools.updateJSONFile( packageJsonTemplatePath, jsonFile => {
-			for ( const property of Object.keys( jsonFile ) ) {
-				// If the `property` is set in the template, leave it.
-				if ( jsonFile[ property ] ) {
-					continue;
-				}
-
-				if ( property == 'private' ) {
-					continue;
-				}
-
-				// Copy value from original package.json file.
-				jsonFile[ property ] = packageJson[ property ];
-			}
-
-			return jsonFile;
-		} );
-
-		// Copy additional files.
-		for ( const file of additionalFiles ) {
-			tools.shExec( `cp ${ path.resolve( cke5Path, file ) } ${ path.resolve( templatePath, file ) }` );
-		}
-
-		log.info( 'Publishing on npm...' );
-
-		// Publish the package on npm.
-		tools.shExec( `cd ${ templatePath } && npm publish && cd ${ cke5Path }` );
-
-		// Remove files that were copy.
-		for ( const file of additionalFiles ) {
-			tools.shExec( `rm ${ path.resolve( templatePath, file ) }` );
-		}
-
-		log.info( 'Creating a release on GitHub...' );
-
-		// Create a release on GitHub.
-		return createGithubRelease( token, {
-			repositoryOwner: 'ckeditor',
-			repositoryName: 'ckeditor5',
-			version: `v${ changelogVersion }`,
-			description: releaseDescription
-		} ).then( () => changelogVersion );
-	} )
-	.then( version => {
-		log.info( 'Restoring the package.json template...' );
-
-		// Restore the template `package.json` to state before the publishing process.
-		tools.updateJSONFile( packageJsonTemplatePath, () => packageJsonTemplateCopy );
-
-		const url = `https://github.com/ckeditor/ckeditor5/releases/tag/v${ version }`;
-		log.info( `Created the release: ${ url }` );
-	} )
-	.catch( err => {
-		log.error( err.stack );
-	} );
-
-function reject( message ) {
-	return Promise.reject( new Error( message ) );
-}

+ 0 - 21
scripts/release/release-dependencies.js

@@ -1,21 +0,0 @@
-#!/usr/bin/env node
-
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* eslint-env node */
-
-'use strict';
-
-// In order to test the whole process, you can use:
-// npm run release:dependencies -- --dry-run
-// It will create some commits but nothing will be pushed or published.
-
-require( '@ckeditor/ckeditor5-dev-env' )
-	.releaseSubRepositories( {
-		cwd: process.cwd(),
-		packages: 'packages',
-		dryRun: process.argv.includes( '--dry-run' )
-	} );

+ 0 - 12
scripts/release/template/package.json

@@ -1,12 +0,0 @@
-{
-  "name": null,
-  "version": null,
-  "description": "A set of ready-to-use rich text editors created with a powerful framework. Made with real-time collaborative editing in mind.",
-  "keywords": null,
-  "engines": null,
-  "author": null,
-  "license": null,
-  "homepage": null,
-  "bugs": null,
-  "repository": null
-}

+ 0 - 54
scripts/update-dependencies-versions.js

@@ -1,54 +0,0 @@
-#!/usr/bin/env node
-
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* eslint-env node */
-
-'use strict';
-
-const path = require( 'path' );
-const { tools, logger } = require( '@ckeditor/ckeditor5-dev-utils' );
-
-const log = logger();
-const packageJsonPath = path.join( __dirname, '..', 'package.json' );
-
-log.info( 'Updating version of dependencies in "package.json"...' );
-let counter = 0;
-
-tools.updateJSONFile( packageJsonPath, packageJson => {
-	const dependencies = packageJson.dependencies;
-
-	for ( const packageName of Object.keys( dependencies ) ) {
-		try {
-			const dependencyPackageJson = require( packageName + '/package.json' );
-			const newVersion = '^' + dependencyPackageJson.version;
-
-			if ( packageJson.dependencies[ dependencyPackageJson.name ] !== newVersion ) {
-				counter += 1;
-			}
-
-			packageJson.dependencies[ dependencyPackageJson.name ] = newVersion;
-		} catch ( error ) {
-			log.warning( `Package "${ packageName }" is not installed and its version cannot be updated.` );
-		}
-	}
-
-	return packageJson;
-} );
-
-log.info( `Updated versions of ${ counter } packages.` );
-
-if ( counter ) {
-	log.info( 'Committing updated "package.json" file...' );
-
-	const response = tools.shExec( 'git add package.json && git commit -m "Internal: Updated dependencies."', { verbosity: 'error' } );
-
-	log.info( response.trim() );
-} else {
-	log.info( 'Nothing to update? It smells like troubles!' );
-}
-
-log.info( 'Done.' );

+ 1 - 6
scripts/release-ckeditor5.sh

@@ -5,14 +5,11 @@
 
 set -e
 
-read -p "Did you update the \"Releases\" section in README.md? " -n 1 -r
+read -p "Are you sure? " -n 1 -r
 echo ""
 
 if [[ $REPLY =~ ^[Yy]$ ]]
 then
-	# Release the CKEditor5 repository.
-	node ./scripts/release/release-ckeditor5.js
-
 	# Update the `stable` branch in the ckeditor5 repository.
 	git checkout stable && git merge master && git checkout master
 
@@ -39,6 +36,4 @@ then
 	mgit exec 'git push origin stable'
 
 	echo "Success! 🎂"
-else
-	echo "Update the \"Releases\" section in README.md before starting the release process."
 fi