瀏覽代碼

Added script for the release main repository to package.json.

Kamil Piechaczek 7 年之前
父節點
當前提交
12537852ab
共有 4 個文件被更改,包括 199 次插入0 次删除
  1. 1 0
      package.json
  2. 42 0
      scripts/release-ckeditor5.sh
  3. 121 0
      scripts/release/release-ckeditor5.js
  4. 35 0
      scripts/release/update-mgit-branches.js

+ 1 - 0
package.json

@@ -109,6 +109,7 @@
     "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",
     "switch-to-dev-dev": "sh ./scripts/switch-to-dev-dev.sh"
   },

+ 42 - 0
scripts/release-ckeditor5.sh

@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+# For licensing, see LICENSE.md.
+
+set -e
+
+read -p "Did you update the README.md? " -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
+
+	# Update all `stable` branches in all packages.
+	mgit exec 'git checkout stable && git merge master && git checkout master'
+
+	# Make sure that `mgit.json` for `stable` and `master` branches is correct.
+	# `stable` branch.
+	git checkout stable && \
+	node -e "require( './scripts/release/update-mgit-branches' )( 'stable' );" && \
+	git commit -a -m "Internal: Use stable branches. [skip ci]".
+
+	# `master` branch.
+	git checkout master && \
+	git merge stable && \
+	node -e "require( './scripts/release/update-mgit-branches' )( 'master' );" && \
+	git commit -a -m "Internal: Use master branches. [skip ci]"
+
+	# Push the `stable` branches.
+	git push origin stable master && \
+	mgit exec 'git push origin stable'
+
+	# Add stable branches in all repos which don't have them yet.
+	mgit exec 'git checkout -b stable && git push origin stable && git checkout master'
+else
+	echo "Update the \"Releases\" section in README.md before starting the release process."
+fi

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

@@ -0,0 +1,121 @@
+#!/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 packageJsonPath = path.resolve( __dirname, '..', '..', 'package.json' );
+let packageJsonCopy;
+
+cli.provideToken()
+	.then( token => {
+		const gitVersion = versionUtils.getLastTagFromGit();
+		const changelogVersion = versionUtils.getLastFromChangelog();
+
+		log.info( 'Comparing versions - saved in changelog and as a tag...' );
+
+		// 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 }."`, { verbosity: 'error' } );
+
+		log.info( 'Updating the package.json...' );
+
+		// Update the `package.json`. Published package shouldn't have any dependencies and devDependencies.
+		// Also, we should omit our environment scripts and their configs.
+		tools.updateJSONFile( packageJsonPath, packageJson => {
+			// Save the original file. It will be restored after publishing the package.
+			packageJsonCopy = Object.assign( {}, packageJson );
+
+			// Remove unnecessary things.
+			delete packageJson.dependencies;
+			delete packageJson.devDependencies;
+			delete packageJson.scripts;
+			delete packageJson[ 'lint-staged' ];
+			delete packageJson.eslintIgnore;
+
+			// Update the package's description.
+			// eslint-disable-next-line max-len
+			packageJson.description = 'A set of ready-to-use rich text editors created with a powerful framework. Made with real-time collaborative editing in mind.';
+
+			// The files listed below will be published even if they won't be specified under the `files` key in package.json.
+			// However, instead of creating the `.npmignore` file and specifying everything here, we can list files that we want to publish.
+			packageJson.files = [
+				'CHANGELOG.md',
+				'LICENSE.md',
+				'README.md',
+				'package.json'
+			];
+
+			return packageJson;
+		} );
+
+		log.info( 'Publishing on npm...' );
+
+		// Publish the package on npm.
+		tools.shExec( 'npm publish' );
+
+		log.info( 'Creating a release on GitHub...' );
+
+		// Create a release on GitHub.
+		return createGithubRelease( token, {
+			repositoryOwner: 'ckeditor',
+			repositoryName: 'ckeditor5',
+			version: changelogVersion,
+			description: releaseDescription
+		} );
+	} )
+	.then( () => {
+		log.info( 'Restoring the package.json...' );
+
+		// Restore the `package.json` to state before the publishing process.
+		tools.updateJSONFile( packageJsonPath, () => packageJsonCopy );
+
+		const url = `https://github.com/ckeditor/ckeditor5/releases/tag/v${ packageJsonCopy.version }`;
+		log.info( `Created the release: ${ url }` );
+	} )
+	.catch( err => {
+		log.error( err.stack );
+	} );
+
+function reject( message ) {
+	return Promise.reject( new Error( message ) );
+}

+ 35 - 0
scripts/release/update-mgit-branches.js

@@ -0,0 +1,35 @@
+/**
+ * @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 mgitJsonPath = path.resolve( __dirname, '..', '..', 'mgit.json' );
+
+module.exports = function updateMgitBranches( branchName ) {
+	const log = logger();
+
+	log.info( 'Updating the mgit.json file...' );
+
+	tools.updateJSONFile( mgitJsonPath, mgitJson => {
+		const dependencies = mgitJson.dependencies;
+
+		for ( const packageName of Object.keys( dependencies ) ) {
+			dependencies[ packageName ] = dependencies[ packageName ].split( '#' )[ 0 ];
+
+			if ( branchName !== 'master' ) {
+				dependencies[ packageName ] += '#' + branchName;
+			}
+		}
+
+		return mgitJson;
+	} );
+
+	logger().info( `Done. Mgit.json uses the "${branchName}" branch now.` );
+};