浏览代码

@grafana/ui - release docs v1 (#15835)

* Readme update

* Update @grafana/ui Readme qith release process description. Allow version commit creation during release

* Run tests and checks for grafana/core before releasing grafana/ui

* Post review Readme updates
Dominik Prokop 6 年之前
父节点
当前提交
d104ee1c15
共有 4 个文件被更改,包括 60 次插入4 次删除
  1. 1 1
      package.json
  2. 30 0
      packages/grafana-ui/README.md
  3. 2 0
      scripts/cli/index.ts
  4. 27 3
      scripts/cli/tasks/grafanaui.release.ts

+ 1 - 1
package.json

@@ -139,7 +139,7 @@
     "gui:build": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts gui:build",
     "gui:releasePrepare": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts gui:release",
     "gui:publish": "cd packages/grafana-ui/dist && npm publish --access public",
-    "gui:release": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts gui:release -p",
+    "gui:release": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts gui:release -p --createVersionCommit",
     "cli": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts"
   },
   "husky": {

+ 30 - 0
packages/grafana-ui/README.md

@@ -12,6 +12,36 @@ See [package source](https://github.com/grafana/grafana/tree/master/packages/gra
 
 `npm install @grafana/ui`
 
+## Development
+
+For development purposes we suggest using `yarn link` that will create symlink to @grafana/ui lib. To do so navigate to `packages/grafana-ui` and run `yarn link`. Then, navigate to your project and run `yarn link @grafana/ui` to use the linked version of the lib. To unlink follow the same procedure, but use `yarn unlink` instead.
+
+## Building @grafana/ui
+To build @grafana/ui run `npm run gui:build` script *from Grafana repository root*. The build will be created in `packages/grafana-ui/dist` directory. Following steps from [Development](#development) you can test built package.
+
+## Releasing new version
+To release new version run `npm run gui:release` script *from Grafana repository root*. The script will prepare the distribution package as well as prompt you to bump library version and publish it to the NPM registry.
+
+### Automatic version bump
+When running `npm run gui:release` package.json file will be automatically updated. Also, package.json file will be commited and pushed to upstream branch.
+
+### Manual version bump
+To use `package.json` defined version run `npm run gui:release --usePackageJsonVersion` *from Grafana repository root*.
+
+### Preparing release package without publishing to NPM registry
+For testing purposes there is `npm run gui:releasePrepare` task that prepares distribution package without publishing it to the NPM registry.
+
+### V1 release process overview
+1. Package is compiled with TSC. Typings are created in `/dist` directory, and the compiled js lands in `/compiled` dir
+2. Rollup creates a CommonJS package based on compiled sources, and outputs it to `/dist` directory
+3. Readme, changelog and index.js files are moved to `/dist` directory
+4. Package version is bumped in both `@grafana/ui` package dir and in dist directory.
+5. Version commit is created and pushed to master branch
+5. Package is published to npm
+
+
 ## Versioning
 To limit the confusion related to @grafana/ui and Grafana versioning we decided to keep the major version in sync between those two.
 This means, that first version of @grafana/ui is taged with 6.0.0-alpha.0 to keep version in sync with Grafana 6.0 release.
+
+

+ 2 - 0
scripts/cli/index.ts

@@ -33,10 +33,12 @@ program
   .description('Prepares @grafana/ui release (and publishes to npm on demand)')
   .option('-p, --publish', 'Publish @grafana/ui to npm registry')
   .option('-u, --usePackageJsonVersion', 'Use version specified in package.json')
+  .option('--createVersionCommit', 'Create and push version commit')
   .action(async cmd => {
     await execTask(releaseTask)({
       publishToNpm: !!cmd.publish,
       usePackageJsonVersion: !!cmd.usePackageJsonVersion,
+      createVersionCommit: !!cmd.createVersionCommit,
     });
   });
 

+ 27 - 3
scripts/cli/tasks/grafanaui.release.ts

@@ -9,10 +9,10 @@ import { savePackage, buildTask } from './grafanaui.build';
 import { TaskRunner, Task } from './task';
 
 type VersionBumpType = 'prerelease' | 'patch' | 'minor' | 'major';
-
 interface ReleaseTaskOptions {
   publishToNpm: boolean;
   usePackageJsonVersion: boolean;
+  createVersionCommit: boolean;
 }
 
 const promptBumpType = async () => {
@@ -62,6 +62,12 @@ const promptConfirm = async (message?: string) => {
   ]);
 };
 
+// Since Grafana core depends on @grafana/ui highly, we run full check before release
+const runChecksAndTests = async () =>
+  useSpinner<void>(`Running checks and tests`, async () => {
+    await execa('npm', ['run', 'test']);
+  })();
+
 const bumpVersion = (version: string) =>
   useSpinner<void>(`Saving version ${version} to package.json`, async () => {
     changeCwdToGrafanaUi();
@@ -94,8 +100,21 @@ const ensureMasterBranch = async () => {
   }
 };
 
-const releaseTaskRunner: TaskRunner<ReleaseTaskOptions> = async ({ publishToNpm, usePackageJsonVersion }) => {
+const prepareVersionCommitAndPush = async (version: string) =>
+  useSpinner<void>('Commiting and pushing @grafana/ui version update', async () => {
+    await execa.stdout('git', ['commit', '-a', '-m', `Upgrade @grafana/ui version to v${version}`]);
+    await execa.stdout('git', ['push']);
+  })();
+
+const releaseTaskRunner: TaskRunner<ReleaseTaskOptions> = async ({
+  publishToNpm,
+  usePackageJsonVersion,
+  createVersionCommit,
+}) => {
+  await runChecksAndTests();
   if (publishToNpm) {
+    // TODO: Ensure release branch
+    // When need to update this when we star keeping @grafana/ui releases in sync with core
     await ensureMasterBranch();
   }
 
@@ -145,10 +164,15 @@ const releaseTaskRunner: TaskRunner<ReleaseTaskOptions> = async ({ publishToNpm,
     await bumpVersion(nextVersion);
   }
 
+  if (createVersionCommit) {
+    await prepareVersionCommitAndPush(nextVersion);
+  }
+
   if (publishToNpm) {
     await publishPackage(pkg.name, nextVersion);
     console.log(chalk.green(`\nVersion ${nextVersion} of ${pkg.name} succesfully released!`));
-    console.log(chalk.yellow(`\nUpdated @grafana/ui/package.json with version bump created - COMMIT THIS FILE!`));
+    console.log(chalk.yellow(`\nUpdated @grafana/ui/package.json with version bump created.`));
+
     process.exit();
   } else {
     console.log(