From c2dea633e60e85b267829e5893df49b4c9afdb73 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Thu, 12 Sep 2019 08:00:31 +0200 Subject: [PATCH] Packages: update versioning and release process (#18195) --- .circleci/config.yml | 28 +++++++++++++++ lerna.json | 2 +- package.json | 6 ++-- packages/README.md | 47 +++++++++++++++++++++---- packages/grafana-data/README.md | 4 ++- packages/grafana-data/package.json | 2 +- packages/grafana-runtime/README.md | 4 ++- packages/grafana-runtime/package.json | 2 +- packages/grafana-toolkit/README.md | 9 +++-- packages/grafana-toolkit/package.json | 2 +- packages/grafana-ui/README.md | 2 ++ packages/grafana-ui/package.json | 2 +- scripts/build/release-packages.sh | 40 +++++++++++++++++++++ scripts/circle-release-next-packages.sh | 12 ++++--- 14 files changed, 140 insertions(+), 22 deletions(-) create mode 100755 scripts/build/release-packages.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index c03c91febfb..be507171f9a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -672,6 +672,21 @@ jobs: name: Release next packages command: './scripts/circle-release-next-packages.sh' + release-packages: + docker: + - image: circleci/node:10 + steps: + - checkout + - run: + name: Boostrap lerna + command: 'npx lerna bootstrap' + - run: + name: npm - Prepare auth token + command: 'echo //registry.npmjs.org/:_authToken=$NPM_TOKEN >> ~/.npmrc' + - run: + name: Release packages + command: ./scripts/build/release-packages.sh "${CIRCLE_TAG}" + workflows: version: 2 build-master: @@ -754,6 +769,7 @@ workflows: - build-all - test-frontend filters: *filter-only-master + release: jobs: - build-all: @@ -810,6 +826,18 @@ workflows: - mysql-integration-test - postgres-integration-test filters: *filter-only-release + - release-packages: + requires: + - build-all + - test-backend + - test-frontend + - codespell + - lint-go + - shellcheck + - mysql-integration-test + - postgres-integration-test + - build-oss-msi + filters: *filter-only-release - build-oss-msi: requires: - build-all diff --git a/lerna.json b/lerna.json index 28322a3f627..30f4e4728fd 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "npmClient": "yarn", "useWorkspaces": true, "packages": ["packages/*"], - "version": "6.4.0-alpha.44" + "version": "6.4.0-pre" } diff --git a/package.json b/package.json index 4ac25982f42..a16e5a32732 100644 --- a/package.json +++ b/package.json @@ -163,10 +163,12 @@ "prettier:write": "prettier --list-different \"**/*.{ts,tsx,scss}\" --write", "precommit": "grafana-toolkit precommit", "themes:generate": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/generateSassVariableFiles.ts", - "packages:prepare": "lerna run clean && npm run test && lerna version --tag-version-prefix=\"packages@\" -m \"Packages: publish %s\" --no-push", + "packages:prepare": "lerna version --no-push --no-git-tag-version --force-publish --exact", "packages:build": "lerna run clean && lerna run build", "packages:publish": "lerna publish from-package --contents dist", - "packages:publishNext": "lerna publish from-package --contents dist --dist-tag next --yes" + "packages:publishLatest": "lerna publish from-package --contents dist --yes", + "packages:publishNext": "lerna publish from-package --contents dist --dist-tag next --yes", + "packages:publishCanary": "lerna publish from-package --contents dist --dist-tag canary --yes" }, "husky": { "hooks": { diff --git a/packages/README.md b/packages/README.md index 992a72c4f51..aa4c4a1b7ec 100644 --- a/packages/README.md +++ b/packages/README.md @@ -1,15 +1,50 @@ ## Grafana frontend packages -## Releasing new version +## Versioning We use [Lerna](https://github.com/lerna/lerna) for packages versioning and releases +All packages are versioned according to the current Grafana version: +- Grafana v6.3.0-alpha1 -> @grafana/* packages @ 6.3.0-alpha.1 +- Grafana v6.2.5 -> @grafana/* packages @ 6.2.5 +- Grafana - master branch version (based on package.json, i.e. 6.4.0-pre) -> @grafana/* packages @ 6.4.0-pre- (see details below about packages publishing channels) + +> Please note that @grafana/toolkit, @grafana/ui, @grafana/data & @grafana/runtime packages are considered ALPHA even though they are not released as alpha versions + +### Stable releases +> **Even though packages are released under a stable version, they are considered ALPHA until further notice!** + +Stable releases are published under `latest` tag on npm. + +### Alpha and beta releases +Alpha and beta releases are published under `next` tag on npm. + +### Automatic pre-releases +Every commit to master that has changes within `packages` directory is a subject of npm packages release. +*ALL* packages will be released under version from lerna.json file with commit SHA added to it: + +``` +- +``` + +Automatic prereleases are published under `canary` dist tag. + ### Manual release -1. Run `packages:prepare` script from root directory. This will perform cleanup, run all tests and bump version for all packages. Also, it will create `@packages@[version]` tag and version bump commit with `Packages: publish [version]` message. -2. Run `packages:build` script that will prepare distribution packages. -3. Run `packages:publish` to publish new versions - - add `--dist-tag next` to publish under `next` tag -4. Push version commit +> All of the steps below should be performed on a release branch, according to Grafana Release Guide + +> Make sure you are logged in to npm in your terminal and that you are a part of Grafana org on npm + +1. Run `yarn packages:prepare` script from root directory. This will perform tests on the packages and prompt for version of the packages. The version should be the same as the one being released. + - Make sure you use semver convention. So, *place a dot between prerelease id and prelease number*!!! i.e. 6.3.0-alpha.1 + - Make sure you confirm the version bump when prompted! +2. Commit changes (lerna.json & package.json files) - *"Packages version update: \"* +3. Run `yarn packages:build` script that will prepare distribution packages in `packages/grafana-*/dist`. These directories are going to be published to npm +4. Depending whether or not it's a prerelease: + - When releasing a prelease run `packages:publishNext` to publish new versions. + - When releasing a stable version run `packages:publishLatest` to publish new versions. + +5. Push version commit to the release branch ### Building individual packages To build induvidual packages run `grafana-toolkit package:build --scope=` + diff --git a/packages/grafana-data/README.md b/packages/grafana-data/README.md index 76401653d06..c63960de81f 100644 --- a/packages/grafana-data/README.md +++ b/packages/grafana-data/README.md @@ -1,3 +1,5 @@ # Grafana Data Library -This package holds the root data types and functions used within Grafana. \ No newline at end of file +> **@grafana/data is currently in ALPHA**. Core API is unstable and can be a subject of breaking changes! + +This package holds the root data types and functions used within Grafana. diff --git a/packages/grafana-data/package.json b/packages/grafana-data/package.json index 7acfffd95f1..634c74f6d95 100644 --- a/packages/grafana-data/package.json +++ b/packages/grafana-data/package.json @@ -2,7 +2,7 @@ "author": "Grafana Labs", "license": "Apache-2.0", "name": "@grafana/data", - "version": "6.4.0-alpha.44", + "version": "6.4.0-pre", "description": "Grafana Data Library", "keywords": [ "typescript" diff --git a/packages/grafana-runtime/README.md b/packages/grafana-runtime/README.md index 852cc3327e9..87e6b374fd9 100644 --- a/packages/grafana-runtime/README.md +++ b/packages/grafana-runtime/README.md @@ -1,3 +1,5 @@ # Grafana Runtime library -This package allows access to grafana services. It requires Grafana to be running already and the functions to be imported as externals. \ No newline at end of file +> **@grafana/runtime is currently in ALPHA**. Core API is unstable and can be a subject of breaking changes! + +This package allows access to grafana services. It requires Grafana to be running already and the functions to be imported as externals. diff --git a/packages/grafana-runtime/package.json b/packages/grafana-runtime/package.json index b0052353bc9..b40a8ff9c9c 100644 --- a/packages/grafana-runtime/package.json +++ b/packages/grafana-runtime/package.json @@ -2,7 +2,7 @@ "author": "Grafana Labs", "license": "Apache-2.0", "name": "@grafana/runtime", - "version": "6.4.0-alpha.44", + "version": "6.4.0-pre", "description": "Grafana Runtime Library", "keywords": [ "grafana", diff --git a/packages/grafana-toolkit/README.md b/packages/grafana-toolkit/README.md index bb8f5863636..f940b635433 100644 --- a/packages/grafana-toolkit/README.md +++ b/packages/grafana-toolkit/README.md @@ -1,14 +1,17 @@ +> **@grafana/toolkit is currently in ALPHA**. Core API is unstable and can be a subject of breaking changes! + # grafana-toolkit grafana-toolkit is CLI that enables efficient development of Grafana extensions + ## Rationale Historically, creating Grafana extension was an exercise of reverse engineering and ceremony around testing, developing and eventually building the plugin. We want to help our community to focus on the core value of their plugins rather than all the setup required to develop an extension. ## Installation You can either add grafana-toolkit to your extension's `package.json` file by running -`yarn add @grafana/toolkit` `npm instal @grafana/toolkit` or use one of our extension templates: +`yarn add @grafana/toolkit` or `npm instal @grafana/toolkit`, or use one of our extension templates: - [React Panel](https://github.com/grafana/simple-react-panel) - [Angular Panel](https://github.com/grafana/simple-angular-panel) @@ -92,7 +95,7 @@ Yes! grafana-toolkit supports Typescript by default. ### How can I test my extension? grafana-toolkit comes with Jest as a test runner. -Internally at Grafana we use Enzyme. If you are developing React extension and you want to configure Enzyme as a testing utility, you need to configure `enzyme-adapter-react`. To do so create `[YOUR_EXTENSION]/config/jest-setup.ts` file that will provide necessary setup. Copy the following code into that file to get Enzyme working with React: +Internally at Grafana we use Enzyme. If you are developing React extension and you want to configure Enzyme as a testing utility, you need to configure `enzyme-adapter-react`. To do so create `/config/jest-setup.ts` file that will provide necessary setup. Copy the following code into that file to get Enzyme working with React: ```ts import { configure } from 'enzyme'; @@ -101,7 +104,7 @@ import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() }); ``` -You can also setup Jest with shims of your needs by creating `jest-shim.ts` file in the same directory: `[YOUR_EXTENSION]/config/jest-shim.ts` +You can also setup Jest with shims of your needs by creating `jest-shim.ts` file in the same directory: `/config/jest-shim.ts` ### Can I provide custom setup for Jest? diff --git a/packages/grafana-toolkit/package.json b/packages/grafana-toolkit/package.json index 919ef39f41f..eab6081f398 100644 --- a/packages/grafana-toolkit/package.json +++ b/packages/grafana-toolkit/package.json @@ -2,7 +2,7 @@ "author": "Grafana Labs", "license": "Apache-2.0", "name": "@grafana/toolkit", - "version": "6.4.0-alpha.44", + "version": "6.4.0-pre", "description": "Grafana Toolkit", "keywords": [ "grafana", diff --git a/packages/grafana-ui/README.md b/packages/grafana-ui/README.md index bc45a78e576..06847c62701 100644 --- a/packages/grafana-ui/README.md +++ b/packages/grafana-ui/README.md @@ -1,5 +1,7 @@ # Grafana UI components library +> **@grafana/toolkit is currently in ALPHA**. Core API is unstable and can be a subject of breaking changes! + @grafana/ui is a collection of components used by [Grafana](https://github.com/grafana/grafana) Our goal is to deliver Grafana's common UI elements for plugins developers and contributors. diff --git a/packages/grafana-ui/package.json b/packages/grafana-ui/package.json index 63de94851a0..4d0ea1bbf32 100644 --- a/packages/grafana-ui/package.json +++ b/packages/grafana-ui/package.json @@ -2,7 +2,7 @@ "author": "Grafana Labs", "license": "Apache-2.0", "name": "@grafana/ui", - "version": "6.4.0-alpha.44", + "version": "6.4.0-pre", "description": "Grafana Components Library", "keywords": [ "grafana", diff --git a/scripts/build/release-packages.sh b/scripts/build/release-packages.sh new file mode 100755 index 00000000000..061ebdd226e --- /dev/null +++ b/scripts/build/release-packages.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +GRAFANA_TAG=${1:-} +RELEASE_CHANNEL="latest" + +if echo "$GRAFANA_TAG" | grep -q "^v"; then + _grafana_version=$(echo "${GRAFANA_TAG}" | cut -d "v" -f 2) +else + echo "Provided tag is not a version tag, skipping packages release..." + exit +fi + +if grep -q "beta" <<< "$GRAFANA_TAG"; then + RELEASE_CHANNEL="next" +fi + +echo "$_grafana_version" + +# Get current version from lerna.json +# Since this happens on tagged branch, the lerna.json version and package.json file SHOULD be updated already +# as specified in release guideline +PACKAGE_VERSION=$(grep '"version"' lerna.json | cut -d '"' -f 4) + +echo "Releasing grafana packages @ ${PACKAGE_VERSION} under ${RELEASE_CHANNEL} channel" + +if [ $RELEASE_CHANNEL == "latest" ]; then + SCRIPT="publishLatest" +elif [ $RELEASE_CHANNEL == "next" ]; then + SCRIPT="publishNext" +else + echo "Unknown channel, skipping packages release" + exit +fi + +echo $'\nBuilding packages' +yarn packages:build + +echo $'\nPublishing packages' +yarn packages:${SCRIPT} + diff --git a/scripts/circle-release-next-packages.sh b/scripts/circle-release-next-packages.sh index b3c47ba6879..6b24fa95021 100755 --- a/scripts/circle-release-next-packages.sh +++ b/scripts/circle-release-next-packages.sh @@ -16,9 +16,13 @@ function unpublish_previous_canary () { for PACKAGE in ui toolkit data runtime do # dist-tag next to be changed to canary when https://github.com/grafana/grafana/pull/18195 is merged - CURRENT_CANARY=$(npm view @grafana/${PACKAGE} dist-tags.next) - echo "Unpublish @grafana/${PACKAGE}@${CURRENT_CANARY}" - npm unpublish "@grafana/${PACKAGE}@${CURRENT_CANARY}" + CURRENT_CANARY=$(npm view @grafana/${PACKAGE} dist-tags.canary) + if [ -z "${CURRENT_CANARY}" ]; then + echo "@grafana/${PACKAGE} - Nothing to unpublish" + else + echo "Unpublish @grafana/${PACKAGE}@${CURRENT_CANARY}" + npm unpublish "@grafana/${PACKAGE}@${CURRENT_CANARY}" + fi done } @@ -57,6 +61,6 @@ else unpublish_previous_canary echo $'\nPublishing packages' - yarn packages:publishNext + yarn packages:publishCanary fi